declare_schema 2.0.0 → 2.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +19 -0
  3. data/.devcontainer/boot.sh +1 -0
  4. data/.devcontainer/devcontainer.json +55 -0
  5. data/.devcontainer/docker-compose.yml +40 -0
  6. data/.github/workflows/declare_schema_build.yml +35 -11
  7. data/Appraisals +2 -10
  8. data/CHANGELOG.md +5 -0
  9. data/CODE-OF-CONDUCT.md +16 -0
  10. data/CONTRIBUTING.md +46 -0
  11. data/Gemfile +6 -1
  12. data/Gemfile.lock +87 -77
  13. data/README.md +38 -14
  14. data/Rakefile +5 -15
  15. data/catalog-info.yaml +35 -0
  16. data/config/brakeman.ignore +2 -2
  17. data/gemfiles/{rails_6_1_sqlite3.gemfile → rails_6_1.gemfile} +3 -0
  18. data/gemfiles/{rails_7_0_sqlite3.gemfile → rails_7_0.gemfile} +3 -0
  19. data/gemfiles/{rails_7_1_sqlite3.gemfile → rails_7_1.gemfile} +3 -0
  20. data/gemfiles/{rails_7_0_mysql2.gemfile → rails_7_2.gemfile} +4 -1
  21. data/lib/declare_schema/command.rb +2 -8
  22. data/lib/declare_schema/model/column.rb +1 -1
  23. data/lib/declare_schema/model/foreign_key_definition.rb +9 -12
  24. data/lib/declare_schema/model/index_definition.rb +16 -8
  25. data/lib/declare_schema/model.rb +10 -14
  26. data/lib/declare_schema/schema_change/base.rb +4 -0
  27. data/lib/declare_schema/schema_change/primary_key_change.rb +19 -6
  28. data/lib/declare_schema/version.rb +1 -1
  29. data/lib/declare_schema.rb +20 -8
  30. data/lib/generators/declare_schema/migration/migration_generator.rb +15 -2
  31. data/lib/generators/declare_schema/migration/migrator.rb +16 -9
  32. data/spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_6.txt +15 -0
  33. data/spec/fixtures/migrations/mysql2/will_generate_unique_constraint_names_rails_7.txt +15 -0
  34. data/spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_6.txt +15 -0
  35. data/spec/fixtures/migrations/postgresql/will_generate_unique_constraint_names_rails_7.txt +15 -0
  36. data/spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_6.txt +15 -0
  37. data/spec/fixtures/migrations/sqlite3/will_generate_unique_constraint_names_rails_7.txt +15 -0
  38. data/spec/lib/declare_schema/api_spec.rb +1 -3
  39. data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +3 -3
  40. data/spec/lib/declare_schema/field_spec_spec.rb +68 -45
  41. data/spec/lib/declare_schema/generator_spec.rb +2 -4
  42. data/spec/lib/declare_schema/interactive_primary_key_spec.rb +3 -10
  43. data/spec/lib/declare_schema/migration_generator_spec.rb +248 -249
  44. data/spec/lib/declare_schema/model/column_spec.rb +89 -41
  45. data/spec/lib/declare_schema/model/foreign_key_definition_spec.rb +14 -8
  46. data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +4 -9
  47. data/spec/lib/declare_schema/model/index_definition_spec.rb +18 -10
  48. data/spec/lib/declare_schema/model/table_options_definition_spec.rb +11 -11
  49. data/spec/lib/declare_schema/schema_change/base_spec.rb +5 -7
  50. data/spec/lib/declare_schema/schema_change/column_add_spec.rb +1 -3
  51. data/spec/lib/declare_schema/schema_change/column_change_spec.rb +1 -3
  52. data/spec/lib/declare_schema/schema_change/column_remove_spec.rb +1 -3
  53. data/spec/lib/declare_schema/schema_change/column_rename_spec.rb +1 -3
  54. data/spec/lib/declare_schema/schema_change/foreign_key_add_spec.rb +1 -3
  55. data/spec/lib/declare_schema/schema_change/foreign_key_remove_spec.rb +1 -3
  56. data/spec/lib/declare_schema/schema_change/index_add_spec.rb +1 -3
  57. data/spec/lib/declare_schema/schema_change/index_remove_spec.rb +1 -3
  58. data/spec/lib/declare_schema/schema_change/primary_key_change_spec.rb +39 -15
  59. data/spec/lib/declare_schema/schema_change/table_add_spec.rb +1 -3
  60. data/spec/lib/declare_schema/schema_change/table_change_spec.rb +1 -3
  61. data/spec/lib/declare_schema/schema_change/table_remove_spec.rb +1 -3
  62. data/spec/lib/declare_schema/schema_change/table_rename_spec.rb +1 -3
  63. data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +0 -4
  64. data/spec/spec_helper.rb +3 -0
  65. data/spec/support/adapter_specific_test_helpers.rb +25 -0
  66. data/spec/{lib/declare_schema → support}/prepare_testapp.rb +3 -1
  67. data/spec/support/test_app_spec_helpers.rb +7 -0
  68. metadata +22 -9
  69. data/gemfiles/rails_6_1_mysql2.gemfile +0 -23
  70. data/gemfiles/rails_7_1_mysql2.gemfile +0 -23
@@ -1,53 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
4
- require 'mysql2'
5
- rescue LoadError
6
- end
7
-
8
- begin
9
- require 'sqlite3'
10
- rescue LoadError
11
- end
12
-
13
3
  RSpec.describe 'DeclareSchema Migration Generator' do
14
- before do
15
- load File.expand_path('prepare_testapp.rb', __dir__)
16
- end
4
+ include_context 'prepare test app'
5
+
17
6
  let(:text_limit) do
18
- if defined?(Mysql2)
7
+ if current_adapter == 'mysql2'
19
8
  ", limit: 4294967295"
20
9
  end
21
10
  end
22
11
  let(:charset_and_collation) do
23
- if defined?(Mysql2)
12
+ if current_adapter == 'mysql2'
24
13
  ', charset: "utf8mb4", collation: "utf8mb4_bin"'
25
14
  end
26
15
  end
16
+ let(:primary_key_type) do
17
+ if current_adapter == 'postgresql'
18
+ ':bigserial'
19
+ else
20
+ ':bigint'
21
+ end
22
+ end
27
23
  let(:create_table_charset_and_collation) do
28
- if defined?(Mysql2)
24
+ if current_adapter == 'mysql2'
29
25
  ", options: \"CHARACTER SET utf8mb4 COLLATE utf8mb4_bin\""
30
26
  end
31
27
  end
32
28
  let(:datetime_precision) do
33
29
  if ActiveSupport::VERSION::MAJOR >= 7
34
30
  ', precision: 6'
35
- elsif defined?(Mysql2)
31
+ elsif current_adapter == 'mysql2'
36
32
  ', precision: 0'
37
33
  end
38
34
  end
39
35
  let(:table_options) do
40
- if defined?(Mysql2)
36
+ case current_adapter
37
+ when 'mysql2'
41
38
  ', options: "DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", charset: "utf8mb4", collation: "utf8mb4_bin"'
39
+ when 'postgresql'
40
+ ""
42
41
  else
43
42
  ", id: :integer"
44
43
  end
45
44
  end
46
45
  let(:lock_version_limit) do
47
- if defined?(Mysql2)
48
- ", limit: 4"
49
- else
46
+ if current_adapter == 'sqlite3'
50
47
  ''
48
+ else
49
+ ', limit: 4'
51
50
  end
