Skip to content

Commit 62e3995

Browse files
fabricio.albarnazrafiss
authored andcommitted
Fix fixtures recreate table and column with max_identifier_length
1 parent 0a36c01 commit 62e3995

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

test/cases/fixtures_test.rb

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def before_setup
306306
id BIGINT PRIMARY KEY DEFAULT nextval('accounts_id_seq'),
307307
firm_id bigint,
308308
firm_name character varying,
309-
credit_limit integer
309+
credit_limit integer,
310+
#{'a' * max_identifier_length} integer
310311
)
311312
")
312313

@@ -382,6 +383,8 @@ def teardown
382383
t.column :name, :string, null: false
383384
t.column :college_id, :integer
384385
end
386+
387+
recreate_parrots
385388
end
386389

387390
# This replaces the same test that's been excluded from
@@ -437,12 +440,37 @@ def test_create_fixtures_resets_sequences_when_not_cached
437440
private
438441

439442
def max_identifier_length
440-
get_identifier.first.to_i
443+
ActiveRecord::Base.connection.index_name_length
441444
end
442445

443-
def get_identifier
444-
connection = ActiveRecord::Base.connection
445-
connection.execute("SHOW max_identifier_length").values.flatten
446+
def recreate_parrots
447+
conn = ActiveRecord::Base.connection
448+
449+
conn.drop_table :parrots_pirates, if_exists: true
450+
conn.drop_table :parrots_treasures, if_exists: true
451+
conn.drop_table :parrots, if_exists: true
452+
453+
conn.create_table :parrots, force: :cascade do |t|
454+
t.string :name
455+
t.string :color
456+
t.string :parrot_sti_class
457+
t.integer :killer_id
458+
t.integer :updated_count, :integer, default: 0
459+
t.datetime :created_at
460+
t.datetime :created_on
461+
t.datetime :updated_at
462+
t.datetime :updated_on
463+
end
464+
465+
conn.create_table :parrots_pirates, id: false, force: true do |t|
466+
t.references :parrot, foreign_key: true
467+
t.references :pirate, foreign_key: true
468+
end
469+
470+
conn.create_table :parrots_treasures, id: false, force: true do |t|
471+
t.references :parrot, foreign_key: true
472+
t.references :treasure, foreign_key: true
473+
end
446474
end
447475
end
448476
end

0 commit comments

Comments
 (0)