diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-24 07:51:01 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-24 07:51:01 -0800 |
commit | 83a9efb8292dcea15defc5c913b66e2c456937c0 (patch) | |
tree | 0d4e017c6826cdb3ae559052aa450ee7a7d8f5ea /activerecord/test/cases/associations | |
parent | fb40358f4f3d0028bbcd1a8f1fc74b1453e2014a (diff) | |
parent | 96c1cafd3ab6250875cc62034000ea83ae1587af (diff) | |
download | rails-83a9efb8292dcea15defc5c913b66e2c456937c0.tar.gz rails-83a9efb8292dcea15defc5c913b66e2c456937c0.tar.bz2 rails-83a9efb8292dcea15defc5c913b66e2c456937c0.zip |
Merge pull request #9397 from senny/9201_duplicate_associations_with_natural_key
test case to prevent duplicated associations with custom PK.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index fd6d531645..d0add42e1e 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -20,6 +20,8 @@ require 'models/car' require 'models/bulb' require 'models/engine' require 'models/categorization' +require 'models/minivan' +require 'models/speedometer' class HasManyAssociationsTestForCountWithFinderSql < ActiveRecord::TestCase class Invoice < ActiveRecord::Base @@ -1747,4 +1749,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase david.posts_with_special_categorizations = [] assert_equal [], david.posts_with_special_categorizations end + + test "does not duplicate associations when used with natural primary keys" do + speedometer = Speedometer.create!(id: '4') + minivan = speedometer.minivans.create!(minivan_id: 'a-van-red' ,name: 'a van', color: 'red') + + assert_equal 1, speedometer.minivans.to_a.size, "Only one association should be present:\n#{speedometer.minivans.to_a}" + assert_equal 1, speedometer.reload.minivans.to_a.size + end end |