mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
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:
@@ -46,8 +46,8 @@ module ActiveRecord
|
||||
alias :sql_conditions :conditions
|
||||
|
||||
def reset
|
||||
@target = nil
|
||||
@loaded = false
|
||||
@target = nil
|
||||
end
|
||||
|
||||
def reload
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user