Lots going on
[lyrix.git] / vendor / rails / activeresource / test / base_errors_test.rb
blob3527eb2353c07a67e22b28a5bc909f6475c58843
1 require "#{File.dirname(__FILE__)}/abstract_unit"
2 require "fixtures/person"
4 class BaseErrorsTest < Test::Unit::TestCase
5   def setup
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
8     end
9     @person = Person.new(:name => '', :age => '')
10     assert_equal @person.save, false
11   end
12   
13   def test_should_mark_as_invalid
14     assert !@person.valid?
15   end
16   
17   def test_should_parse_xml_errors
18     assert_kind_of ActiveResource::Errors, @person.errors
19     assert_equal 4, @person.errors.size
20   end
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
26   end
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.")
34   end
35 end