public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/edwin/rails.git
Calling ActiveRecord#inspect on an unloaded association won't wipe the 
collection [#9 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
zargony (author)
Wed May 07 22:04:53 -0700 2008
josh (committer)
Wed May 07 22:04:53 -0700 2008
commit  bcb090c56b842a76397e0ea32f54c942fd11910e
tree    2921e7b7b80559f1e20a335da021fdd308993eab
parent  2561732a08ae97fa44706a8eca4db147c4a7c286
...
118
119
120
121
 
122
123
124
...
167
168
169
170
 
171
172
173
...
118
119
120
 
121
122
123
124
...
167
168
169
 
170
171
172
173
0
@@ -118,7 +118,7 @@ module ActiveRecord
0
       end
0
 
0
       def inspect
0
- reload unless loaded?
0
+ load_target
0
         @target.inspect
0
       end
0
 
0
@@ -167,7 +167,7 @@ module ActiveRecord
0
         def with_scope(*args, &block)
0
           @reflection.klass.send :with_scope, *args, &block
0
         end
0
-
0
+
0
       private
0
         def method_missing(method, *args)
0
           if load_target
...
149
150
151
 
 
 
 
 
 
152
153
154
...
149
150
151
152
153
154
155
156
157
158
159
160
0
@@ -149,6 +149,12 @@ class AssociationProxyTest < ActiveRecord::TestCase
0
     assert !david.projects.loaded?
0
   end
0
 
0
+ def test_inspect_does_not_reload_a_not_yet_loaded_target
0
+ andreas = Developer.new :name => 'Andreas', :log => 'new developer added'
0
+ assert !andreas.audit_logs.loaded?
0
+ assert_match(/message: "new developer added"/, andreas.audit_logs.inspect)
0
+ end
0
+
0
   def test_save_on_parent_saves_children
0
     developer = Developer.create :name => "Bryan", :salary => 50_000
0
     assert_equal 1, developer.reload.audit_logs.size
...
49
50
51
 
 
 
 
52
53
54
...
49
50
51
52
53
54
55
56
57
58
0
@@ -49,6 +49,10 @@ class Developer < ActiveRecord::Base
0
   before_create do |developer|
0
     developer.audit_logs.build :message => "Computer created"
0
   end
0
+
0
+ def log=(message)
0
+ audit_logs.build :message => message
0
+ end
0
 end
0
 
0
 class AuditLog < ActiveRecord::Base

Comments

    No one has commented yet.