aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-28 19:46:17 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-01-28 19:46:17 +0000
commit285361d1589002fcdd1584c07e6eb295f13c9f37 (patch)
tree2d50a69b3b59b6fb3cb7577b990fe3b1aaf58f4f /activeresource
parentdfa19408651ecc82e2aeba95d93db871ba8a6e41 (diff)
parentd58398c2b5e98aad18dc72790230f338c10d145c (diff)
downloadrails-285361d1589002fcdd1584c07e6eb295f13c9f37.tar.gz
rails-285361d1589002fcdd1584c07e6eb295f13c9f37.tar.bz2
rails-285361d1589002fcdd1584c07e6eb295f13c9f37.zip
Merge remote branch 'mainstream/master'
Conflicts: railties/lib/rails/railtie.rb
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/railtie.rb8
-rw-r--r--activeresource/lib/active_resource/validations.rb6
-rw-r--r--activeresource/test/cases/base_errors_test.rb13
3 files changed, 23 insertions, 4 deletions
diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb
index 1b9307d472..7e35fdc0eb 100644
--- a/activeresource/lib/active_resource/railtie.rb
+++ b/activeresource/lib/active_resource/railtie.rb
@@ -3,9 +3,15 @@ require "rails"
module ActiveResource
class Railtie < Rails::Railtie
- plugin_name :active_resource
+ railtie_name :active_resource
require "active_resource/railties/subscriber"
subscriber ActiveResource::Railties::Subscriber.new
+
+ initializer "active_resource.set_configs" do |app|
+ app.config.active_resource.each do |k,v|
+ ActiveResource::Base.send "#{k}=", v
+ end
+ end
end
end \ No newline at end of file
diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb
index 7b2382bd8c..4774c6dd22 100644
--- a/activeresource/lib/active_resource/validations.rb
+++ b/activeresource/lib/active_resource/validations.rb
@@ -101,10 +101,10 @@ module ActiveResource
# Loads the set of remote errors into the object's Errors based on the
# content-type of the error-block received
def load_remote_errors(remote_errors, save_cache = false ) #:nodoc:
- case remote_errors.response['Content-Type']
- when /xml/
+ case self.class.format
+ when ActiveResource::Formats[:xml]
errors.from_xml(remote_errors.response.body, save_cache)
- when /json/
+ when ActiveResource::Formats[:json]
errors.from_json(remote_errors.response.body, save_cache)
end
end
diff --git a/activeresource/test/cases/base_errors_test.rb b/activeresource/test/cases/base_errors_test.rb
index 1eb7765132..b4fd75fba3 100644
--- a/activeresource/test/cases/base_errors_test.rb
+++ b/activeresource/test/cases/base_errors_test.rb
@@ -69,6 +69,19 @@ class BaseErrorsTest < Test::Unit::TestCase
end
end
+ def test_should_mark_as_invalid_when_content_type_is_unavailable_in_response_header
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.post "/people.xml", {}, %q(<?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, {}
+ mock.post "/people.json", {}, %q({"errors":["Age can't be blank","Name can't be blank","Name must start with a letter","Person quota full for today."]}), 422, {}
+ end
+
+ [ :json, :xml ].each do |format|
+ invalid_user_using_format(format) do
+ assert !@person.valid?
+ end
+ end
+ end
+
private
def invalid_user_using_format(mime_type_reference)
previous_format = Person.format