Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #9397 from senny/9201_duplicate_associations_with_…

…natural_key

test case to prevent duplicated associations with custom PK.
  • Loading branch information...
commit 83a9efb8292dcea15defc5c913b66e2c456937c0 2 parents fb40358 + 96c1caf
@rafaelfranca rafaelfranca authored
View
10 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -20,6 +20,8 @@
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 @@ def test_collection_association_with_private_kernel_method
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
View
2  activerecord/test/models/speedometer.rb
@@ -1,4 +1,6 @@
class Speedometer < ActiveRecord::Base
self.primary_key = :speedometer_id
belongs_to :dashboard
+
+ has_many :minivans
end
Please sign in to comment.
Something went wrong with that request. Please try again.