aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb2
-rwxr-xr-xactiverecord/test/associations_test.rb17
2 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 32810c91e0..1e4414cfe3 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -46,8 +46,8 @@ module ActiveRecord
alias :sql_conditions :conditions
def reset
- @target = nil
@loaded = false
+ @target = nil
end
def reload
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 20224cbd42..f2a87eec49 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -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