提交 3441dfdb 编写于 作者: J Jeremy Kemper

Associations handle case-equality more consistently: item.parts.is_a?(Array)...

Associations handle case-equality more consistently: item.parts.is_a?(Array) and item.parts === Array.  Closes #1345.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3043 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 4f4aa4a1
*SVN*
* Associations handle case-equality more consistently: item.parts.is_a?(Array) and item.parts === Array. #1345 [MarkusQ@reality.com]
* SQLServer: insert uses given primary key value if not nil rather than SELECT @@IDENTITY. #2866 [kajism@yahoo.com, Tom Ward <tom@popdog.net>]
* Oracle: active? and reconnect! methods for handling stale connections. Optionally retry queries after reconnect. #428 [Michael Schoen <schoenm@earthlink.net>]
......
......@@ -17,13 +17,20 @@ def initialize(owner, association_name, association_class_name, association_clas
reset
end
def reload
reset
def respond_to?(symbol, include_priv = false)
proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
end
# Explicitly proxy === because the instance method removal above
# doesn't catch it.
def ===(other)
load_target
other === @target
end
def respond_to?(symbol, include_priv = false)
proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
def reload
reset
load_target
end
def loaded?
......@@ -98,4 +105,4 @@ def raise_on_type_mismatch(record)
end
end
end
end
\ No newline at end of file
end
......@@ -79,6 +79,7 @@ def test_proxy_assignment
def test_triple_equality
assert Account === companies(:first_firm).account
assert companies(:first_firm).account === Account
end
def test_type_mismatch
......@@ -280,6 +281,11 @@ def test_finding
assert_equal 2, Firm.find(:first).clients.length
end
def test_triple_equality
assert !(Array === Firm.find(:first).clients)
assert Firm.find(:first).clients === Array
end
def test_finding_default_orders
assert_equal "Summit", Firm.find(:first).clients.first.name
end
......@@ -747,6 +753,11 @@ def test_proxy_assignment
assert_nothing_raised { account.firm = account.firm }
end
def test_triple_equality
assert Client.find(3).firm === Firm
assert Firm === Client.find(3).firm
end
def test_type_mismatch
assert_raise(ActiveRecord::AssociationTypeMismatch) { Account.find(1).firm = 1 }
assert_raise(ActiveRecord::AssociationTypeMismatch) { Account.find(1).firm = Project.find(1) }
......@@ -1026,6 +1037,11 @@ def test_has_and_belongs_to_many
assert active_record.developers.include?(david)
end
def test_triple_equality
assert !(Array === Developer.find(1).projects)
assert Developer.find(1).projects === Array
end
def test_adding_single
jamis = Developer.find(2)
jamis.projects.reload # causing the collection to load
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册