aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-09-08 00:07:30 +0000
committerRick Olson <technoweenie@gmail.com>2006-09-08 00:07:30 +0000
commit8d9e6609f8f67e55bba1f9bdbea62af22360dd3c (patch)
treed8315802e29467a28af7d6fb036b912cadbff587 /activeresource/test
parent7c4b6a55b61229ef5f2f053c9a88a738497c70cf (diff)
downloadrails-8d9e6609f8f67e55bba1f9bdbea62af22360dd3c.tar.gz
rails-8d9e6609f8f67e55bba1f9bdbea62af22360dd3c.tar.bz2
rails-8d9e6609f8f67e55bba1f9bdbea62af22360dd3c.zip
Basic validation support [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5068 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/base_errors_test.rb38
-rw-r--r--activeresource/test/connection_test.rb5
2 files changed, 42 insertions, 1 deletions
diff --git a/activeresource/test/base_errors_test.rb b/activeresource/test/base_errors_test.rb
new file mode 100644
index 0000000000..25a368535f
--- /dev/null
+++ b/activeresource/test/base_errors_test.rb
@@ -0,0 +1,38 @@
+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 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>", 400
+ end
+ @exception = nil
+ @person = Person.new(:name => '', :age => '')
+ @person.save
+ rescue ActiveResource::ResourceInvalid
+ @exception = $!
+ 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 \ No newline at end of file
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 4790c30bed..d72c1c612d 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -17,8 +17,11 @@ class ConnectionTest < Test::Unit::TestCase
# 404 is a missing resource.
assert_response_raises ActiveResource::ResourceNotFound, 404
+ # 400 is a validation error
+ assert_response_raises ActiveResource::ResourceInvalid, 400
+
# 4xx are client errors.
- [400, 499].each do |code|
+ [401, 499].each do |code|
assert_response_raises ActiveResource::ClientError, code
end