diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-06 11:29:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-06 11:29:40 -0700 |
commit | 59ba85fa5e31965130632d0c90c508693b14b086 (patch) | |
tree | 1cd5986da0779b216b11853774a6771f65536529 /activerecord/test | |
parent | 97a19c6b4b71d1e12d62d880ec8c8eed357b3d3c (diff) | |
download | rails-59ba85fa5e31965130632d0c90c508693b14b086.tar.gz rails-59ba85fa5e31965130632d0c90c508693b14b086.tar.bz2 rails-59ba85fa5e31965130632d0c90c508693b14b086.zip |
auto link hm:t fixture join tables like habtm
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 4e877aed2e..22eeb5076c 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -263,6 +263,41 @@ class FixturesTest < ActiveRecord::TestCase end end +class HasManyThroughFixture < ActiveSupport::TestCase + def make_model(name) + Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } + end + + def test_has_many_through + pt = make_model "ParrotTreasure" + parrot = make_model "Parrot" + treasure = make_model "Treasure" + + pt.table_name = "parrots_treasures" + 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['parrots_treasures'] + end + + def load_has_and_belongs_to_many + parrot = make_model "Parrot" + parrot.has_and_belongs_to_many :treasures + + parrots = File.join FIXTURES_ROOT, 'parrots' + + fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots + fs.table_rows + end +end + if Account.connection.respond_to?(:reset_pk_sequence!) class FixturesResetPkSequenceTest < ActiveRecord::TestCase fixtures :accounts |