52
51
  end
53
52
 
@@ -58,8 +57,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
58
57
 
59
58
  expect(Generators::DeclareSchema::Migration::Migrator.run).to migrate_up("").and migrate_down("")
60
59
 
61
- class Advert < ActiveRecord::Base
62
- end
60
+ class Advert < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
63
61
 
64
62
  expect(Generators::DeclareSchema::Migration::Migrator.run).to migrate_up("").and migrate_down("")
65
63
 
@@ -68,7 +66,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
68
66
  Advert.connection.schema_cache.clear!
69
67
  Advert.reset_column_information
70
68
 
71
- class Advert < ActiveRecord::Base
69
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
72
70
  declare_schema do
73
71
  string :name, limit: 250, null: true
74
72
  end
@@ -77,18 +75,18 @@ RSpec.describe 'DeclareSchema Migration Generator' do
77
75
  up, _ = Generators::DeclareSchema::Migration::Migrator.run.tap do |migrations|
78
76
  expect(migrations).to(
79
77
  migrate_up(<<~EOS.strip)
80
- create_table :adverts, id: :bigint#{create_table_charset_and_collation} do |t|
78
+ create_table :adverts, id: #{primary_key_type}#{create_table_charset_and_collation} do |t|
81
79
  t.string :name, limit: 250, null: true#{charset_and_collation}
82
80
  end
83
81
  EOS
84
- .and migrate_down("drop_table :adverts")
82
+ .and(migrate_down("drop_table :adverts"))
85
83
  )
86
84
  end
87
85
 
88
86
  ActiveRecord::Migration.class_eval(up)
89
87
  expect(Advert.columns.map(&:name)).to eq(["id", "name"])
90
88
 
91
- class Advert < ActiveRecord::Base
89
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
92
90
  declare_schema do
93
91
  string :name, limit: 250, null: true
94
92
  text :body, null: true
@@ -104,14 +102,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
104
102
  add_column :adverts, :body, :text#{text_limit}, null: true#{charset_and_collation}
105
103
  add_column :adverts, :published_at, :datetime, null: true
106
104
  EOS
107
- .and migrate_down(<<~EOS.strip)
108
- remove_column :adverts, :published_at
109
- remove_column :adverts, :body
105
+ .and(migrate_down(<<~EOS.strip))
106
+ remove_column :adverts, :published_at
107
+ remove_column :adverts, :body
110
108
  EOS
111
109
  )
112
110
 
113
111
  Advert.field_specs.clear # not normally needed
114
- class Advert < ActiveRecord::Base
112
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
115
113
  declare_schema do
116
114
  string :name, limit: 250, null: true
117
115
  text :body, null: true
@@ -119,13 +117,13 @@ RSpec.describe 'DeclareSchema Migration Generator' do
119
117
  end
120
118
 
121
119
  expect(migrate).to(
122
- migrate_up("remove_column :adverts, :published_at").and(
123
- migrate_down("add_column :adverts, :published_at, :datetime#{datetime_precision}, null: true")
124
- )
120
+ migrate_up("remove_column :adverts, :published_at").and(
121
+ migrate_down("add_column :adverts, :published_at, :datetime#{datetime_precision}, null: true")
122
+ )
125
123
  )
126
124
 
127
125
  nuke_model_class(Advert)
128
- class Advert < ActiveRecord::Base
126
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
129
127
  declare_schema do
130
128
  string :title, limit: 250, null: true
131
129
  text :body, null: true
@@ -137,21 +135,21 @@ RSpec.describe 'DeclareSchema Migration Generator' do
137
135
  add_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
138
136
  remove_column :adverts, :name
139
137
  EOS
140
- .and migrate_down(<<~EOS.strip)
141
- add_column :adverts, :name, :string, limit: 250, null: true#{charset_and_collation}
142
- remove_column :adverts, :title
138
+ .and(migrate_down(<<~EOS.strip))
139
+ add_column :adverts, :name, :string, limit: 250, null: true#{charset_and_collation}
140
+ remove_column :adverts, :title
143
141
  EOS
144
142
  )
145
143
 
146
144
  expect(Generators::DeclareSchema::Migration::Migrator.run(adverts: { name: :title })).to(
147
- migrate_up("rename_column :adverts, :name, :title").and(
148
- migrate_down("rename_column :adverts, :title, :name")
149
- )
145
+ migrate_up("rename_column :adverts, :name, :title").and(
146
+ migrate_down("rename_column :adverts, :title, :name")
147
+ )
150
148
  )
151
149
 
152
150
  migrate
153
151
 
154
- class Advert < ActiveRecord::Base
152
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
155
153
  declare_schema do
156
154
  text :title, null: true
157
155
  text :body, null: true
@@ -159,12 +157,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
159
157
  end
160
158
 
161
159
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
162
- migrate_up("change_column :adverts, :title, :text#{text_limit}, null: true#{charset_and_collation}").and(
163
- migrate_down("change_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}")
164
- )
160
+ migrate_up("change_column :adverts, :title, :text#{text_limit}, null: true#{charset_and_collation}").and(
161
+ migrate_down("change_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}")
162
+ )
165
163
  )
166
164
 
167
- class Advert < ActiveRecord::Base
165
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
168
166
  declare_schema do
169
167
  string :title, default: "Untitled", limit: 250, null: true
170
168
  text :body, null: true
@@ -172,17 +170,17 @@ RSpec.describe 'DeclareSchema Migration Generator' do
172
170
  end
173
171
 
174
172
  expect(migrate).to(
175
- migrate_up(<<~EOS.strip)
173
+ migrate_up(<<~EOS.strip)
176
174
  change_column :adverts, :title, :string, limit: 250, null: true, default: "Untitled"#{charset_and_collation}
177
- EOS
178
- .and migrate_down(<<~EOS.strip)
179
- change_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
180
- EOS
175
+ EOS
176
+ .and(migrate_down(<<~EOS.strip))
177
+ change_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
178
+ EOS
181
179
  )
182
180
 
183
181
  ### Limits
184
182
 
185
- class Advert < ActiveRecord::Base
183
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
186
184
  declare_schema do
187
185
  integer :price, null: true, limit: 2
188
186
  end
@@ -195,23 +193,23 @@ RSpec.describe 'DeclareSchema Migration Generator' do
195
193
  # Now run the migration, then change the limit:
196
194
 
197
195
  ActiveRecord::Migration.class_eval(up)
198
- class Advert < ActiveRecord::Base
196
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
199
197
  declare_schema do
200
198
  integer :price, null: true, limit: 3
201
199
  end
202
200
  end
203
201
 
204
202
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
205
- migrate_up(<<~EOS.strip)
203
+ migrate_up(<<~EOS.strip)
206
204
  change_column :adverts, :price, :integer, limit: 3, null: true
207
- EOS
208
- .and migrate_down(<<~EOS.strip)
209
- change_column :adverts, :price, :integer, limit: 2, null: true
210
- EOS
205
+ EOS
206
+ .and(migrate_down(<<~EOS.strip))
207
+ change_column :adverts, :price, :integer, limit: 2, null: true
208
+ EOS
211
209
  )
212
210
 
213
- ActiveRecord::Migration.class_eval("remove_column :adverts, :price")
214
- class Advert < ActiveRecord::Base
211
+ ActiveRecord::Migration.class_eval("remove_column :adverts, :price", __FILE__, __LINE__)
212
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
215
213
  declare_schema do
216
214
  decimal :price, precision: 4, scale: 1, null: true
