diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-24 16:24:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-24 16:24:38 -0800 |
commit | f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4 (patch) | |
tree | 6d34ad08f99ec8dc0192a7b1474342634616f41d /activerecord/test/cases | |
parent | f4f94081dd1a3e9ff99e17ae88b7d91fcdbb19fc (diff) | |
parent | 8e16a00de4f77f15e405d083d535b92a23779d9d (diff) | |
download | rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.tar.gz rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.tar.bz2 rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.zip |
Merge pull request #17426 from jpcody/fixture_associations_fix
Rely on through table name in has_many fixtures
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index f41245dfd2..7ef2ebc998 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -273,7 +273,7 @@ class HasManyThroughFixture < ActiveSupport::TestCase Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } end - def test_has_many_through + def test_has_many_through_with_default_table_name pt = make_model "ParrotTreasure" parrot = make_model "Parrot" treasure = make_model "Treasure" @@ -292,6 +292,24 @@ class HasManyThroughFixture < ActiveSupport::TestCase assert_equal load_has_and_belongs_to_many['parrots_treasures'], rows['parrots_treasures'] end + def test_has_many_through_with_renamed_table + pt = make_model "ParrotTreasure" + parrot = make_model "Parrot" + treasure = make_model "Treasure" + + pt.belongs_to :parrot, :class => parrot + pt.belongs_to :treasure, :class => treasure + + parrot.has_many :parrot_treasures, :class => pt + parrot.has_many :treasures, :through => :parrot_treasures + + parrots = File.join FIXTURES_ROOT, 'parrots' + + fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots + rows = fs.table_rows + assert_equal load_has_and_belongs_to_many['parrots_treasures'], rows['parrot_treasures'] + end + def load_has_and_belongs_to_many parrot = make_model "Parrot" parrot.has_and_belongs_to_many :treasures |