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

Ticket #8700: improve_ares_validations_test_coverage.diff

File improve_ares_validations_test_coverage.diff, 1.4 kB (added by josh, 2 years ago)
  • activeresource/test/base_errors_test.rb

    old new  
    99    @person = Person.new(:name => '', :age => '') 
    1010    assert_equal @person.save, false 
    1111  end 
    12    
     12 
    1313  def test_should_mark_as_invalid 
    1414    assert !@person.valid? 
    1515  end 
    16    
     16 
    1717  def test_should_parse_xml_errors 
    1818    assert_kind_of ActiveResource::Errors, @person.errors 
    1919    assert_equal 4, @person.errors.size 
    2020  end 
    2121 
    2222  def test_should_parse_errors_to_individual_attributes 
     23    assert @person.errors.invalid?(:name)     
    2324    assert_equal "can't be blank", @person.errors.on(:age) 
    2425    assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] 
    2526    assert_equal "Person quota full for today.", @person.errors.on_base 
    2627  end 
    2728 
     29  def test_should_iterate_over_errors 
     30    errors = [] 
     31    @person.errors.each { |attribute, message| errors << [attribute, message] } 
     32    assert_equal ["name", "can't be blank"], errors.first 
     33  end 
     34 
     35  def test_should_iterate_over_full_errors 
     36    errors = [] 
     37    @person.errors.each_full { |message| errors << message } 
     38    assert_equal "Name can't be blank", errors.first 
     39  end 
     40 
    2841  def test_should_format_full_errors 
    2942    full = @person.errors.full_messages 
    3043    assert full.include?("Age can't be blank")