aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-13 15:18:45 -0700
committerCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-13 15:18:45 -0700
commit906aebceedb95d8caa6db6314bc90f605bdfaf2b (patch)
tree5abc86bb6709b20df7cb5f4d1750b27c641dca4b /activeresource
parent2036d3ba75da1a0f3061bf5a33c89e2b2eaff420 (diff)
parentc877857d59554d78dbf45f5f9fcaafb8badec4e2 (diff)
downloadrails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.tar.gz
rails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.tar.bz2
rails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.zip
Bring abstract_controller up to date with rails/master
Resolved all the conflicts since 2.3.0 -> HEAD. Following is a list of commits that could not be applied cleanly or are obviated with the abstract_controller refactor. They all need to be revisited to ensure that fixes made in 2.3 do not reappear in 3.0: 2259ecf368e6a6715966f69216e3ee86bf1a82a7 AR not available * This will be reimplemented with ActionORM or equivalent 06182ea02e92afad579998aa80144588e8865ac3 implicitly rendering a js response should not use the default layout [#1844 state:resolved] * This will be handled generically 893e9eb99504705419ad6edac14d00e71cef5f12 Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved] * We will need to reimplement rails-dev-boost on top of the refactor; the changes here are very implementation specific and cannot be cleanly applied. The following commits are implicated: 199e750d46c04970b5e7684998d09405648ecbd4 3942cb406e1d5db0ac00e03153809cc8dc4cc4db f8ea9f85d4f1e3e6f3b5d895bef6b013aa4b0690 e3b166aab37ddc2fbab030b146eb61713b91bf55 ae9f258e03c9fd5088da12c1c6cd216cc89a01f7 44423126c6f6133a1d9cf1d0832b527e8711d40f 0cb020b4d6d838025859bd60fb8151c8e21b8e84 workaround for picking layouts based on wrong view_paths [#1974 state:resolved] * The specifics of this commit no longer apply. Since it is a two-line commit, we will reimplement this change. 8c5cc66a831aadb159f3daaffa4208064c30af0e make action_controller/layouts pick templates from the current instance's view_paths instead of the class view_paths [#1974 state:resolved] * This does not apply at all. It should be trivial to apply the feature to the reimplemented ActionController::Base. 87e8b162463f13bd50d27398f020769460a770e3 fix HTML fallback for explicit templates [#2052 state:resolved] * There were a number of patches related to this that simply compounded each other. Basically none of them apply cleanly, and the underlying issue needs to be revisited. After discussing the underlying problem with Koz, we will defer these fixes for further discussion.
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/CHANGELOG5
-rw-r--r--activeresource/README14
-rw-r--r--activeresource/Rakefile4
-rw-r--r--activeresource/lib/active_resource/base.rb32
-rw-r--r--activeresource/lib/active_resource/connection.rb22
-rw-r--r--activeresource/lib/active_resource/http_mock.rb66
-rw-r--r--activeresource/lib/active_resource/validations.rb19
-rw-r--r--activeresource/lib/active_resource/version.rb2
-rw-r--r--activeresource/test/abstract_unit.rb13
-rw-r--r--activeresource/test/authorization_test.rb8
-rw-r--r--activeresource/test/base_test.rb22
-rw-r--r--activeresource/test/connection_test.rb28
-rw-r--r--activeresource/test/setter_trap.rb5
13 files changed, 112 insertions, 128 deletions
diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG
index 428c6d91e9..6572934893 100644
--- a/activeresource/CHANGELOG
+++ b/activeresource/CHANGELOG
@@ -1,3 +1,8 @@
+*2.3.2 [Final] (March 15, 2009)*
+
+* Nothing new, just included in 2.3.2
+
+
*2.2.1 [RC2] (November 14th, 2008)*
* Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 [Paolo Angelini]
diff --git a/activeresource/README b/activeresource/README
index 924017a659..127ac5b4a9 100644
--- a/activeresource/README
+++ b/activeresource/README
@@ -1,7 +1,7 @@
= Active Resource
Active Resource (ARes) connects business objects and Representational State Transfer (REST)
-web services. It implements object-relational mapping for REST webservices to provide transparent
+web services. It implements object-relational mapping for REST web services to provide transparent
proxying capabilities between a client (ActiveResource) and a RESTful service (which is provided by Simply RESTful routing
in ActionController::Resources).
@@ -22,14 +22,14 @@ received and serialized into a usable Ruby object.
=== Configuration and Usage
-Putting ActiveResource to use is very similar to ActiveRecord. It's as simple as creating a model class
+Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class
that inherits from ActiveResource::Base and providing a <tt>site</tt> class variable to it:
class Person < ActiveResource::Base
self.site = "http://api.people.com:3000/"
end
-Now the Person class is REST enabled and can invoke REST services very similarly to how ActiveRecord invokes
+Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
lifecycle methods that operate against a persistent store.
# Find a person with id = 1
@@ -42,7 +42,7 @@ records. But rather than dealing directly with a database record, you're dealin
==== Protocol
Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing
-built into ActionController but will also work with any other REST service that properly implements the protocol.
+built into Action Controller but will also work with any other REST service that properly implements the protocol.
REST uses HTTP, but unlike "typical" web applications, it makes use of all the verbs available in the HTTP specification:
* GET requests are used for finding and retrieving resources.
@@ -55,8 +55,8 @@ for more general information on REST web services, see the article here[http://e
==== Find
-GET Http requests expect the XML form of whatever resource/resources is/are being requested. So,
-for a request for a single element - the XML of that item is expected in response:
+Find requests use the GET method and expect the XML form of whatever resource/resources is/are being requested. So,
+for a request for a single element, the XML of that item is expected in response:
# Expects a response of
#
@@ -101,7 +101,7 @@ Collections can also be requested in a similar fashion
==== Create
-Creating a new resource submits the xml form of the resource as the body of the request and expects
+Creating a new resource submits the XML form of the resource as the body of the request and expects
a 'Location' header in the response with the RESTful URL location of the newly created resource. The
id of the newly created resource is parsed out of the Location response header and automatically set
as the id of the ARes object.
diff --git a/activeresource/Rakefile b/activeresource/Rakefile
index ef99caea67..bf7bbb0201 100644
--- a/activeresource/Rakefile
+++ b/activeresource/Rakefile
@@ -28,6 +28,8 @@ task :default => [ :test ]
# Run the unit tests
Rake::TestTask.new { |t|
+ activesupport_path = "#{File.dirname(__FILE__)}/../activesupport/lib"
+ t.libs << activesupport_path if File.directory?(activesupport_path)
t.libs << "test"
t.pattern = 'test/**/*_test.rb'
t.verbose = true
@@ -65,7 +67,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.0' + PKG_BUILD)
+ s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'active_resource'
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 94418fb559..6cb5beb789 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -19,7 +19,7 @@ module ActiveResource
# end
#
# Now the Person class is mapped to RESTful resources located at <tt>http://api.people.com:3000/people/</tt>, and
- # you can now use Active Resource's lifecycles methods to manipulate resources. In the case where you already have
+ # you can now use Active Resource's lifecycle methods to manipulate resources. In the case where you already have
# an existing model with the same name as the desired RESTful resource you can set the +element_name+ value.
#
# class PersonResource < ActiveResource::Base
@@ -112,6 +112,7 @@ module ActiveResource
#
# Note: Some values cannot be provided in the URL passed to site. e.g. email addresses
# as usernames. In those situations you should use the separate user and password option.
+ #
# == Errors & Validation
#
# Error handling and validation is handled in much the same manner as you're used to seeing in
@@ -156,7 +157,7 @@ module ActiveResource
#
# === Validation errors
#
- # Active Resource supports validations on resources and will return errors if any these validations fail
+ # Active Resource supports validations on resources and will return errors if any of these validations fail
# (e.g., "First name can not be blank" and so on). These types of errors are denoted in the response by
# a response code of <tt>422</tt> and an XML representation of the validation errors. The save operation will
# then fail (with a <tt>false</tt> return value) and the validation errors can be accessed on the resource in question.
@@ -413,7 +414,7 @@ module ActiveResource
# will split from the +prefix_options+.
#
# ==== Options
- # * +prefix_options+ - A hash to add a prefix to the request for nested URL's (e.g., <tt>:account_id => 19</tt>
+ # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
# would yield a URL like <tt>/accounts/19/purchases.xml</tt>).
# * +query_options+ - A hash to add items to the query string for the request.
#
@@ -462,7 +463,7 @@ module ActiveResource
# that_guy.valid? # => false
# that_guy.new? # => true
def create(attributes = {})
- returning(self.new(attributes)) { |res| res.save }
+ self.new(attributes).tap { |resource| resource.save }
end
# Core method for finding resources. Used similarly to Active Record's +find+ method.
@@ -600,7 +601,7 @@ module ActiveResource
end
def instantiate_record(record, prefix_options = {})
- returning new(record) do |resource|
+ new(record).tap do |resource|
resource.prefix_options = prefix_options
end
end
@@ -691,7 +692,7 @@ module ActiveResource
end
- # A method to determine if the resource a \new object (i.e., it has not been POSTed to the remote service yet).
+ # Returns +true+ if this object hasn't yet been saved, otherwise, returns +false+.
#
# ==== Examples
# not_new = Computer.create(:brand => 'Apple', :make => 'MacBook', :vendor => 'MacMall')
@@ -747,7 +748,7 @@ module ActiveResource
#
def ==(other)
other.equal?(self) || (other.instance_of?(self.class) && other.id == id && other.prefix_options == prefix_options)
- end
+ end
# Tests for equality (delegates to ==).
def eql?(other)
@@ -760,7 +761,7 @@ module ActiveResource
id.hash
end
- # Duplicate the current resource without saving it.
+ # Duplicates the current resource without saving it.
#
# ==== Examples
# my_invoice = Invoice.create(:customer => 'That Company')
@@ -773,14 +774,14 @@ module ActiveResource
# my_invoice.customer # => That Company
# next_invoice.customer # => That Company
def dup
- returning self.class.new do |resource|
+ self.class.new.tap do |resource|
resource.attributes = @attributes
resource.prefix_options = @prefix_options
end
end
- # A method to \save (+POST+) or \update (+PUT+) a resource. It delegates to +create+ if a \new object,
- # +update+ if it is existing. If the response to the \save includes a body, it will be assumed that this body
+ # Saves (+POST+) or \updates (+PUT+) a resource. Delegates to +create+ if the object is \new,
+ # +update+ if it exists. If the response to the \save includes a body, it will be assumed that this body
# is XML for the final object as it looked after the \save (which would include attributes like +created_at+
# that weren't part of the original submit).
#
@@ -832,7 +833,7 @@ module ActiveResource
!new? && self.class.exists?(to_param, :params => prefix_options)
end
- # A method to convert the the resource to an XML string.
+ # Converts the resource to an XML string representation.
#
# ==== Options
# The +options+ parameter is handed off to the +to_xml+ method on each
@@ -861,8 +862,7 @@ module ActiveResource
attributes.to_xml({:root => self.class.element_name}.merge(options))
end
- # Returns a JSON string representing the model. Some configuration is
- # available through +options+.
+ # Converts the resource to a JSON string representation.
#
# ==== Options
# The +options+ are passed to the +to_json+ method on each
@@ -985,14 +985,14 @@ module ActiveResource
# Update the resource on the remote service.
def update
- returning connection.put(element_path(prefix_options), encode, self.class.headers) do |response|
+ connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response|
load_attributes_from_response(response)
end
end
# Create (i.e., \save to the remote service) the \new resource.
def create
- returning connection.post(collection_path, encode, self.class.headers) do |response|
+ connection.post(collection_path, encode, self.class.headers).tap do |response|
self.id = id_from_response(response)
load_attributes_from_response(response)
end
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 85103b53c5..80d5c95b68 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -95,46 +95,46 @@ module ActiveResource
@password = URI.decode(@site.password) if @site.password
end
- # Set user for remote service.
+ # Sets the user for remote service.
def user=(user)
@user = user
end
- # Set password for remote service.
+ # Sets the password for remote service.
def password=(password)
@password = password
end
- # Set the number of seconds after which HTTP requests to the remote service should time out.
+ # Sets the number of seconds after which HTTP requests to the remote service should time out.
def timeout=(timeout)
@timeout = timeout
end
- # Execute a GET request.
+ # Executes a GET request.
# Used to get (find) resources.
def get(path, headers = {})
format.decode(request(:get, path, build_request_headers(headers, :get)).body)
end
- # Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
+ # Executes a DELETE request (see HTTP protocol documentation if unfamiliar).
# Used to delete resources.
def delete(path, headers = {})
request(:delete, path, build_request_headers(headers, :delete))
end
- # Execute a PUT request (see HTTP protocol documentation if unfamiliar).
+ # Executes a PUT request (see HTTP protocol documentation if unfamiliar).
# Used to update resources.
def put(path, body = '', headers = {})
request(:put, path, body.to_s, build_request_headers(headers, :put))
end
- # Execute a POST request.
+ # Executes a POST request.
# Used to create new resources.
def post(path, body = '', headers = {})
request(:post, path, body.to_s, build_request_headers(headers, :post))
end
- # Execute a HEAD request.
+ # Executes a HEAD request.
# Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
def head(path, headers = {})
request(:head, path, build_request_headers(headers))
@@ -142,7 +142,7 @@ module ActiveResource
private
- # Makes request to remote service.
+ # Makes a request to the remote service.
def request(method, path, *arguments)
logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
result = nil
@@ -153,7 +153,7 @@ module ActiveResource
raise TimeoutError.new(e.message)
end
- # Handles response and error codes from remote service.
+ # Handles response and error codes from the remote service.
def handle_response(response)
case response.code.to_i
when 301,302
@@ -183,7 +183,7 @@ module ActiveResource
end
end
- # Creates new Net::HTTP instance for communication with
+ # Creates new Net::HTTP instance for communication with the
# remote service and resources.
def http
http = Net::HTTP.new(@site.host, @site.port)
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 0b4549f759..7d7e378436 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -59,7 +59,7 @@ module ActiveResource
# end
module_eval <<-EOE, __FILE__, __LINE__
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
- @responses[Request.new(:#{method}, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
+ @responses << [Request.new(:#{method}, path, nil, request_headers), Response.new(body || "", status, response_headers)]
end
EOE
end
@@ -91,21 +91,17 @@ module ActiveResource
@@requests ||= []
end
- # Returns a hash of <tt>request => response</tt> pairs for all all responses this mock has delivered, where +request+
- # is an instance of ActiveResource::Request and the response is, naturally, an instance of
- # ActiveResource::Response.
+ # Returns the list of requests and their mocked responses. Look up a
+ # response for a request using responses.assoc(request).
def responses
- @@responses ||= {}
+ @@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!
- pairs.each do |(path, response)|
- responses[path] = response
- end
-
+ responses.concat pairs.to_a
if block_given?
yield Responder.new(responses)
else
@@ -120,29 +116,23 @@ module ActiveResource
end
end
- for method in [ :post, :put ]
- # def post(path, body, headers)
- # request = ActiveResource::Request.new(:post, path, body, headers)
- # self.class.requests << request
- # self.class.responses[request] || raise(InvalidRequestError.new("No response recorded for #{request}"))
- # end
- module_eval <<-EOE, __FILE__, __LINE__
- def #{method}(path, body, headers)
- request = ActiveResource::Request.new(:#{method}, path, body, headers)
- self.class.requests << request
- self.class.responses[request] || raise(InvalidRequestError.new("No response recorded for \#{request}"))
- end
- EOE
- end
-
- for method in [ :get, :delete, :head ]
- module_eval <<-EOE, __FILE__, __LINE__
- def #{method}(path, headers)
- request = ActiveResource::Request.new(:#{method}, path, nil, headers)
- self.class.requests << request
- self.class.responses[request] || raise(InvalidRequestError.new("No response recorded for \#{request}"))
- end
- EOE
+ # body? methods
+ { true => %w(post put),
+ false => %w(get delete head) }.each do |has_body, methods|
+ methods.each do |method|
+ # 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}"))
+ # end
+ module_eval <<-EOE, __FILE__, __LINE__
+ 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}"))
+ end
+ EOE
+ end
end
def initialize(site) #:nodoc:
@@ -157,21 +147,13 @@ module ActiveResource
@method, @path, @body, @headers = method, path, body, headers.merge(ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method] => 'application/xml')
end
- def ==(other_request)
- other_request.hash == hash
- end
-
- def eql?(other_request)
- self == other_request
+ def ==(req)
+ path == req.path && method == req.method && headers == req.headers
end
def to_s
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
end
-
- def hash
- "#{path}#{method}#{headers}".hash
- end
end
class Response
diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb
index 4bc906d291..8d21f8adbb 100644
--- a/activeresource/lib/active_resource/validations.rb
+++ b/activeresource/lib/active_resource/validations.rb
@@ -3,7 +3,7 @@ module ActiveResource
end
# Active Resource validation is reported to and from this object, which is used by Base#save
- # to determine whether the object in a valid state to be saved. See usage example in Validations.
+ # to determine whether the object is in a valid state to be saved. See usage example in Validations.
class Errors
include Enumerable
attr_reader :errors
@@ -14,7 +14,10 @@ module ActiveResource
@base, @errors = base, {}
end
- # Add an error to the base Active Resource object rather than an attribute.
+ # Adds an error to the base object instead of any particular attribute. This is used
+ # to report errors that don't tie to any specific attribute, but rather to the object
+ # as a whole. These error messages don't get prepended with any field name when iterating
+ # with +each_full+, so they should be complete sentences.
#
# ==== Examples
# my_folder = Folder.find(1)
@@ -68,9 +71,9 @@ module ActiveResource
!@errors[attribute.to_s].nil?
end
- # A method to return the errors associated with +attribute+, which returns nil, if no errors are
- # associated with the specified +attribute+, the error message if one error is associated with the specified +attribute+,
- # or an array of error messages if more than one error is associated with the specified +attribute+.
+ # Returns +nil+ if no errors are associated with the specified +attribute+.
+ # Returns the error message if one error is associated with the specified +attribute+.
+ # Returns an array of error messages if more than one error is associated with the specified +attribute+.
#
# ==== Examples
# my_person = Person.new(params[:person])
@@ -92,9 +95,7 @@ module ActiveResource
alias :[] :on
- # A method to return errors assigned to +base+ object through add_to_base, which returns nil, if no errors are
- # associated with the specified +attribute+, the error message if one error is associated with the specified +attribute+,
- # or an array of error messages if more than one error is associated with the specified +attribute+.
+ # Returns errors assigned to the base object through +add_to_base+ according to the normal rules of <tt>on(attribute)</tt>.
#
# ==== Examples
# my_account = Account.find(1)
@@ -203,7 +204,7 @@ module ActiveResource
def from_xml(xml)
clear
humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) }
- messages = Hash.from_xml(xml)['errors']['error'] rescue []
+ messages = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue []
messages.each do |message|
attr_message = humanized_attributes.keys.detect do |attr_name|
if message[0, attr_name.size + 1] == "#{attr_name} "
diff --git a/activeresource/lib/active_resource/version.rb b/activeresource/lib/active_resource/version.rb
index c420ac813e..3df2555d53 100644
--- a/activeresource/lib/active_resource/version.rb
+++ b/activeresource/lib/active_resource/version.rb
@@ -2,7 +2,7 @@ module ActiveResource
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
- TINY = 0
+ TINY = 2
STRING = [MAJOR, MINOR, TINY].join('.')
end
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb
index e612412033..0f11ea482a 100644
--- a/activeresource/test/abstract_unit.rb
+++ b/activeresource/test/abstract_unit.rb
@@ -1,6 +1,11 @@
+require 'rubygems'
require 'test/unit'
+gem 'mocha', '>= 0.9.5'
+require 'mocha'
+
$:.unshift "#{File.dirname(__FILE__)}/../lib"
+$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
require 'active_resource'
require 'active_resource/http_mock'
@@ -10,17 +15,9 @@ require 'setter_trap'
ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
def uses_gem(gem_name, test_name, version = '> 0')
- require 'rubygems'
gem gem_name.to_s, version
require gem_name.to_s
yield
rescue LoadError
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
end
-
-# Wrap tests that use Mocha and skip if unavailable.
-unless defined? uses_mocha
- def uses_mocha(test_name, &block)
- uses_gem('mocha', test_name, '>= 0.5.5', &block)
- end
-end
diff --git a/activeresource/test/authorization_test.rb b/activeresource/test/authorization_test.rb
index ead7f5c12f..ca25f437e3 100644
--- a/activeresource/test/authorization_test.rb
+++ b/activeresource/test/authorization_test.rb
@@ -107,10 +107,10 @@ class AuthorizationTest < Test::Unit::TestCase
end
def test_raises_invalid_request_on_unauthorized_requests
- assert_raises(ActiveResource::InvalidRequestError) { @conn.post("/people/2.xml") }
- assert_raises(ActiveResource::InvalidRequestError) { @conn.post("/people/2/addresses.xml") }
- assert_raises(ActiveResource::InvalidRequestError) { @conn.put("/people/2.xml") }
- assert_raises(ActiveResource::InvalidRequestError) { @conn.delete("/people/2.xml") }
+ assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2.xml") }
+ assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2/addresses.xml") }
+ assert_raise(ActiveResource::InvalidRequestError) { @conn.put("/people/2.xml") }
+ assert_raise(ActiveResource::InvalidRequestError) { @conn.delete("/people/2.xml") }
end
protected
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
index e22388f4a7..6ed6f1a406 100644
--- a/activeresource/test/base_test.rb
+++ b/activeresource/test/base_test.rb
@@ -47,7 +47,7 @@ class BaseTest < Test::Unit::TestCase
{:name => 'Milena',
:children => []}]}]}.to_xml(:root => 'customer')
# - resource with yaml array of strings; for ActiveRecords using serialize :bar, Array
- @marty = <<-eof
+ @marty = <<-eof.strip
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<person>
<id type=\"integer\">5</id>
@@ -564,14 +564,14 @@ class BaseTest < Test::Unit::TestCase
def test_custom_header
Person.headers['key'] = 'value'
- assert_raises(ActiveResource::ResourceNotFound) { Person.find(4) }
+ assert_raise(ActiveResource::ResourceNotFound) { Person.find(4) }
ensure
Person.headers.delete('key')
end
def test_find_by_id_not_found
- assert_raises(ActiveResource::ResourceNotFound) { Person.find(99) }
- assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
+ assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) }
+ assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
end
def test_find_all_by_from
@@ -689,7 +689,7 @@ class BaseTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to do |mock|
mock.post "/people.xml", {}, nil, 409
end
- assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
+ assert_raise(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
end
def test_create_without_location
@@ -726,7 +726,7 @@ class BaseTest < Test::Unit::TestCase
matz.non_ar_arr = ["not", "ARes"]
matz_c = matz.clone
assert matz_c.new?
- assert_raises(NoMethodError) {matz_c.address}
+ assert_raise(NoMethodError) {matz_c.address}
assert_equal matz.non_ar_hash, matz_c.non_ar_hash
assert_equal matz.non_ar_arr, matz_c.non_ar_arr
@@ -764,7 +764,7 @@ class BaseTest < Test::Unit::TestCase
mock.get "/people/2.xml", {}, @david
mock.put "/people/2.xml", @default_request_headers, nil, 409
end
- assert_raises(ActiveResource::ResourceConflict) { Person.find(2).save }
+ assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save }
end
def test_destroy
@@ -772,7 +772,7 @@ class BaseTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, nil, 404
end
- assert_raises(ActiveResource::ResourceNotFound) { Person.find(1).destroy }
+ assert_raise(ActiveResource::ResourceNotFound) { Person.find(1).destroy }
end
def test_destroy_with_custom_prefix
@@ -780,7 +780,7 @@ class BaseTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1/addresses/1.xml", {}, nil, 404
end
- assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
+ assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
end
def test_delete
@@ -788,7 +788,7 @@ class BaseTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, nil, 404
end
- assert_raises(ActiveResource::ResourceNotFound) { Person.find(1) }
+ assert_raise(ActiveResource::ResourceNotFound) { Person.find(1) }
end
def test_delete_with_custom_prefix
@@ -796,7 +796,7 @@ class BaseTest < Test::Unit::TestCase
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1/addresses/1.xml", {}, nil, 404
end
- assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
+ assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
end
def test_exists
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 84bcf69219..831fbc4003 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -168,21 +168,19 @@ class ConnectionTest < Test::Unit::TestCase
assert_equal 200, response.code
end
- uses_mocha('test_timeout, test_accept_http_header') do
- def test_timeout
- @http = mock('new Net::HTTP')
- @conn.expects(:http).returns(@http)
- @http.expects(:get).raises(Timeout::Error, 'execution expired')
- assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') }
- end
-
- def test_accept_http_header
- @http = mock('new Net::HTTP')
- @conn.expects(:http).returns(@http)
- path = '/people/1.xml'
- @http.expects(:get).with(path, {'Accept' => 'application/xhtml+xml'}).returns(ActiveResource::Response.new(@matz, 200, {'Content-Type' => 'text/xhtml'}))
- assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) }
- end
+ def test_timeout
+ @http = mock('new Net::HTTP')
+ @conn.expects(:http).returns(@http)
+ @http.expects(:get).raises(Timeout::Error, 'execution expired')
+ assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') }
+ end
+
+ def test_accept_http_header
+ @http = mock('new Net::HTTP')
+ @conn.expects(:http).returns(@http)
+ path = '/people/1.xml'
+ @http.expects(:get).with(path, {'Accept' => 'application/xhtml+xml'}).returns(ActiveResource::Response.new(@matz, 200, {'Content-Type' => 'text/xhtml'}))
+ assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) }
end
protected
diff --git a/activeresource/test/setter_trap.rb b/activeresource/test/setter_trap.rb
index 9a899b0fa0..7cfd9ca111 100644
--- a/activeresource/test/setter_trap.rb
+++ b/activeresource/test/setter_trap.rb
@@ -1,9 +1,8 @@
class SetterTrap < ActiveSupport::BasicObject
class << self
def rollback_sets(obj)
- returning yield(setter_trap = new(obj)) do
- setter_trap.rollback_sets
- end
+ trapped = new(obj)
+ yield(trapped).tap { trapped.rollback_sets }
end
end