|
6 | 6 |
|
7 | 7 | RSpec.describe RubyLLM::InstallGenerator, type: :generator do
|
8 | 8 | # Use the actual template directory
|
9 |
| - let(:template_dir) { '/Users/kieranklaassen/rails/ruby_llm/lib/generators/ruby_llm/install/templates' } |
10 |
| - let(:generator_file) { '/Users/kieranklaassen/rails/ruby_llm/lib/generators/ruby_llm/install_generator.rb' } |
| 9 | + let(:template_dir) { File.join(File.dirname(__FILE__), '../../../../lib/generators/ruby_llm/install/templates') } |
| 10 | + let(:generator_file) { File.join(File.dirname(__FILE__), '../../../../lib/generators/ruby_llm/install_generator.rb') } |
11 | 11 |
|
12 | 12 | describe 'migration templates' do
|
13 | 13 | let(:expected_migration_files) do
|
|
28 | 28 | let(:chat_migration) { File.read(File.join(template_dir, 'create_chats_migration.rb.tt')) }
|
29 | 29 |
|
30 | 30 | it 'defines chats table' do
|
31 |
| - expect(chat_migration).to include('create_table :chats') |
| 31 | + expect(chat_migration).to include('create_table :<%= options[:chat_model_name].tableize %>') |
32 | 32 | end
|
33 | 33 |
|
34 | 34 | it 'includes model_id field' do
|
|
40 | 40 | let(:message_migration) { File.read(File.join(template_dir, 'create_messages_migration.rb.tt')) }
|
41 | 41 |
|
42 | 42 | it 'defines messages table' do
|
43 |
| - expect(message_migration).to include('create_table :messages') |
| 43 | + expect(message_migration).to include('create_table :<%= options[:message_model_name].tableize %>') |
44 | 44 | end
|
45 | 45 |
|
46 | 46 | it 'includes chat reference' do
|
47 |
| - expect(message_migration).to include('t.references :chat') |
| 47 | + expect(message_migration).to include('t.references :<%= options[:chat_model_name].tableize.singularize %>, null: false, foreign_key: true') |
48 | 48 | end
|
49 | 49 |
|
50 | 50 | it 'includes role field' do
|
|
60 | 60 | let(:tool_call_migration) { File.read(File.join(template_dir, 'create_tool_calls_migration.rb.tt')) }
|
61 | 61 |
|
62 | 62 | it 'defines tool_calls table' do
|
63 |
| - expect(tool_call_migration).to include('create_table :tool_calls') |
| 63 | + expect(tool_call_migration).to include('create_table :<%= options[:tool_call_model_name].tableize %>') |
64 | 64 | end
|
65 | 65 |
|
66 | 66 | it 'includes tool_call_id field' do
|
|
78 | 78 |
|
79 | 79 | describe 'PostgreSQL support' do
|
80 | 80 | it 'includes postgresql condition check' do
|
81 |
| - expect(tool_call_migration).to include('if postgresql?') |
82 |
| - end |
83 |
| - |
84 |
| - it 'uses jsonb type' do |
85 |
| - expect(tool_call_migration).to include('t.jsonb :arguments') |
86 |
| - end |
87 |
| - end |
88 |
| - |
89 |
| - describe 'other databases support' do |
90 |
| - it 'includes else condition' do |
91 |
| - expect(tool_call_migration).to include('else') |
92 |
| - end |
93 |
| - |
94 |
| - it 'uses json type' do |
95 |
| - expect(tool_call_migration).to include('t.json :arguments') |
| 81 | + expect(tool_call_migration).to include("t.<%= postgresql? ? 'jsonb' : 'json' %> :arguments, default: {}") |
96 | 82 | end
|
97 | 83 | end
|
98 | 84 | end
|
|
149 | 135 | end
|
150 | 136 |
|
151 | 137 | describe 'README template' do
|
152 |
| - let(:readme_content) { File.read(File.join(template_dir, 'README.md')) } |
| 138 | + let(:readme_content) { File.read(File.join(template_dir, 'README.md.tt')) } |
153 | 139 |
|
154 | 140 | it 'has README template file' do
|
155 |
| - expect(File.exist?(File.join(template_dir, 'README.md'))).to be(true) |
| 141 | + expect(File.exist?(File.join(template_dir, 'README.md.tt'))).to be(true) |
156 | 142 | end
|
157 | 143 |
|
158 | 144 | it 'includes welcome message' do
|
|
216 | 202 | end
|
217 | 203 | end
|
218 | 204 |
|
219 |
| - describe 'migration sequence' do |
220 |
| - let(:generator_content) { File.read(generator_file) } |
221 |
| - let(:migrations_order) do |
222 |
| - { |
223 |
| - chats: generator_content.index('create_chats.rb'), |
224 |
| - tool_calls: generator_content.index('create_tool_calls.rb'), |
225 |
| - messages: generator_content.index('create_messages.rb') |
226 |
| - } |
227 |
| - end |
228 |
| - |
229 |
| - it 'orders chats before tool_calls' do |
230 |
| - expect(migrations_order[:chats]).to be < migrations_order[:tool_calls] |
231 |
| - end |
232 |
| - |
233 |
| - it 'orders tool_calls before messages' do |
234 |
| - expect(migrations_order[:tool_calls]).to be < migrations_order[:messages] |
235 |
| - end |
236 |
| - |
237 |
| - it 'initializes timestamp from current time' do |
238 |
| - expect(generator_content).to include('@migration_number = Time.now.utc.strftime') |
239 |
| - end |
240 |
| - |
241 |
| - it 'increments timestamp for sequential migrations' do |
242 |
| - expect(generator_content).to include('@migration_number = (@migration_number.to_i + 1).to_s') |
243 |
| - end |
244 |
| - end |
245 |
| - |
246 | 205 | describe 'database detection' do
|
247 | 206 | let(:generator_content) { File.read(generator_file) }
|
248 | 207 |
|
|
0 commit comments