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
This commit is contained in:
Michael Koziarski
2007-11-29 02:19:10 +00:00
parent 0a9bc591e7
commit e302759451
2 changed files with 18 additions and 1 deletions

View File

@@ -46,8 +46,8 @@ module ActiveRecord
alias :sql_conditions :conditions
def reset
@target = nil
@loaded = false
@target = nil
end
def reload

View File

@@ -122,6 +122,23 @@ class AssociationProxyTest < Test::Unit::TestCase
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