X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=vendor%2Frails%2Factiveresource%2Ftest%2Fbase_errors_test.rb;fp=vendor%2Frails%2Factiveresource%2Ftest%2Fbase_errors_test.rb;h=7ae92c7d9885bded1ad353da9ca36cffa3b866b3;hb=d115f2e23823271635bad69229a42cd8ac68debe;hp=0000000000000000000000000000000000000000;hpb=37cb670bf3ddde90b214e591f100ed4446469484;p=depot.git diff --git a/vendor/rails/activeresource/test/base_errors_test.rb b/vendor/rails/activeresource/test/base_errors_test.rb new file mode 100644 index 0000000..7ae92c7 --- /dev/null +++ b/vendor/rails/activeresource/test/base_errors_test.rb @@ -0,0 +1,48 @@ +require 'abstract_unit' +require "fixtures/person" + +class BaseErrorsTest < Test::Unit::TestCase + def setup + ActiveResource::HttpMock.respond_to do |mock| + mock.post "/people.xml", {}, "Age can't be blankName can't be blankName must start with a letterPerson quota full for today.", 422 + end + @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 errors.include?(["name", "can't be blank"]) + end + + def test_should_iterate_over_full_errors + errors = [] + @person.errors.each_full { |message| errors << message } + assert errors.include?("Name can't be blank") + end + + def test_should_format_full_errors + full = @person.errors.full_messages + assert full.include?("Age can't be blank") + assert full.include?("Name can't be blank") + assert full.include?("Name must start with a letter") + assert full.include?("Person quota full for today.") + end +end