217
215
  end
@@ -222,11 +220,11 @@ RSpec.describe 'DeclareSchema Migration Generator' do
222
220
  # If a `limit` is given, it will only be used in MySQL, to choose the smallest TEXT field that will accommodate
223
221
  # that limit (0xff for TINYTEXT, 0xffff for TEXT, 0xffffff for MEDIUMTEXT, 0xffffffff for LONGTEXT).
224
222
 
225
- if defined?(SQLite3)
223
+ if current_adapter == 'sqlite3'
226
224
  expect(::DeclareSchema::Model::FieldSpec.mysql_text_limits?).to be_falsey
227
225
  end
228
226
 
229
- class Advert < ActiveRecord::Base
227
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
230
228
  declare_schema do
231
229
  text :notes
232
230
  text :description, limit: 30000
@@ -234,11 +232,11 @@ RSpec.describe 'DeclareSchema Migration Generator' do
234
232
  end
235
233
 
236
234
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
237
- migrate_up(<<~EOS.strip)
235
+ migrate_up(<<~EOS.strip)
238
236
  add_column :adverts, :price, :decimal, precision: 4, scale: 1, null: true
239
237
  add_column :adverts, :notes, :text#{text_limit}, null: false#{charset_and_collation}
240
- add_column :adverts, :description, :text#{', limit: 65535' if defined?(Mysql2)}, null: false#{charset_and_collation}
241
- EOS
238
+ add_column :adverts, :description, :text#{', limit: 65535' if current_adapter == 'mysql2'}, null: false#{charset_and_collation}
239
+ EOS
242
240
  )
243
241
 
244
242
  Advert.field_specs.delete :price
@@ -247,7 +245,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
247
245
 
248
246
  # In MySQL, limits are applied, rounded up:
249
247
 
250
- if defined?(Mysql2)
248
+ if current_adapter == 'mysql2'
251
249
  expect(::DeclareSchema::Model::FieldSpec.mysql_text_limits?).to be_truthy
252
250
 
253
251
  class Advert < ActiveRecord::Base
@@ -258,10 +256,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
258
256
  end
259
257
 
260
258
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
261
- migrate_up(<<~EOS.strip)
259
+ migrate_up(<<~EOS.strip)
262
260
  add_column :adverts, :notes, :text, limit: 4294967295, null: false#{charset_and_collation}
263
261
  add_column :adverts, :description, :text, limit: 255, null: false#{charset_and_collation}
264
- EOS
262
+ EOS
265
263
  )
266
264
 
267
265
  Advert.field_specs.delete :notes
@@ -269,7 +267,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
269
267
  # Limits that are too high for MySQL will raise an exception.
270
268
 
271
269
  expect do
272
- class Advert < ActiveRecord::Base
270
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
273
271
  declare_schema do
274
272
  text :notes
275
273
  text :description, limit: 0x1_0000_0000
@@ -286,8 +284,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
286
284
  Advert.connection.execute "ALTER TABLE adverts ADD COLUMN description TINYTEXT"
287
285
  Advert.connection.schema_cache.clear!
288
286
  Advert.reset_column_information
289
- expect(Advert.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables).
290
- to eq(["adverts"])
287
+ expect(Advert.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables).to eq(["adverts"])
291
288
  expect(Advert.columns.map(&:name)).to eq(["id", "body", "title", "description"])
292
289
 
293
290
  # Now migrate to an unstated text limit:
@@ -299,12 +296,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
299
296
  end
300
297
 
301
298
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
302
- migrate_up(<<~EOS.strip)
299
+ migrate_up(<<~EOS.strip)
303
300
  change_column :adverts, :description, :text, limit: 4294967295, null: false#{charset_and_collation}
304
- EOS
305
- .and migrate_down(<<~EOS.strip)
306
- change_column :adverts, :description, :text#{', limit: 255' if defined?(Mysql2)}, null: true#{charset_and_collation}
307
- EOS
301
+ EOS
302
+ .and(migrate_down(<<~EOS.strip))
303
+ change_column :adverts, :description, :text#{', limit: 255' if current_adapter == 'mysql2'}, null: true#{charset_and_collation}
304
+ EOS
308
305
  )
309
306
 
310
307
  # And migrate to a stated text limit that is the same as the unstated one:
@@ -316,19 +313,20 @@ RSpec.describe 'DeclareSchema Migration Generator' do
316
313
  end
317
314
 
318
315
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
319
- migrate_up(<<~EOS.strip)
316
+ migrate_up(<<~EOS.strip)
320
317
  change_column :adverts, :description, :text, limit: 4294967295, null: false#{charset_and_collation}
321
- EOS
322
- .and migrate_down(<<~EOS.strip)
323
- change_column :adverts, :description, :text#{', limit: 255' if defined?(Mysql2)}, null: true#{charset_and_collation}
324
- EOS
318
+ EOS
319
+ .and(migrate_down(<<~EOS.strip))
320
+ change_column :adverts, :description, :text#{', limit: 255' if current_adapter == 'mysql2'}, null: true#{charset_and_collation}
321
+ EOS
325
322
  )
326
323
  end
327
324
 
328
325
  Advert.field_specs.clear
329
326
  Advert.connection.schema_cache.clear!
330
327
  Advert.reset_column_information
331
- class Advert < ActiveRecord::Base
328
+
329
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
332
330
  declare_schema do
333
331
  string :name, limit: 250, null: true
334
332
  end
@@ -345,8 +343,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
345
343
  # DeclareSchema extends the `belongs_to` macro so that it also declares the
346
344
  # foreign-key field. It also generates an index on the field.
347
345
 
348
- class Category < ActiveRecord::Base; end
349
- class Advert < ActiveRecord::Base
346
+ class Category < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
347
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
350
348
  declare_schema do
351
349
  string :name, limit: 250, null: true
352
350
  end
@@ -357,12 +355,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
357
355
  migrate_up(<<~EOS.strip)
358
356
  add_column :adverts, :category_id, :integer, limit: 8, null: false
359
357
  add_index :adverts, [:category_id], name: :index_adverts_on_category_id
360
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" if defined?(Mysql2)}
358
+ #{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" unless current_adapter == 'sqlite3'}
361
359
  EOS
362
- .and migrate_down(<<~EOS.strip)
363
- #{"remove_foreign_key :adverts, name: :index_adverts_on_category_id" if defined?(Mysql2)}
364
- remove_index :adverts, name: :index_adverts_on_category_id
365
- remove_column :adverts, :category_id
360
+ .and(migrate_down(<<~EOS.strip))
361
+ #{'remove_foreign_key :adverts, name: :index_adverts_on_category_id' unless current_adapter == 'sqlite3'}
362
+ remove_index :adverts, name: :index_adverts_on_category_id
363
+ remove_column :adverts, :category_id
366
364
  EOS
367
365
  )
368
366
 
@@ -371,8 +369,9 @@ RSpec.describe 'DeclareSchema Migration Generator' do
371
369
 
372
370
  # If you specify a custom foreign key, the migration generator observes that:
373
371
 
374
- class Category < ActiveRecord::Base; end
375
- class Advert < ActiveRecord::Base
372
+ class Category < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
373
+
374
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
376
375
  declare_schema { }
377
376
  belongs_to :category, foreign_key: "c_id", class_name: 'Category'
378
377
  end
@@ -381,8 +380,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
381
380
  migrate_up(<<~EOS.strip)
382
381
  add_column :adverts, :c_id, :integer, limit: 8, null: false
