aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/README.rdoc2
-rw-r--r--activeresource/lib/active_resource/base.rb8
-rw-r--r--activeresource/lib/active_resource/http_mock.rb8
-rw-r--r--activeresource/test/cases/http_mock_test.rb11
4 files changed, 22 insertions, 7 deletions
diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc
index 02398d969d..0aaad1d097 100644
--- a/activeresource/README.rdoc
+++ b/activeresource/README.rdoc
@@ -30,7 +30,7 @@ that inherits from ActiveResource::Base and providing a <tt>site</tt> class vari
end
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.
+life cycle methods that operate against a persistent store.
# Find a person with id = 1
ryan = Person.find(1)
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index a462f70684..7963aa462f 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -35,7 +35,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 lifecycle methods to manipulate resources. In the case where you already have
+ # you can now use Active Resource's life cycle 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
@@ -51,7 +51,7 @@ module ActiveResource
# end
#
#
- # == Lifecycle methods
+ # == Life cycle methods
#
# Active Resource exposes methods for creating, finding, updating, and deleting resources
# from REST web services.
@@ -70,12 +70,12 @@ module ActiveResource
#
# ryan.destroy # => true
#
- # As you can see, these are very similar to Active Record's lifecycle methods for database records.
+ # As you can see, these are very similar to Active Record's life cycle methods for database records.
# You can read more about each of these methods in their respective documentation.
#
# === Custom REST methods
#
- # Since simple CRUD/lifecycle methods can't accomplish every task, Active Resource also supports
+ # Since simple CRUD/life cycle methods can't accomplish every task, Active Resource also supports
# defining your own custom REST methods. To invoke them, Active Resource provides the <tt>get</tt>,
# <tt>post</tt>, <tt>put</tt> and <tt>\delete</tt> methods where you can specify a custom REST method
# name to invoke.
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index a98af88a37..8753a21835 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -126,7 +126,7 @@ module ActiveResource
# if response = self.class.responses.assoc(request)
# response[1]
# else
- # raise InvalidRequestError.new("No response recorded for #{request}")
+ # 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
@@ -136,7 +136,7 @@ module ActiveResource
if response = self.class.responses.assoc(request)
response[1]
else
- raise InvalidRequestError.new("No response recorded for \#{request}")
+ raise InvalidRequestError.new("Could not find a response recorded for \#{request.to_s} - Responses recorded are: \#{inspect_responses}")
end
end
EOE
@@ -146,6 +146,10 @@ 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
diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb
index 5e032d03f1..a387cd20b1 100644
--- a/activeresource/test/cases/http_mock_test.rb
+++ b/activeresource/test/cases/http_mock_test.rb
@@ -59,6 +59,17 @@ class HttpMockTest < ActiveSupport::TestCase
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
def request(method, path, headers = {}, body = nil)