Update to Rails 2.3.9 and itextomml 1.3.27
This commit is contained in:
parent
113e0af736
commit
ef30cc22df
200 changed files with 3065 additions and 1204 deletions
5
vendor/rails/activeresource/CHANGELOG
vendored
5
vendor/rails/activeresource/CHANGELOG
vendored
|
@ -1,8 +1,5 @@
|
|||
*2.3.9 (September 4, 2010)*
|
||||
*2.3.8 (May 24, 2010)*
|
||||
|
||||
* Version bump.
|
||||
|
||||
|
||||
*2.3.7 (May 24, 2010)*
|
||||
|
||||
* Version bump.
|
||||
|
|
2
vendor/rails/activeresource/Rakefile
vendored
2
vendor/rails/activeresource/Rakefile
vendored
|
@ -66,7 +66,7 @@ spec = Gem::Specification.new do |s|
|
|||
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
||||
end
|
||||
|
||||
s.add_dependency('activesupport', '= 2.3.8' + PKG_BUILD)
|
||||
s.add_dependency('activesupport', '= 2.3.9' + PKG_BUILD)
|
||||
|
||||
s.require_path = 'lib'
|
||||
s.autorequire = 'active_resource'
|
||||
|
|
|
@ -29,7 +29,8 @@ module ActiveResource
|
|||
#
|
||||
# In order for a mock to deliver its content, the incoming request must match by the <tt>http_method</tt>,
|
||||
# +path+ and <tt>request_headers</tt>. If no match is found an InvalidRequestError exception
|
||||
# will be raised letting you know you need to create a new mock for that request.
|
||||
# will be raised showing you what request it could not find a response for and also what requests and response
|
||||
# pairs have been recorded so you can create a new mock for that request.
|
||||
#
|
||||
# ==== Example
|
||||
# def setup
|
||||
|
@ -97,10 +98,79 @@ module ActiveResource
|
|||
@@responses ||= []
|
||||
end
|
||||
|
||||
# Accepts a block which declares a set of requests and responses for the HttpMock to respond to. See the main
|
||||
# ActiveResource::HttpMock description for a more detailed explanation.
|
||||
def respond_to(pairs = {}) #:yields: mock
|
||||
reset!
|
||||
# Accepts a block which declares a set of requests and responses for the HttpMock to respond to in
|
||||
# the following format:
|
||||
#
|
||||
# mock.http_method(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
||||
# ActiveResource::HttpMock.respond_to do |mock|
|
||||
# mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
|
||||
# mock.get "/people/1.xml", {}, @matz
|
||||
# mock.put "/people/1.xml", {}, nil, 204
|
||||
# mock.delete "/people/1.xml", {}, nil, 200
|
||||
# end
|
||||
#
|
||||
# Alternatively, accepts a hash of <tt>{Request => Response}</tt> pairs allowing you to generate
|
||||
# these the following format:
|
||||
#
|
||||
# ActiveResource::Request.new(method, path, body, request_headers)
|
||||
# ActiveResource::Response.new(body, status, response_headers)
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# Request.new(:#{method}, path, nil, request_headers)
|
||||
#
|
||||
# @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
||||
#
|
||||
# create_matz = ActiveResource::Request.new(:post, '/people.xml', @matz, {})
|
||||
# created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"})
|
||||
# get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
||||
# ok_response = ActiveResource::Response.new("", 200, {})
|
||||
#
|
||||
# pairs = {create_matz => created_response, get_matz => ok_response}
|
||||
#
|
||||
# ActiveResource::HttpMock.respond_to(pairs)
|
||||
#
|
||||
# Note, by default, every time you call +respond_to+, any previous request and response pairs stored
|
||||
# in HttpMock will be deleted giving you a clean slate to work on.
|
||||
#
|
||||
# If you want to override this behaviour, pass in +false+ as the last argument to +respond_to+
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# ActiveResource::HttpMock.respond_to do |mock|
|
||||
# mock.send(:get, "/people/1", {}, "XML1")
|
||||
# end
|
||||
# ActiveResource::HttpMock.responses.length #=> 1
|
||||
#
|
||||
# ActiveResource::HttpMock.respond_to(false) do |mock|
|
||||
# mock.send(:get, "/people/2", {}, "XML2")
|
||||
# end
|
||||
# ActiveResource::HttpMock.responses.length #=> 2
|
||||
#
|
||||
# This also works with passing in generated pairs of requests and responses, again, just pass in false
|
||||
# as the last argument:
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# ActiveResource::HttpMock.respond_to do |mock|
|
||||
# mock.send(:get, "/people/1", {}, "XML1")
|
||||
# end
|
||||
# ActiveResource::HttpMock.responses.length #=> 1
|
||||
#
|
||||
# get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
||||
# ok_response = ActiveResource::Response.new("", 200, {})
|
||||
#
|
||||
# pairs = {get_matz => ok_response}
|
||||
#
|
||||
# ActiveResource::HttpMock.respond_to(pairs, false)
|
||||
# ActiveResource::HttpMock.responses.length #=> 2
|
||||
def respond_to(*args) #:yields: mock
|
||||
pairs = args.first || {}
|
||||
reset! if args.last.class != FalseClass
|
||||
responses.concat pairs.to_a
|
||||
if block_given?
|
||||
yield Responder.new(responses)
|
||||
|
@ -123,13 +193,21 @@ module ActiveResource
|
|||
# def post(path, body, headers)
|
||||
# request = ActiveResource::Request.new(:post, path, body, headers)
|
||||
# self.class.requests << request
|
||||
# self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for #{request}"))
|
||||
# if response = self.class.responses.assoc(request)
|
||||
# response[1]
|
||||
# else
|
||||
# raise InvalidRequestError.new("Could not find a response recorded for #{request.to_s} - Responses recorded are: - #{inspect_responses}")
|
||||
# end
|
||||
# end
|
||||
module_eval <<-EOE, __FILE__, __LINE__ + 1
|
||||
def #{method}(path, #{'body, ' if has_body}headers)
|
||||
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers)
|
||||
self.class.requests << request
|
||||
self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for \#{request}"))
|
||||
if response = self.class.responses.assoc(request)
|
||||
response[1]
|
||||
else
|
||||
raise InvalidRequestError.new("Could not find a response recorded for \#{request.to_s} - Responses recorded are: \#{inspect_responses}")
|
||||
end
|
||||
end
|
||||
EOE
|
||||
end
|
||||
|
@ -138,22 +216,39 @@ module ActiveResource
|
|||
def initialize(site) #:nodoc:
|
||||
@site = site
|
||||
end
|
||||
|
||||
def inspect_responses #:nodoc:
|
||||
self.class.responses.map { |r| r[0].to_s }.inspect
|
||||
end
|
||||
end
|
||||
|
||||
class Request
|
||||
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
|
||||
|
|
|
@ -2,7 +2,7 @@ module ActiveResource
|
|||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 3
|
||||
TINY = 8
|
||||
TINY = 9
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
|
155
vendor/rails/activeresource/test/http_mock_test.rb
vendored
Normal file
155
vendor/rails/activeresource/test/http_mock_test.rb
vendored
Normal file
|
@ -0,0 +1,155 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
class HttpMockTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@http = ActiveResource::HttpMock.new("http://example.com")
|
||||
end
|
||||
|
||||
FORMAT_HEADER = { :get => 'Accept',
|
||||
:put => 'Content-Type',
|
||||
:post => 'Content-Type',
|
||||
:delete => 'Accept',
|
||||
:head => 'Accept'
|
||||
}
|
||||
|
||||
[:post, :put, :get, :delete, :head].each do |method|
|
||||
test "responds to simple #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "Response")
|
||||
end
|
||||
|
||||
assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body
|
||||
end
|
||||
|
||||
test "adds format header by default to #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {}, "Response")
|
||||
end
|
||||
|
||||
assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body
|
||||
end
|
||||
|
||||
test "respond only when headers match header by default to #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {"X-Header" => "X"}, "Response")
|
||||
end
|
||||
|
||||
assert_equal "Response", request(method, "/people/1", "X-Header" => "X").body
|
||||
assert_raise(ActiveResource::InvalidRequestError) { request(method, "/people/1") }
|
||||
end
|
||||
|
||||
test "does not overwrite format header to #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/json"}, "Response")
|
||||
end
|
||||
|
||||
assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body
|
||||
end
|
||||
|
||||
test "ignores format header when there is only one response to same url in a #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {}, "Response")
|
||||
end
|
||||
|
||||
assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body
|
||||
assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body
|
||||
end
|
||||
|
||||
test "responds correctly when format header is given to #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "XML")
|
||||
mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/json"}, "Json")
|
||||
end
|
||||
|
||||
assert_equal "XML", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body
|
||||
assert_equal "Json", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body
|
||||
end
|
||||
|
||||
test "raises InvalidRequestError if no response found for the #{method} request" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "XML")
|
||||
end
|
||||
|
||||
assert_raise(::ActiveResource::InvalidRequestError) do
|
||||
request(method, "/people/1", FORMAT_HEADER[method] => "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
test "allows you to send in pairs directly to the respond_to method" do
|
||||
matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
||||
|
||||
create_matz = ActiveResource::Request.new(:post, '/people.xml', matz, {})
|
||||
created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"})
|
||||
get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
||||
ok_response = ActiveResource::Response.new(matz, 200, {})
|
||||
|
||||
pairs = {create_matz => created_response, get_matz => ok_response}
|
||||
|
||||
ActiveResource::HttpMock.respond_to(pairs)
|
||||
assert_equal 2, ActiveResource::HttpMock.responses.length
|
||||
assert_equal "", ActiveResource::HttpMock.responses.assoc(create_matz)[1].body
|
||||
assert_equal matz, ActiveResource::HttpMock.responses.assoc(get_matz)[1].body
|
||||
end
|
||||
|
||||
test "resets all mocked responses on each call to respond_to with a block by default" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(:get, "/people/1", {}, "XML1")
|
||||
end
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(:get, "/people/2", {}, "XML2")
|
||||
end
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
end
|
||||
|
||||
test "resets all mocked responses on each call to respond_to by passing pairs by default" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(:get, "/people/1", {}, "XML1")
|
||||
end
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
|
||||
matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
||||
get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
||||
ok_response = ActiveResource::Response.new(matz, 200, {})
|
||||
ActiveResource::HttpMock.respond_to({get_matz => ok_response})
|
||||
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
end
|
||||
|
||||
test "allows you to add new responses to the existing responses by calling a block" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(:get, "/people/1", {}, "XML1")
|
||||
end
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
|
||||
ActiveResource::HttpMock.respond_to(false) do |mock|
|
||||
mock.send(:get, "/people/2", {}, "XML2")
|
||||
end
|
||||
assert_equal 2, ActiveResource::HttpMock.responses.length
|
||||
end
|
||||
|
||||
test "allows you to add new responses to the existing responses by passing pairs" do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.send(:get, "/people/1", {}, "XML1")
|
||||
end
|
||||
assert_equal 1, ActiveResource::HttpMock.responses.length
|
||||
|
||||
matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
||||
get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
||||
ok_response = ActiveResource::Response.new(matz, 200, {})
|
||||
ActiveResource::HttpMock.respond_to({get_matz => ok_response}, false)
|
||||
|
||||
assert_equal 2, ActiveResource::HttpMock.responses.length
|
||||
end
|
||||
|
||||
def request(method, path, headers = {}, body = nil)
|
||||
if [:put, :post].include? method
|
||||
@http.send(method, path, body, headers)
|
||||
else
|
||||
@http.send(method, path, headers)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue