From 97849debf33123387d33ba11fa5cf776873a5e94 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 23 Jan 2005 15:19:33 +0000 Subject: [PATCH] Fixed that association proxies would fail === tests like PremiumSubscription === @account.subscription git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@476 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/base.rb | 5 +++++ activerecord/test/associations_test.rb | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e006a34edc..65174cb1b8 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that association proxies would fail === tests like PremiumSubscription === @account.subscription + * Fixed that column aliases didn't work as expected with the new MySql411 driver #507 [Demetrius] * Fixed that find_all would produce invalid sql when called sequentialy #490 [Scott Baron] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5af24caeef..bae91da22d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -598,6 +598,11 @@ module ActiveRecord #:nodoc: return result end + # Overwrite the default class equality method to provide support for association proxies. + def ===(object) + object.is_a?(self) + end + private # Finder methods must instantiate through this method to work with the single-table inheritance model # that makes it possible to create objects of different types from the same table. diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 0e992526bc..420fae069b 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -74,6 +74,10 @@ class HasOneAssociationsTest < Test::Unit::TestCase assert_equal Account.find(1).credit_limit, @signals37.account.credit_limit end + def test_triple_equality + assert Account === @signals37.account + end + def test_type_mismatch assert_raises(ActiveRecord::AssociationTypeMismatch) { @signals37.account = 1 } assert_raises(ActiveRecord::AssociationTypeMismatch) { @signals37.account = Project.find(1) }