提交 e3027594 编写于 作者: M Michael Koziarski

Make reset return nil when using a dangling belongs_to association. Current...

Make reset return nil when using a dangling belongs_to association.  Current behaviour is to return false which can be confusing. Closes #10293 [fcheung]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8236 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 0a9bc591
......@@ -46,8 +46,8 @@ def conditions
alias :sql_conditions :conditions
def reset
@target = nil
@loaded = false
@target = nil
end
def reload
......
......@@ -122,6 +122,23 @@ def test_save_on_parent_saves_children
developer = Developer.create :name => "Bryan", :salary => 50_000
assert_equal 1, developer.reload.audit_logs.size
end
def test_failed_reload_returns_nil
p = setup_dangling_association
assert_nil p.author.reload
end
def test_failed_reset_returns_nil
p = setup_dangling_association
assert_nil p.author.reset
end
def setup_dangling_association
josh = Author.create(:name => "Josh")
p = Post.create(:title => "New on Edge", :body => "More cool stuff!", :author => josh)
josh.destroy
p
end
end
class HasOneAssociationsTest < Test::Unit::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册