@@ -379,26 +379,54 @@ class BotToolCall < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinition
379379 end
380380
381381 describe 'Action Text content support' do
382- it 'converts Action Text content to plain text' do
383- chat = Chat . create! ( model_id : model )
384- action_text_content = instance_double ( ActionText ::RichText )
385- allow ( action_text_content ) . to receive ( :to_plain_text ) . and_return ( 'This is rich text content' )
382+ let ( :chat ) { Chat . create! ( model_id : model ) }
383+
384+ def mock_action_text ( plain_text )
385+ instance_double ( ActionText ::RichText ) . tap do |mock |
386+ allow ( mock ) . to receive ( :to_plain_text ) . and_return ( plain_text )
387+ end
388+ end
386389
390+ it 'converts Action Text content to plain text' do
391+ action_text_content = mock_action_text ( 'This is rich text content' )
387392 message = chat . messages . create! ( role : 'user' )
388393 allow ( message ) . to receive ( :content ) . and_return ( action_text_content )
389394
390395 llm_message = message . to_llm
391396
397+ expect ( message . content ) . not_to be_a ( String )
392398 expect ( action_text_content ) . to have_received ( :to_plain_text )
393399 expect ( llm_message . content ) . to eq ( 'This is rich text content' )
394400 end
395401
396402 it 'handles regular string content when to_plain_text is not available' do
397- chat = Chat . create! ( model_id : model )
398403 message = chat . messages . create! ( role : 'user' , content : 'Regular text content' )
404+
399405 llm_message = message . to_llm
406+
407+ expect ( message . content ) . to be_a ( String )
400408 expect ( llm_message . content ) . to eq ( 'Regular text content' )
401409 end
410+
411+ it 'handles Action Text content with attachments' do
412+ action_text_content = mock_action_text ( 'Rich text with attachment reference' )
413+ message = chat . messages . create! ( role : 'user' )
414+ allow ( message ) . to receive ( :content ) . and_return ( action_text_content )
415+
416+ message . attachments . attach (
417+ io : StringIO . new ( 'test data' ) ,
418+ filename : 'test.txt' ,
419+ content_type : 'text/plain'
420+ )
421+
422+ llm_message = message . to_llm
423+
424+ expect ( action_text_content ) . to have_received ( :to_plain_text )
425+ expect ( llm_message . content ) . to be_a ( RubyLLM ::Content )
426+ expect ( llm_message . content . text ) . to eq ( 'Rich text with attachment reference' )
427+ expect ( llm_message . content . attachments ) . not_to be_empty
428+ expect ( llm_message . content . attachments . first . mime_type ) . to eq ( 'text/plain' )
429+ end
402430 end
403431
404432 describe 'attachment handling' do
0 commit comments