383
382
  add_index :adverts, [:c_id], name: :index_adverts_on_c_id
384
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
385
- "add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
383
+ #{unless current_adapter == 'sqlite3'
384
+ "add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" \
385
+ 'add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id'
386
+ end}
386
387
  EOS
387
388
  )
388
389
 
@@ -392,8 +393,9 @@ RSpec.describe 'DeclareSchema Migration Generator' do
392
393
 
393
394
  # You can avoid generating the index by specifying `index: false`
394
395
 
395
- class Category < ActiveRecord::Base; end
396
- class Advert < ActiveRecord::Base
396
+ class Category < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
397
+
398
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
397
399
  declare_schema { }
398
400
  belongs_to :category, index: false
399
401
  end
@@ -401,8 +403,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
401
403
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
402
404
  migrate_up(<<~EOS.strip)
403
405
  add_column :adverts, :category_id, :integer, limit: 8, null: false
404
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id" if defined?(Mysql2)}
405
- EOS
406
+ #{'add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id' unless current_adapter == 'sqlite3'}
407
+ EOS
406
408
  )
407
409
 
408
410
  Advert.field_specs.delete(:category_id)
@@ -411,10 +413,13 @@ RSpec.describe 'DeclareSchema Migration Generator' do
411
413
 
412
414
  # You can specify the index name with index: 'name' [deprecated]
413
415
 
414
- expect(ActiveSupport::Deprecation).to receive(:warn).with(/belongs_to :category, index: 'name' is deprecated; use index: \{ name: 'name' \} instead/i)
416
+ expect(DeclareSchema.deprecator).to(
417
+ receive(:warn).with(/belongs_to :category, index: 'name' is deprecated; use index: \{ name: 'name' \} instead/i)
418
+ )
419
+
420
+ class Category < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
415
421
 
416
- class Category < ActiveRecord::Base; end
417
- class Advert < ActiveRecord::Base
422
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
418
423
  declare_schema { }
419
424
  belongs_to :category, index: 'my_index'
420
425
  end
@@ -423,7 +428,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
423
428
  migrate_up(<<~EOS.strip)
424
429
  add_column :adverts, :category_id, :integer, limit: 8, null: false
425
430
  add_index :adverts, [:category_id], name: :my_index
426
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :my_index" if defined?(Mysql2)}
431
+ #{'add_foreign_key :adverts, :categories, column: :category_id, name: :my_index' unless current_adapter == 'sqlite3'}
427
432
  EOS
428
433
  )
429
434
 
@@ -433,8 +438,9 @@ RSpec.describe 'DeclareSchema Migration Generator' do
433
438
 
434
439
  # You can specify the index name with index: { name: }'name', unique: true|false }
435
440
 
436
- class Category < ActiveRecord::Base; end
437
- class Advert < ActiveRecord::Base
441
+ class Category < ActiveRecord::Base; end # rubocop:disable Lint/ConstantDefinitionInBlock
442
+
443
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
438
444
  declare_schema { }
439
445
  belongs_to :category, index: { name: 'my_index', unique: false }
440
446
  end
@@ -443,7 +449,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
443
449
  migrate_up(<<~EOS.strip)
444
450
  add_column :adverts, :category_id, :integer, limit: 8, null: false
445
451
  add_index :adverts, [:category_id], name: :my_index
446
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :my_index" if defined?(Mysql2)}
452
+ #{'add_foreign_key :adverts, :categories, column: :category_id, name: :my_index' unless current_adapter == 'sqlite3'}
447
453
  EOS
448
454
  )
449
455
 
@@ -456,7 +462,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
456
462
  # `updated_at` and `created_at` can be declared with the shorthand `timestamps`.
457
463
  # Similarly, `lock_version` can be declared with the "shorthand" `optimimistic_lock`.
458
464
 
459
- class Advert < ActiveRecord::Base
465
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
460
466
  declare_schema do
461
467
  timestamps
462
468
  optimistic_lock
@@ -469,10 +475,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
469
475
  add_column :adverts, :updated_at, :datetime, null: true
470
476
  add_column :adverts, :lock_version, :integer#{lock_version_limit}, null: false, default: 1
471
477
  EOS
472
- .and migrate_down(<<~EOS.strip)
473
- remove_column :adverts, :lock_version
474
- remove_column :adverts, :updated_at
475
- remove_column :adverts, :created_at
478
+ .and(migrate_down(<<~EOS.strip))
479
+ remove_column :adverts, :lock_version
480
+ remove_column :adverts, :updated_at
481
+ remove_column :adverts, :created_at
476
482
  EOS
477
483
  )
478
484
 
@@ -484,10 +490,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
484
490
 
485
491
  # You can add an index to a field definition
486
492
 
487
- expect(ActiveSupport::Deprecation).to receive(:warn).with(/belongs_to :category, index: 'name' is deprecated; use index: \{ name: 'name' \} instead/i)
488
- expect(ActiveSupport::Deprecation).to receive(:warn).with(/belongs_to :category, unique: true\|false is deprecated; use index: \{ unique: true\|false \} instead/i)
493
+ expect(DeclareSchema.deprecator).to(
494
+ receive(:warn).with(/belongs_to :category, index: 'name' is deprecated; use index: \{ name: 'name' \} instead/i)
495
+ )
496
+ expect(DeclareSchema.deprecator).to(
497
+ receive(:warn).with(/belongs_to :category, unique: true\|false is deprecated; use index: \{ unique: true\|false \} instead/i)
498
+ )
489
499
 
490
- class Advert < ActiveRecord::Base
500
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
491
501
  declare_schema do
492
502
  string :title, index: true, limit: 250, null: true
493
503
  end
@@ -500,7 +510,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
500
510
  add_column :adverts, :category_id, :integer, limit: 8, null: false
501
511
  add_index :adverts, [:title], name: :index_adverts_on_title
502
512
  add_index :adverts, [:category_id], name: :my_index
503
- #{"add_foreign_key :adverts, :categories, column: :category_id, name: :my_index" if defined?(Mysql2)}
513
+ #{'add_foreign_key :adverts, :categories, column: :category_id, name: :my_index' unless current_adapter == 'sqlite3'}
504
514
  EOS
505
515
  )
506
516
 
@@ -510,7 +520,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
510
520
 
511
521
  # You can ask for a unique index (deprecated syntax; use index: { unique: true } instead).
512
522
 
513
- class Advert < ActiveRecord::Base
523
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
514
524
  declare_schema do
515
525
  string :title, index: true, unique: true, null: true, limit: 250
516
526
  end
@@ -527,7 +537,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
527
537
 
528
538
  # You can specify the name for the index
529
539
 
530
- class Advert < ActiveRecord::Base
540
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
531
541
  declare_schema do
532
542
  string :title, index: 'my_index', limit: 250, null: true
533
543
  end
@@ -544,7 +554,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
544
554
 
545
555
  # You can ask for an index outside of the fields block
546
556
 
547
- class Advert < ActiveRecord::Base
557
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
548
558
  declare_schema do
549
559
  string :title, limit: 250, null: true
550
560
  end
@@ -562,7 +572,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
562
572
 
563
573
  # The available options for the index function are :unique, :name, :where, and :length.
564
574
 
565
- class Advert < ActiveRecord::Base
575
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
566
576
  index :title, unique: false, name: 'my_index', length: 10
567
577
  end
568
578
 
@@ -577,7 +587,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
577
587
 
578
588
  # You can create an index on more than one field
579
589
 
