From f99e5bba192938ed7e812f1ae82785ad796c636d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 21 Sep 2007 23:31:21 +0000 Subject: Increase test coverage (closes #8699, #8700) [josh] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7532 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/test/base_errors_test.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'activeresource/test/base_errors_test.rb') diff --git a/activeresource/test/base_errors_test.rb b/activeresource/test/base_errors_test.rb index 3527eb2353..f9aa58016d 100644 --- a/activeresource/test/base_errors_test.rb +++ b/activeresource/test/base_errors_test.rb @@ -9,22 +9,35 @@ class BaseErrorsTest < Test::Unit::TestCase @person = Person.new(:name => '', :age => '') assert_equal @person.save, false end - + def test_should_mark_as_invalid assert !@person.valid? end - + def test_should_parse_xml_errors assert_kind_of ActiveResource::Errors, @person.errors assert_equal 4, @person.errors.size end def test_should_parse_errors_to_individual_attributes + assert @person.errors.invalid?(:name) assert_equal "can't be blank", @person.errors.on(:age) assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] assert_equal "Person quota full for today.", @person.errors.on_base end + def test_should_iterate_over_errors + errors = [] + @person.errors.each { |attribute, message| errors << [attribute, message] } + assert_equal ["name", "can't be blank"], errors.first + end + + def test_should_iterate_over_full_errors + errors = [] + @person.errors.each_full { |message| errors << message } + assert_equal "Name can't be blank", errors.first + end + def test_should_format_full_errors full = @person.errors.full_messages assert full.include?("Age can't be blank") -- cgit v1.2.3