public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/JackDanger/rails.git
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
NZKoz (author)
Wed Nov 28 18:19:10 -0800 2007
commit  e302759451fbed36d7e8916d7b5c8377762e3efd
tree    b81444c861a94fab84a87cc0a6b5a112635fe581
parent  0a9bc591e78382b221ef5c2f463bac90564b9982
...
46
47
48
49
50
 
51
52
53
...
46
47
48
 
49
50
51
52
53
0
@@ -46,8 +46,8 @@ module ActiveRecord
0
       alias :sql_conditions :conditions
0
       
0
       def reset
0
- @target = nil
0
         @loaded = false
0
+ @target = nil
0
       end
0
 
0
       def reload
...
122
123
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
126
127
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
0
@@ -122,6 +122,23 @@ class AssociationProxyTest < Test::Unit::TestCase
0
     developer = Developer.create :name => "Bryan", :salary => 50_000
0
     assert_equal 1, developer.reload.audit_logs.size
0
   end
0
+
0
+ def test_failed_reload_returns_nil
0
+ p = setup_dangling_association
0
+ assert_nil p.author.reload
0
+ end
0
+
0
+ def test_failed_reset_returns_nil
0
+ p = setup_dangling_association
0
+ assert_nil p.author.reset
0
+ end
0
+
0
+ def setup_dangling_association
0
+ josh = Author.create(:name => "Josh")
0
+ p = Post.create(:title => "New on Edge", :body => "More cool stuff!", :author => josh)
0
+ josh.destroy
0
+ p
0
+ end
0
 end
0
 
0
 class HasOneAssociationsTest < Test::Unit::TestCase

Comments

    No one has commented yet.