Permalink
Browse files

there's no need for Responder to have a not_found method

  • Loading branch information...
nakajima committed Feb 1, 2009
1 parent 82d7945 commit b9699a5bbeff5750db48a1c958d92ffac080ca62
@@ -10,7 +10,7 @@ module Hat
module Actions
def self.included(map)
map.action :destroy, '/:id', :verb => :delete do |request|
- record = model.find(request.params) || responder.not_found(request)
+ record = model.find(request.params) || request.not_found
record.destroy
responder.success(:destroy, request, record)
end
@@ -21,18 +21,18 @@ def self.included(map)
end
map.action :update, '/:id', :verb => :put do |request|
- record = model.update(request.params) || responder.not_found(request)
+ record = model.update(request.params) || request.not_found
result = record.save ? :success : :failure
responder.send(result, :update, request, record)
end
map.action :edit, '/:id/edit' do |request|
- record = model.find(request.params) || responder.not_found(request)
+ record = model.find(request.params) || request.not_found
responder.success(:edit, request, record)
end
map.action :show, '/:id' do |request|
- record = model.find(request.params) || responder.not_found(request)
+ record = model.find(request.params) || request.not_found
set_cache_headers(request, record) unless protected?(:show)
responder.success(:show, request, record)
end
@@ -49,23 +49,27 @@ def defaults
}
end
+ # Called when a request is handled successfully. For most GET
+ # requests, this is always the case. For update/create actions,
+ # it is when the record is created/updated successfully.
def success(name, request, data)
handle(:success, name, request, data)
end
+ # Called when a request is not able to handled. This could be
+ # because a record could not be created or saved.
def failure(name, request, data)
handle(:failure, name, request, data)
end
+ # Serializes the data passed in, first looking for a custom formatter,
+ # then falling back on trying to call to_[format] on the data. If neither
+ # are available, returns an error with the status code 406.
def serialize(request, data)
name = request.params[:format].to_sym
formatter = to_format(name)
formatter[data] || request.error(406)
end
-
- def not_found(request)
- request.not_found
- end
private
@@ -51,7 +51,7 @@ def handle(*args)
end
it "returns not_found" do
- mock.proxy(maker.responder).not_found(request)
+ mock.proxy(request).not_found
catch(:halt) { handle(request) }
end
end
@@ -25,7 +25,7 @@ def handle(*args)
end
it "returns not_found" do
- mock.proxy(maker.responder).not_found(request)
+ mock(request).not_found
handle(request)
end
end
@@ -78,7 +78,7 @@ def handle(*args)
end
it "returns not_found" do
- mock.proxy(maker.responder).not_found(request)
+ mock(request).not_found
handle(request)
end
@@ -21,7 +21,7 @@ def handle(*args)
end
it "returns not_found" do
- mock.proxy(maker.responder).not_found(request)
+ mock.proxy(request).not_found
catch(:halt) { handle(request) }
end
end
View
@@ -66,13 +66,6 @@ def new_responder(maker=@maker)
end
end
- describe "not_found" do
- it "calls not_found on the request" do
- mock(request = fake_request).not_found
- new_responder.not_found(request)
- end
- end
-
describe "failure" do
# context "when there's a format" do
# it "serializes the response" do

0 comments on commit b9699a5

Please sign in to comment.