Sha256: 5457c85c76f76489806da1ad125e71e29071798e9ac2e8be48c3808aaa9b14ac

Contents?: true

Size: 1.3 KB

Versions: 56

Compression:

Stored size: 1.3 KB

Contents

require "#{File.dirname(__FILE__)}/abstract_unit"
require "fixtures/person"

class BaseErrorsTest < Test::Unit::TestCase
  def setup
    ActiveResource::HttpMock.respond_to do |mock|
      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
    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_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_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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
backlog-0.0.0 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.0.1 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.0.2 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.0.4 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.0.5 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.1.0 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.1.1 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.1.2 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.2.0 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.2.1 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.0 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.1 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.3 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.2 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.4 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.5 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.6 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.7 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.8 vendor/rails/activeresource/test/base_errors_test.rb
backlog-0.3.9 vendor/rails/activeresource/test/base_errors_test.rb