diff options
author | James Le Cuirot <james.le-cuirot@yakara.com> | 2015-03-18 15:15:05 +0000 |
---|---|---|
committer | James Le Cuirot <james.le-cuirot@yakara.com> | 2018-10-29 15:11:35 +0000 |
commit | cf1d75d95d06ce3ac9e3ab7f19ecc17b49530942 (patch) | |
tree | fdb7c6f84f92f5f90bf346447ea5d5dce277e466 /activerecord/test | |
parent | 0d68e0690f449bf815c975c25d4d74917d3cad11 (diff) | |
download | rails-cf1d75d95d06ce3ac9e3ab7f19ecc17b49530942.tar.gz rails-cf1d75d95d06ce3ac9e3ab7f19ecc17b49530942.tar.bz2 rails-cf1d75d95d06ce3ac9e3ab7f19ecc17b49530942.zip |
Avoid violating key constraints in fixture HABTM associations
When loading fixtures, Ruby 1.9's hash key ordering means that HABTM
join table rows are always loaded before the parent table rows,
violating foreign key constraints that may be in place. This very
simple change ensures that the parent table's key appears first in the
hash. Violations may still occur if fixtures are loaded in the wrong
order but those instances can be avoided unlike this one.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 82ca15b415..1092b9553f 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -619,6 +619,10 @@ class HasManyThroughFixture < ActiveRecord::TestCase assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrot_treasures"] end + def test_has_and_belongs_to_many_order + assert_equal ["parrots", "parrots_treasures"], load_has_and_belongs_to_many.keys + end + def load_has_and_belongs_to_many parrot = make_model "Parrot" parrot.has_and_belongs_to_many :treasures |