580
- class Advert < ActiveRecord::Base
590
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
581
591
  index [:title, :category_id]
582
592
  end
583
593
 
@@ -598,7 +608,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
598
608
 
599
609
  # The migration generator respects the `set_table_name` declaration, although as before, we need to explicitly tell the generator that we want a rename rather than a create and a drop.
600
610
 
601
- class Advert < ActiveRecord::Base
611
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
602
612
  self.table_name = "ads"
603
613
  declare_schema do
604
614
  string :title, limit: 250, null: true
@@ -613,20 +623,20 @@ RSpec.describe 'DeclareSchema Migration Generator' do
613
623
  migrate_up(<<~EOS.strip)
614
624
  rename_table :adverts, :ads
615
625
  add_column :ads, :title, :string, limit: 250, null: true#{charset_and_collation}
616
- add_column :ads, :body, :text#{', limit: 4294967295' if defined?(Mysql2)}, null: true#{charset_and_collation}
626
+ add_column :ads, :body, :text#{', limit: 4294967295' if current_adapter == 'mysql2'}, null: true#{charset_and_collation}
627
+ EOS
628
+ .and(migrate_down(<<~EOS.strip))
629
+ remove_column :ads, :body
630
+ remove_column :ads, :title
631
+ rename_table :ads, :adverts
617
632
  EOS
618
- .and migrate_down(<<~EOS.strip)
619
- remove_column :ads, :body
620
- remove_column :ads, :title
621
- rename_table :ads, :adverts
622
- EOS
623
633
  )
624
634
 
625
635
  # Set the table name back to what it should be and confirm we're in sync:
626
636
 
627
637
  nuke_model_class(Advert)
628
638
 
629
- class Advert < ActiveRecord::Base
639
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
630
640
  self.table_name = "adverts"
631
641
  end
632
642
 
@@ -638,7 +648,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
638
648
 
639
649
  nuke_model_class(Advert)
640
650
 
641
- class Advertisement < ActiveRecord::Base
651
+ class Advertisement < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
642
652
  declare_schema do
643
653
  string :title, limit: 250, null: true
644
654
  text :body, null: true
@@ -649,14 +659,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
649
659
  migrate_up(<<~EOS.strip)
650
660
  rename_table :adverts, :advertisements
651
661
  add_column :advertisements, :title, :string, limit: 250, null: true#{charset_and_collation}
652
- add_column :advertisements, :body, :text#{', limit: 4294967295' if defined?(Mysql2)}, null: true#{charset_and_collation}
662
+ add_column :advertisements, :body, :text#{', limit: 4294967295' if current_adapter == 'mysql2'}, null: true#{charset_and_collation}
653
663
  remove_column :advertisements, :name
654
664
  EOS
655
- .and migrate_down(<<~EOS.strip)
656
- add_column :advertisements, :name, :string, limit: 250, null: true#{charset_and_collation}
657
- remove_column :advertisements, :body
658
- remove_column :advertisements, :title
659
- rename_table :advertisements, :adverts
665
+ .and(migrate_down(<<~EOS.strip))
666
+ add_column :advertisements, :name, :string, limit: 250, null: true#{charset_and_collation}
667
+ remove_column :advertisements, :body
668
+ remove_column :advertisements, :title
669
+ rename_table :advertisements, :adverts
660
670
  EOS
661
671
  )
662
672
 
@@ -672,10 +682,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
672
682
  migrate_up(<<~EOS.strip)
673
683
  drop_table :adverts
674
684
  EOS
675
- .and migrate_down(<<~EOS.strip)
676
- create_table "adverts"#{table_options}, force: :cascade do |t|
677
- t.string "name", limit: 250#{charset_and_collation}
678
- end
685
+ .and(migrate_down(<<~EOS.strip))
686
+ create_table "adverts"#{table_options}, force: :cascade do |t|
687
+ t.string "name", limit: 250#{charset_and_collation}
688
+ end
679
689
  EOS
680
690
  )
681
691
 
@@ -685,7 +695,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
685
695
 
686
696
  # Adding a subclass or two should introduce the 'type' column and no other changes
687
697
 
688
- class Advert < ActiveRecord::Base
698
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
689
699
  declare_schema do
690
700
  text :body, null: true
691
701
  string :title, default: "Untitled", limit: 250, null: true
@@ -694,9 +704,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
694
704
  up = Generators::DeclareSchema::Migration::Migrator.run.first
695
705
  ActiveRecord::Migration.class_eval(up)
696
706
 
697
- class FancyAdvert < Advert
707
+ class FancyAdvert < Advert # rubocop:disable Lint/ConstantDefinitionInBlock
698
708
  end
699
- class SuperFancyAdvert < FancyAdvert
709
+
710
+ class SuperFancyAdvert < FancyAdvert # rubocop:disable Lint/ConstantDefinitionInBlock
700
711
  end
701
712
 
702
713
  expect(Generators::DeclareSchema::Migration::Migrator.run.first).to be_present
@@ -707,9 +718,9 @@ RSpec.describe 'DeclareSchema Migration Generator' do
707
718
  add_column :adverts, :type, :string, limit: 250, null: true#{charset_and_collation}
708
719
  add_index :adverts, [:type], name: :on_type
709
720
  EOS
710
- .and migrate_down(<<~EOS.strip)
711
- remove_index :adverts, name: :on_type
712
- remove_column :adverts, :type
721
+ .and(migrate_down(<<~EOS.strip))
722
+ remove_index :adverts, name: :on_type
723
+ remove_column :adverts, :type
713
724
  EOS
714
725
  )
715
726
  end
@@ -729,17 +740,16 @@ RSpec.describe 'DeclareSchema Migration Generator' do
729
740
  Advert.connection.schema_cache.clear!
730
741
  Advert.reset_column_information
731
742
 
732
- expect(Advert.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables).
733
- to eq(["adverts"])
743
+ expect(Advert.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables)
744
+ .to eq(["adverts"])
734
745
  expect(Advert.columns.map(&:name).sort).to eq(["body", "id", "title"])
735
746
  expect(Generators::DeclareSchema::Migration::Migrator.run).to eq(["", ""])
736
747
 
737
-
738
748
  ### Rename a column and change the default
739
749
 
740
750
  Advert.field_specs.clear
741
751
 
742
- class Advert < ActiveRecord::Base
752
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
743
753
  declare_schema do
744
754
  string :name, default: "No Name", limit: 250, null: true
745
755
  text :body, null: true
@@ -751,16 +761,16 @@ RSpec.describe 'DeclareSchema Migration Generator' do
751
761
  rename_column :adverts, :title, :name
752
762
  change_column :adverts, :name, :string, limit: 250, null: true, default: "No Name"#{charset_and_collation}
753
763
  EOS
754
- .and migrate_down(<<~EOS.strip)
755
- change_column :adverts, :name, :string, limit: 250, null: true, default: "Untitled"#{charset_and_collation}
756
- rename_column :adverts, :name, :title
764
+ .and(migrate_down(<<~EOS.strip))
765
+ change_column :adverts, :name, :string, limit: 250, null: true, default: "Untitled"#{charset_and_collation}
766
+ rename_column :adverts, :name, :title
757
767
  EOS
758
768
  )
759
769
 
760
770
  ### Rename a table and add a column
761
771
 
762
772
  nuke_model_class(Advert)
763
- class Ad < ActiveRecord::Base
773
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
764
774
  declare_schema do
765
775
  string :title, default: "Untitled", limit: 250
766
776
  text :body, null: true
