|
30 | 30 | expect(message_migration).to include("t.references :chat")
|
31 | 31 | expect(message_migration).to include("t.string :role")
|
32 | 32 | expect(message_migration).to include("t.text :content")
|
| 33 | + expect(message_migration).to include("t.references :tool_call") |
33 | 34 |
|
34 | 35 | tool_call_migration = File.read(File.join(template_dir, "create_tool_calls_migration.rb"))
|
35 | 36 | expect(tool_call_migration).to include("create_table :tool_calls")
|
36 |
| - expect(tool_call_migration).to include("t.references :message") |
| 37 | + expect(tool_call_migration).to include("# No reference to message to avoid circular references") |
37 | 38 | expect(tool_call_migration).to include("t.string :tool_call_id")
|
38 | 39 | expect(tool_call_migration).to include("t.string :name")
|
39 | 40 |
|
|
97 | 98 | expect(generator_content).to include("def create_model_files")
|
98 | 99 | expect(generator_content).to include("def create_initializer")
|
99 | 100 | end
|
| 101 | + |
| 102 | + it "creates migrations in the correct order" do |
| 103 | + generator_file = "/Users/kieranklaassen/rails/ruby_llm/lib/generators/ruby_llm/install_generator.rb" |
| 104 | + generator_content = File.read(generator_file) |
| 105 | + |
| 106 | + # Check for correct order in migration creation |
| 107 | + # 1. First chats table (no dependencies) |
| 108 | + # 2. Then tool_calls table (will be referenced by messages) |
| 109 | + # 3. Finally messages table (depends on both chats and tool_calls) |
| 110 | + |
| 111 | + # Simply check the order of template calls |
| 112 | + # Chats should come before tool_calls, which should come before messages |
| 113 | + chats_position = generator_content.index('create_chats.rb') |
| 114 | + tool_calls_position = generator_content.index('create_tool_calls.rb') |
| 115 | + messages_position = generator_content.index('create_messages.rb') |
| 116 | + |
| 117 | + # Verify order: chats -> tool_calls -> messages |
| 118 | + expect(chats_position).to be < tool_calls_position |
| 119 | + expect(tool_calls_position).to be < messages_position |
| 120 | + |
| 121 | + # Also test that the method enforces sequential timestamps |
| 122 | + expect(generator_content).to include("@migration_number = Time.now.utc.strftime") |
| 123 | + expect(generator_content).to include("@migration_number = (@migration_number.to_i + 1).to_s") |
| 124 | + expect(generator_content).to include("@migration_number = (@migration_number.to_i + 2).to_s") |
| 125 | + end |
100 | 126 | end
|
101 | 127 |
|
102 | 128 | describe "database adapter detection" do
|
|
0 commit comments