Froze rails gems
[depot.git] / vendor / rails / activeresource / test / base_errors_test.rb
1 require 'abstract_unit'
2 require "fixtures/person"
3
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
21
22 def test_should_parse_errors_to_individual_attributes
23 assert @person.errors.invalid?(:name)
24 assert_equal "can't be blank", @person.errors.on(:age)
25 assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name]
26 assert_equal "Person quota full for today.", @person.errors.on_base
27 end
28
29 def test_should_iterate_over_errors
30 errors = []
31 @person.errors.each { |attribute, message| errors << [attribute, message] }
32 assert errors.include?(["name", "can't be blank"])
33 end
34
35 def test_should_iterate_over_full_errors
36 errors = []
37 @person.errors.each_full { |message| errors << message }
38 assert errors.include?("Name can't be blank")
39 end
40
41 def test_should_format_full_errors
42 full = @person.errors.full_messages
43 assert full.include?("Age can't be blank")
44 assert full.include?("Name can't be blank")
45 assert full.include?("Name must start with a letter")
46 assert full.include?("Person quota full for today.")
47 end
48 end