1 require "#{File.dirname(__FILE__)}/abstract_unit"
2 require "fixtures/person"
4 class BaseErrorsTest < Test::Unit::TestCase
6 ActiveResource::HttpMock.respond_to do |mock|
7 mock.post "/people.xml", {}, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error></errors>", 422
9 @person = Person.new(:name => '', :age => '')
10 assert_equal @person.save, false
13 def test_should_mark_as_invalid
14 assert !@person.valid?
17 def test_should_parse_xml_errors
18 assert_kind_of ActiveResource::Errors, @person.errors
19 assert_equal 4, @person.errors.size
22 def test_should_parse_errors_to_individual_attributes
23 assert_equal "can't be blank", @person.errors.on(:age)
24 assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name]
25 assert_equal "Person quota full for today.", @person.errors.on_base
28 def test_should_format_full_errors
29 full = @person.errors.full_messages
30 assert full.include?("Age can't be blank")
31 assert full.include?("Name can't be blank")
32 assert full.include?("Name must start with a letter")
33 assert full.include?("Person quota full for today.")