aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/base.rb1
-rw-r--r--activeresource/lib/active_resource/http_mock.rb16
-rw-r--r--activeresource/lib/active_resource/log_subscriber.rb15
-rw-r--r--activeresource/lib/active_resource/railtie.rb3
-rw-r--r--activeresource/lib/active_resource/railties/log_subscriber.rb15
-rw-r--r--activeresource/lib/active_resource/validations.rb2
6 files changed, 31 insertions, 21 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 521e2b6f5d..6c494a8bcc 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -17,6 +17,7 @@ require 'active_resource/exceptions'
require 'active_resource/connection'
require 'active_resource/formats'
require 'active_resource/schema'
+require 'active_resource/log_subscriber'
module ActiveResource
# ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application.
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 1ed3804017..f192c53b4f 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -148,16 +148,28 @@ module ActiveResource
attr_accessor :path, :method, :body, :headers
def initialize(method, path, body = nil, headers = {})
- @method, @path, @body, @headers = method, path, body, headers.merge(ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method] => 'application/xml')
+ @method, @path, @body, @headers = method, path, body, headers
end
def ==(req)
- path == req.path && method == req.method && headers == req.headers
+ path == req.path && method == req.method && headers_match?(req)
end
def to_s
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
end
+
+ private
+
+ def headers_match?(req)
+ # Ignore format header on equality if it's not defined
+ format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]
+ if headers[format_header].present? || req.headers[format_header].blank?
+ headers == req.headers
+ else
+ headers.dup.merge(format_header => req.headers[format_header]) == req.headers
+ end
+ end
end
class Response
diff --git a/activeresource/lib/active_resource/log_subscriber.rb b/activeresource/lib/active_resource/log_subscriber.rb
new file mode 100644
index 0000000000..9e52baf36d
--- /dev/null
+++ b/activeresource/lib/active_resource/log_subscriber.rb
@@ -0,0 +1,15 @@
+module ActiveResource
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ def request(event)
+ result = event.payload[:result]
+ info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
+ info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration]
+ end
+
+ def logger
+ ActiveResource::Base.logger
+ end
+ end
+end
+
+ActiveResource::LogSubscriber.attach_to :active_resource \ No newline at end of file
diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb
index aa878c7212..60f6f88311 100644
--- a/activeresource/lib/active_resource/railtie.rb
+++ b/activeresource/lib/active_resource/railtie.rb
@@ -5,9 +5,6 @@ module ActiveResource
class Railtie < Rails::Railtie
config.active_resource = ActiveSupport::OrderedOptions.new
- require "active_resource/railties/log_subscriber"
- log_subscriber :active_resource, ActiveResource::Railties::LogSubscriber.new
-
initializer "active_resource.set_configs" do |app|
app.config.active_resource.each do |k,v|
ActiveResource::Base.send "#{k}=", v
diff --git a/activeresource/lib/active_resource/railties/log_subscriber.rb b/activeresource/lib/active_resource/railties/log_subscriber.rb
deleted file mode 100644
index 86806a93d0..0000000000
--- a/activeresource/lib/active_resource/railties/log_subscriber.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module ActiveResource
- module Railties
- class LogSubscriber < Rails::LogSubscriber
- def request(event)
- result = event.payload[:result]
- info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
- info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration]
- end
-
- def logger
- ActiveResource::Base.logger
- 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 a19e0d0ac9..026d81e44a 100644
--- a/activeresource/lib/active_resource/validations.rb
+++ b/activeresource/lib/active_resource/validations.rb
@@ -27,7 +27,7 @@ module ActiveResource
# Grabs errors from a json response.
def from_json(json, save_cache = false)
- array = ActiveSupport::JSON.decode(json)['errors'] rescue []
+ array = Array.wrap(ActiveSupport::JSON.decode(json)['errors']) rescue []
from_array array, save_cache
end