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

Ticket #8713: test_for_edge.patch

File test_for_edge.patch, 1.4 kB (added by shoe, 6 months ago)

add a test_save_without_validations_after_build_without_loading_association

  • a/activerecord/test/cases/associations_test.rb

    old new  
    813813  def test_build_followed_by_save_does_not_load_target 
    814814    new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client") 
    815815    assert companies(:first_firm).save 
     816    assert !new_client.new_record? 
    816817    assert !companies(:first_firm).clients_of_firm.loaded? 
    817818  end 
    818819 
     
    830831    assert_equal 2, first_topic.replies.to_ary.size 
    831832  end 
    832833 
     834  def test_save_without_validations_after_build_without_loading_association 
     835    first_topic = topics(:first) 
     836    Reply.column_names 
     837 
     838    assert_equal 1, first_topic.replies.size 
     839    new_reply = nil 
     840 
     841    assert_no_queries do 
     842      new_reply = first_topic.replies.build(:title => "Not saved", :content => "Superstars") 
     843      assert new_reply.new_record? 
     844      assert_equal 2, first_topic.replies.size 
     845    end 
     846    assert first_topic.save(false) 
     847    assert !new_reply.new_record? 
     848 
     849    assert_equal 2, first_topic.replies.to_ary.size 
     850  end 
     851 
    833852  def test_create_without_loading_association 
    834853    first_firm  = companies(:first_firm) 
    835854    Firm.column_names