@@ -776,7 +786,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
776
786
  EOS
777
787
  )
778
788
 
779
- class Advert < ActiveRecord::Base
789
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
780
790
  declare_schema do
781
791
  text :body, null: true
782
792
  string :title, default: "Untitled", limit: 250, null: true
@@ -789,7 +799,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
789
799
 
790
800
  nuke_model_class(Ad)
791
801
 
792
- class Advert < ActiveRecord::Base
802
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
793
803
  declare_schema do
794
804
  text :body, null: true
795
805
  end
@@ -803,13 +813,13 @@ RSpec.describe 'DeclareSchema Migration Generator' do
803
813
  )
804
814
 
805
815
  nuke_model_class(Advert)
806
- ActiveRecord::Base.connection.execute("drop table `adverts`;")
816
+ ActiveRecord::Base.connection.execute("DROP TABLE #{ActiveRecord::Base.connection.quote_table_name('adverts')};")
807
817
 
808
818
  ## DSL
809
819
 
810
820
  # The DSL allows lambdas and constants
811
821
 
812
- class User < ActiveRecord::Base
822
+ class User < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
813
823
  declare_schema do
814
824
  string :company, limit: 250, ruby_default: -> { "BigCorp" }
815
825
  end
@@ -823,14 +833,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
823
833
 
824
834
  # DeclareSchema can accept a validates hash in the field options.
825
835
 
826
- class Ad < ActiveRecord::Base
836
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
827
837
  class << self
828
838
  def validates(field_name, options)
829
839
  end
830
840
  end
831
841
  end
832
842
  expect(Ad).to receive(:validates).with(:company, presence: true, uniqueness: { case_sensitive: false })
833
- class Ad < ActiveRecord::Base
843
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
834
844
  declare_schema do
835
845
  string :company, limit: 250, index: true, unique: true, validates: { presence: true, uniqueness: { case_sensitive: false } }
836
846
  end
@@ -843,13 +853,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
843
853
  # DeclareSchema supports has_and_belongs_to_many relationships and generates the intersection ("join") table
844
854
  # with appropriate primary key, indexes, and foreign keys.
845
855
 
846
- class Advertiser < ActiveRecord::Base
856
+ class Advertiser < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
847
857
  declare_schema do
848
858
  string :name, limit: 250
849
859
  end
850
860
  has_and_belongs_to_many :creatives
851
861
  end
852
- class Creative < ActiveRecord::Base
862
+
863
+ class Creative < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
853
864
  declare_schema do
854
865
  string :url, limit: 500
855
866
  end
@@ -863,10 +874,10 @@ RSpec.describe 'DeclareSchema Migration Generator' do
863
874
  t.integer :advertiser_id, limit: 8, null: false
864
875
  t.integer :creative_id, limit: 8, null: false
865
876
  end
866
- create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
877
+ create_table :creatives, id: #{primary_key_type}#{create_table_charset_and_collation} do |t|
867
878
  t.string :url, limit: 500, null: false#{charset_and_collation}
868
879
  end
869
- create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
880
+ create_table :advertisers, id: #{primary_key_type}#{create_table_charset_and_collation} do |t|
870
881
  t.string :name, limit: 250, null: false#{charset_and_collation}
871
882
  end
872
883
  add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
@@ -875,14 +886,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
875
886
  EOS
876
887
  else
877
888
  migrate_up(<<~EOS.strip)
878
- create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
889
+ create_table :advertisers, id: #{primary_key_type}#{create_table_charset_and_collation} do |t|
879
890
  t.string :name, limit: 250, null: false#{charset_and_collation}
880
891
  end
881
892
  create_table :advertisers_creatives, primary_key: [:advertiser_id, :creative_id]#{create_table_charset_and_collation} do |t|
882
893
  t.integer :advertiser_id, limit: 8, null: false
883
894
  t.integer :creative_id, limit: 8, null: false
884
895
  end
885
- create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
896
+ create_table :creatives, id: #{primary_key_type}#{create_table_charset_and_collation} do |t|
886
897
  t.string :url, limit: 500, null: false#{charset_and_collation}
887
898
  end
888
899
  add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
@@ -898,19 +909,25 @@ RSpec.describe 'DeclareSchema Migration Generator' do
898
909
  end
899
910
 
900
911
  context 'models with the same parent foreign key relation' do
912
+ include_context 'skip if' do
913
+ let(:adapter) { 'sqlite3' }
914
+ end
915
+
901
916
  before do
902
- class Category < ActiveRecord::Base
917
+ class Category < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
903
918
  declare_schema do
904
919
  string :name, limit: 250, null: true
905
920
  end
906
921
  end
907
- class Advertiser < ActiveRecord::Base
922
+
923
+ class Advertiser < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
908
924
  declare_schema do
909
925
  string :name, limit: 250, null: true
910
926
  end
911
927
  belongs_to :category, limit: 8
912
928
  end
913
- class Affiliate < ActiveRecord::Base
929
+
930
+ class Affiliate < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
914
931
  declare_schema do
915
932
  string :name, limit: 250, null: true
916
933
  end
@@ -918,56 +935,27 @@ RSpec.describe 'DeclareSchema Migration Generator' do
918
935
  end
919
936
  end
920
937
 
938
+ let(:fixture_file_path) do
939
+ if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
940
+ "../../fixtures/migrations/#{current_adapter}/will_generate_unique_constraint_names_rails_7.txt"
941
+ else
942
+ "../../fixtures/migrations/#{current_adapter}/will_generate_unique_constraint_names_rails_6.txt"
943
+ end
944
+ end
945
+
921
946
  it 'will generate unique constraint names' do
922
- expect(Generators::DeclareSchema::Migration::Migrator.run).to(
923
- if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
924
- migrate_up(<<~EOS.strip)
925
- create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
926
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
927
- t.integer :category_id, limit: 8, null: false
928
- end
929
- create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
930
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
931
- t.integer :category_id, limit: 8, null: false
932
- end
933
- create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
934
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
935
- end
936
- add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
937
- add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
938
- add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
939
- add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
940
- EOS
941
- else
942
- migrate_up(<<~EOS.strip)
943
- create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
944
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
945
- end
946
- create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
947
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
948
- t.integer :category_id, limit: 8, null: false
949
- end
950
- create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
951
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
952
- t.integer :category_id, limit: 8, null: false
953
- end
954
- add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
955
- add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
956
- add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
957
- add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
958
- EOS
959
- end
960
- )
947
+ expect(Generators::DeclareSchema::Migration::Migrator.run).to(migrate_up(File.read(File.expand_path(fixture_file_path, __dir__)).chomp))
948
+
961
949
  migrate
962
950
 
963
951
  nuke_model_class(Advertiser)
964
952
  nuke_model_class(Affiliate)
965
953
  end
966
- end if !defined?(SQLite3)
954
+ end
967
955
 
968
956
  describe 'serialize' do
969
957
  before do
970
- class Ad < ActiveRecord::Base
958
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
971
959
  @serialize_args = []
972
960
 
973
961
  class << self
@@ -982,7 +970,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
982
970
 
983
971
  describe 'untyped' do
984
972
  it 'allows serialize: true' do
985
- class Ad < ActiveRecord::Base
973
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
986
974
  declare_schema do
987
975
  text :allow_list, limit: 0xFFFF, serialize: true
988
976
  end
@@ -992,7 +980,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
992
980
  end
993
981
 
994
982
  it 'converts defaults with .to_yaml' do
