aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-27 17:28:24 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-27 17:28:24 -0300
commit722b2729b04954f92a04acd0a28efeb6eb1b7d6d (patch)
treea16e4b55e40b5bb1c542c771039397918f904301 /activerecord/test
parentab6f0dfbd7371c820fd141a63716633240bb71e5 (diff)
parent4f1ec3ac96d4593063603306d2548e0206124d5c (diff)
downloadrails-722b2729b04954f92a04acd0a28efeb6eb1b7d6d.tar.gz
rails-722b2729b04954f92a04acd0a28efeb6eb1b7d6d.tar.bz2
rails-722b2729b04954f92a04acd0a28efeb6eb1b7d6d.zip
Merge pull request #20849 from vngrs/misleading_nested_exceptions
Fix misleading errors for has_one through relations
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_one_through_associations_test.rb7
-rw-r--r--activerecord/test/cases/associations/nested_through_associations_test.rb2
-rw-r--r--activerecord/test/models/member_detail.rb7
3 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb
index 97fd458994..2c8feb9152 100644
--- a/activerecord/test/cases/associations/has_one_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -352,4 +352,11 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
assert_deprecated { member.club(true) }
end
+
+ def test_has_one_through_associations_are_mutable_unless_through_belongs_to
+ member_detail = MemberDetail.new(member: @member)
+ assert_raise(ActiveRecord::HasOneThroughCantAssociateThroughHasOneOrManyReflection) do
+ member_detail.membership = Membership.new
+ end
+ end
end
diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb
index 31b68c940e..b040485d99 100644
--- a/activerecord/test/cases/associations/nested_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_through_associations_test.rb
@@ -495,7 +495,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase
groucho = members(:groucho)
founding = member_types(:founding)
- assert_raises(ActiveRecord::HasManyThroughNestedAssociationsAreReadonly) do
+ assert_raises(ActiveRecord::HasOneThroughNestedAssociationsAreReadonly) do
groucho.nested_member_type = founding
end
end
diff --git a/activerecord/test/models/member_detail.rb b/activerecord/test/models/member_detail.rb
index 9d253aa126..157130986c 100644
--- a/activerecord/test/models/member_detail.rb
+++ b/activerecord/test/models/member_detail.rb
@@ -1,7 +1,8 @@
class MemberDetail < ActiveRecord::Base
- belongs_to :member, :inverse_of => false
+ belongs_to :member, inverse_of: false
belongs_to :organization
- has_one :member_type, :through => :member
+ has_one :member_type, through: :member
+ has_one :membership, through: :member
- has_many :organization_member_details, :through => :organization, :source => :member_details
+ has_many :organization_member_details, through: :organization, source: :member_details
end