diff options
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/cases/associations_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 4 |
3 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index c415ad2df3..68503a3c40 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -118,7 +118,7 @@ module ActiveRecord end def inspect - reload unless loaded? + load_target @target.inspect end @@ -167,7 +167,7 @@ module ActiveRecord def with_scope(*args, &block) @reflection.klass.send :with_scope, *args, &block end - + private def method_missing(method, *args) if load_target diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index ed2fab6d22..d8fe98bf57 100755 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -149,6 +149,12 @@ class AssociationProxyTest < ActiveRecord::TestCase assert !david.projects.loaded? end + def test_inspect_does_not_reload_a_not_yet_loaded_target + andreas = Developer.new :name => 'Andreas', :log => 'new developer added' + assert !andreas.audit_logs.loaded? + assert_match(/message: "new developer added"/, andreas.audit_logs.inspect) + end + def test_save_on_parent_saves_children developer = Developer.create :name => "Bryan", :salary => 50_000 assert_equal 1, developer.reload.audit_logs.size diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 192c2cb5ab..f77fd0e96d 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -49,6 +49,10 @@ class Developer < ActiveRecord::Base before_create do |developer| developer.audit_logs.build :message => "Computer created" end + + def log=(message) + audit_logs.build :message => message + end end class AuditLog < ActiveRecord::Base |