995
- class Ad < ActiveRecord::Base
983
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
996
984
  declare_schema do
997
985
  string :allow_list, limit: 250, serialize: true, null: true, default: []
998
986
  string :allow_hash, limit: 250, serialize: true, null: true, default: {}
@@ -1010,7 +998,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1010
998
 
1011
999
  describe 'Array' do
1012
1000
  it 'allows serialize: Array' do
1013
- class Ad < ActiveRecord::Base
1001
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1014
1002
  declare_schema do
1015
1003
  string :allow_list, limit: 250, serialize: Array, null: true
1016
1004
  end
@@ -1020,7 +1008,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1020
1008
  end
1021
1009
 
1022
1010
  it 'allows Array defaults' do
1023
- class Ad < ActiveRecord::Base
1011
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1024
1012
  declare_schema do
1025
1013
  string :allow_list, limit: 250, serialize: Array, null: true, default: [2]
1026
1014
  string :allow_string, limit: 250, serialize: Array, null: true, default: ['abc']
@@ -1038,7 +1026,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1038
1026
 
1039
1027
  describe 'Hash' do
1040
1028
  it 'allows serialize: Hash' do
1041
- class Ad < ActiveRecord::Base
1029
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1042
1030
  declare_schema do
1043
1031
  string :allow_list, limit: 250, serialize: Hash, null: true
1044
1032
  end
@@ -1048,7 +1036,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1048
1036
  end
1049
1037
 
1050
1038
  it 'allows Hash defaults' do
1051
- class Ad < ActiveRecord::Base
1039
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1052
1040
  declare_schema do
1053
1041
  string :allow_loc, limit: 250, serialize: Hash, null: true, default: { 'state' => 'CA' }
1054
1042
  string :allow_hash, limit: 250, serialize: Hash, null: true, default: {}
@@ -1064,7 +1052,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1064
1052
 
1065
1053
  describe 'JSON' do
1066
1054
  it 'allows serialize: JSON' do
1067
- class Ad < ActiveRecord::Base
1055
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1068
1056
  declare_schema do
1069
1057
  string :allow_list, limit: 250, serialize: JSON
1070
1058
  end
@@ -1074,7 +1062,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1074
1062
  end
1075
1063
 
1076
1064
  it 'allows JSON defaults' do
1077
- class Ad < ActiveRecord::Base
1065
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1078
1066
  declare_schema do
1079
1067
  string :allow_hash, limit: 250, serialize: JSON, null: true, default: { 'state' => 'CA' }
1080
1068
  string :allow_empty_array, limit: 250, serialize: JSON, null: true, default: []
@@ -1090,7 +1078,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1090
1078
  end
1091
1079
  end
1092
1080
 
1093
- class ValueClass
1081
+ class ValueClass # rubocop:disable Lint/ConstantDefinitionInBlock
1094
1082
  delegate :present?, :inspect, to: :@value
1095
1083
 
1096
1084
  def initialize(value)
@@ -1114,7 +1102,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1114
1102
 
1115
1103
  describe 'custom coder' do
1116
1104
  it 'allows serialize: ValueClass' do
1117
- class Ad < ActiveRecord::Base
1105
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1118
1106
  declare_schema do
1119
1107
  string :allow_list, limit: 250, serialize: ValueClass
1120
1108
  end
@@ -1124,7 +1112,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1124
1112
  end
1125
1113
 
1126
1114
  it 'allows ValueClass defaults' do
1127
- class Ad < ActiveRecord::Base
1115
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1128
1116
  declare_schema do
1129
1117
  string :allow_hash, limit: 250, serialize: ValueClass, null: true, default: ValueClass.new([2])
1130
1118
  string :allow_empty_array, limit: 250, serialize: ValueClass, null: true, default: ValueClass.new([])
@@ -1140,7 +1128,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1140
1128
 
1141
1129
  it 'disallows serialize: with a non-string column type' do
1142
1130
  expect do
1143
- class Ad < ActiveRecord::Base
1131
+ class Ad < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1144
1132
  declare_schema do
1145
1133
  integer :allow_list, limit: 8, serialize: true
1146
1134
  end
@@ -1163,7 +1151,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1163
1151
  end
1164
1152
  end
1165
1153
 
1166
- class Advert < ActiveRecord::Base
1154
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1167
1155
  declare_schema do
1168
1156
  string :name, limit: 250, null: true
1169
1157
  integer :category_id, limit: 8
@@ -1175,7 +1163,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1175
1163
  end
1176
1164
 
1177
1165
  it 'passes through optional: when given' do
1178
- class AdvertBelongsTo < ActiveRecord::Base
1166
+ class AdvertBelongsTo < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1179
1167
  self.table_name = 'adverts'
1180
1168
  declare_schema { }
1181
1169
  reset_column_information
@@ -1186,7 +1174,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1186
1174
 
1187
1175
  describe 'contradictory settings' do # contradictory settings are ok--for example, during migration
1188
1176
  it 'passes through optional: true, null: false' do
1189
- class AdvertBelongsTo < ActiveRecord::Base
1177
+ class AdvertBelongsTo < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1190
1178
  self.table_name = 'adverts'
1191
1179
  declare_schema { }
1192
1180
  reset_column_information
@@ -1197,7 +1185,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1197
1185
  end
1198
1186
 
1199
1187
  it 'passes through optional: false, null: true' do
1200
- class AdvertBelongsTo < ActiveRecord::Base
1188
+ class AdvertBelongsTo < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1201
1189
  self.table_name = 'adverts'
1202
1190
  declare_schema { }
1203
1191
  reset_column_information
@@ -1211,7 +1199,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1211
1199
  [false, true].each do |nullable|
1212
1200
  context "nullable=#{nullable}" do
1213
1201
  it 'infers optional: from null:' do
1214
- eval <<~EOS
1202
+ eval <<~EOS # rubocop:disable Style/EvalWithLocation,Security/Eval
1215
1203
  class AdvertBelongsTo < ActiveRecord::Base
1216
1204
  declare_schema { }
1217
1205
  belongs_to :ad_category, null: #{nullable}
@@ -1222,7 +1210,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1222
1210
  end
1223
1211
 
1224
1212
  it 'infers null: from optional:' do
1225
- eval <<~EOS
1213
+ eval <<~EOS # rubocop:disable Style/EvalWithLocation,Security/Eval
1226
1214
  class AdvertBelongsTo < ActiveRecord::Base
1227
1215
  declare_schema { }
1228
1216
  belongs_to :ad_category, optional: #{nullable}
@@ -1235,8 +1223,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1235
1223
  end
1236
1224
 
1237
1225
  it 'deprecates limit:' do
1238
- expect(ActiveSupport::Deprecation).to receive(:warn).with("belongs_to :ad_category, limit: is deprecated since it is now inferred")
1239
- eval <<~EOS
1226
+ expect(DeclareSchema.deprecator).to receive(:warn).with("belongs_to :ad_category, limit: is deprecated since it is now inferred")
1227
+ eval <<~EOS # rubocop:disable Style/EvalWithLocation
1240
1228
  class UsingLimit < ActiveRecord::Base
1241
1229
  declare_schema { }
1242
1230
  belongs_to :ad_category, limit: 4
@@ -1247,18 +1235,21 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1247
1235
 
1248
1236
  context 'when parent object PKs have different limits' do
1249
1237
  before do
1250
- class IdDefault < ActiveRecord::Base
1238
+ class IdDefault < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1251
1239
  declare_schema { }
1252
1240
  end
