mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
d336ca5280
commit
97849debf3
3 changed files with 11 additions and 0 deletions
|
@ -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]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue