Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11514: inspect_on_new_object_association_does_not_reload_association.diff

File inspect_on_new_object_association_does_not_reload_association.diff, 1.2 kB (added by acirugeda, 4 months ago)
  • activerecord/test/cases/associations_test.rb

    old new  
    141141    assert_equal 1, josh.posts.size 
    142142  end 
    143143 
     144  def test_inspect_does_not_lose_additions_to_new_record 
     145    andres = Author.new(:name => "Andrés") 
     146    andres.posts.build(:title => "New on Edge", :body => "More cool stuff!") 
     147    assert !andres.posts.loaded? 
     148    assert_equal 1, andres.posts.size 
     149    andres.posts.inspect 
     150    assert !andres.posts.loaded? 
     151    assert_equal 1, andres.posts.size 
     152  end 
     153 
    144154  def test_save_on_parent_does_not_load_target 
    145155    david = developers(:david) 
    146156 
  • activerecord/lib/active_record/associations/association_proxy.rb

    old new  
    7373      end 
    7474 
    7575      def inspect 
    76         reload unless loaded? 
     76        reload unless loaded? || (@owner.new_record? && !foreign_key_present) 
    7777        @target.inspect 
    7878      end 
    7979