1253
- class Id4 < ActiveRecord::Base
1241
+
1242
+ class Id4 < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1254
1243
  declare_schema id: :integer do
1255
1244
  end
1256
1245
  end
1257
- class Id8 < ActiveRecord::Base
1246
+
1247
+ class Id8 < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1258
1248
  declare_schema id: :bigint do
1259
1249
  end
1260
1250
  end
1261
- class Fk < ActiveRecord::Base
1251
+
1252
+ class Fk < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1262
1253
  declare_schema { }
1263
1254
  belongs_to :id_default
1264
1255
  belongs_to :id4
@@ -1271,7 +1262,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1271
1262
 
1272
1263
  create_id4_defaults = up.split("\n").grep(/create_table :id_defaults/).first
1273
1264
  expect(create_id4_defaults).to be, up
1274
- expect(create_id4_defaults).to match(/, id: :bigint/)
1265
+ case current_adapter
1266
+ when 'postgresql'
1267
+ expect(create_id4_defaults).to match(/, id: :bigserial/)
1268
+ else
1269
+ expect(create_id4_defaults).to match(/, id: :bigint/)
1270
+ end
1275
1271
 
1276
1272
  create_id4s = up.split("\n").grep(/create_table :id4s/).first
1277
1273
  expect(create_id4s).to be, up
@@ -1286,7 +1282,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1286
1282
  up = Generators::DeclareSchema::Migration::Migrator.run.first
1287
1283
 
1288
1284
  create_fks = up.split("\n").grep(/t\.integer /).map { |command| command.gsub(', null: false', '').gsub(/^ +/, '') }
1289
- if defined?(SQLite3)
1285
+ if current_adapter == 'sqlite3'
1290
1286
  create_fks.map! { |command| command.gsub(/limit: [a-z0-9]+/, 'limit: X') }
1291
1287
  expect(create_fks).to eq([
1292
1288
  't.integer :id_default_id, limit: X',
@@ -1312,20 +1308,22 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1312
1308
  nuke_model_class(Fk)
1313
1309
  ActiveRecord::Base.connection.schema_cache.clear!
1314
1310
 
1315
-
1316
- class NewIdDefault < ActiveRecord::Base
1311
+ class NewIdDefault < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1317
1312
  self.table_name = 'id_defaults'
1318
1313
  declare_schema { }
1319
1314
  end
1320
- class NewId4 < ActiveRecord::Base
1315
+
1316
+ class NewId4 < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1321
1317
  self.table_name = 'id4s'
1322
1318
  declare_schema { }
1323
1319
  end
1324
- class NewId8 < ActiveRecord::Base
1320
+
1321
+ class NewId8 < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1325
1322
  self.table_name = 'id8s'
1326
1323
  declare_schema { }
1327
1324
  end
1328
- class NewFk < ActiveRecord::Base
1325
+
1326
+ class NewFk < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
1329
1327
  declare_schema { }
1330
1328
  belongs_to :new_id_default
1331
1329
  belongs_to :new_id4
@@ -1337,7 +1335,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1337
1335
  up = Generators::DeclareSchema::Migration::Migrator.run.first
1338
1336
 
1339
1337
  create_fks = up.split("\n").grep(/t\.integer /).map { |command| command.gsub(', null: false', '').gsub(/^ +/, '') }
1340
- if defined?(SQLite3)
1338
+ if current_adapter == 'sqlite3'
1341
1339
  create_fks.map! { |command| command.gsub(/limit: [a-z0-9]+/, 'limit: X') }
1342
1340
  expect(create_fks).to eq([
1343
1341
  't.integer :new_id_default_id, limit: X',
@@ -1359,7 +1357,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1359
1357
 
1360
1358
  describe 'migration base class' do
1361
1359
  it 'adapts to Rails 4' do
1362
- class Advert < active_record_base_class.constantize
1360
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1363
1361
  declare_schema do
1364
1362
  string :title, limit: 100
1365
1363
  end
@@ -1379,7 +1377,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1379
1377
 
1380
1378
  context 'Does not generate migrations' do
1381
1379
  it 'for aliased fields bigint -> integer limit 8' do
1382
- class Advert < active_record_base_class.constantize
1380
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1383
1381
  declare_schema do
1384
1382
  bigint :price
1385
1383
  end
@@ -1390,7 +1388,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1390
1388
  migrations = Dir.glob('db/migrate/*declare_schema_migration*.rb')
1391
1389
  expect(migrations.size).to eq(1), migrations.inspect
1392
1390
 
1393
- class Advert < active_record_base_class.constantize
1391
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1394
1392
  declare_schema do
1395
1393
  integer :price, limit: 8
1396
1394
  end
@@ -1404,7 +1402,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1404
1402
  let(:default_schema_block) { nil }
1405
1403
  let(:declare_model) do
1406
1404
  -> do
1407
- class Advert < active_record_base_class.constantize
1405
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1408
1406
  declare_schema do
1409
1407
  integer :price, limit: 8
1410
1408
  end
@@ -1444,7 +1442,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1444
1442
 
1445
1443
  context 'and the model sets default_schema: false' do
1446
1444
  before do
1447
- class Advert < active_record_base_class.constantize
1445
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1448
1446
  declare_schema default_schema: false do
1449
1447
  integer :price, limit: 8
1450
1448
  end
@@ -1458,7 +1456,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1458
1456
 
1459
1457
  context 'and the block has redundant fields' do
1460
1458
  before do
1461
- class Advert < active_record_base_class.constantize
1459
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1462
1460
  declare_schema do
1463
1461
  integer :price, limit: 8
1464
1462
  timestamps
@@ -1475,7 +1473,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1475
1473
 
1476
1474
  context 'index' do
1477
1475
  before do
1478
- class Advert < active_record_base_class.constantize
1476
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1479
1477
  declare_schema { }
1480
1478
  belongs_to :ad_category
1481
1479
  end
@@ -1501,7 +1499,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1501
1499
 
1502
1500
  context 'constraint' do
1503
1501
  before do
1504
- class Advert < active_record_base_class.constantize
1502
+ class Advert < active_record_base_class.constantize # rubocop:disable Lint/ConstantDefinitionInBlock
1505
1503
  declare_schema { }
1506
1504
  belongs_to :ad_category
1507
1505
  end
@@ -1509,13 +1507,14 @@ RSpec.describe 'DeclareSchema Migration Generator' do
1509
1507
 
1510
1508
  it "when exactly equal, it is idempotent and doesn't raise" do
1511
1509
  expect do
1512
- Advert.constraint :ad_category_id, parent_table_name: 'ad_categories', constraint_name: :index_adverts_on_ad_category_id, parent_class_name: 'AdCategory'
1510
+ Advert.constraint(:ad_category_id, parent_table_name: 'ad_categories',
1511
+ constraint_name: :index_adverts_on_ad_category_id, parent_class_name: 'AdCategory')
1513
1512
  end.to_not change { Advert.index_definitions.size }
1514
1513
  end
1515
1514
 
1516
1515
  it "when equivalent, it is idempotent and doesn't raise" do
1517
1516
  expect do
1518
- Advert.constraint :ad_category_id, parent_table_name: 'ad_categories', constraint_name: :constraint_1, parent_class_name: 'AdCategory'
1517
+ Advert.constraint(:ad_category_id, parent_table_name: 'ad_categories', constraint_name: :constraint_1, parent_class_name: 'AdCategory')
1519
1518
  end.to_not change { Advert.index_definitions.size }
1520
1519
  end
1521
1520
  end