forked from caelum/restfulie
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ab3507
commit 2f13e12
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
full-examples/rest_from_scratch/part_3/app/views/items/show.tokamak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
member(@item) do |member, item| | ||
partial "show", binding | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
lib/restfulie/server/action_controller/created_responder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Restfulie | ||
module Server | ||
module ActionController | ||
|
||
# Adds support to answering as a 201 when the resource has been just created | ||
module CreatedResponder | ||
|
||
def to_format | ||
if [201, :created].include? options[:status] | ||
head :status => 201, :location => controller.url_for(resource) | ||
else | ||
super | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
spec/units/server/action_controller/created_responder_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
class ResponderWithCreated < ::ActionController::Responder | ||
include Restfulie::Server::ActionController::CreatedResponder | ||
end | ||
|
||
class CreationController < ApplicationController | ||
self.responder = ResponderWithCreated | ||
respond_to :atom | ||
|
||
def create | ||
@resource = Object.new | ||
respond_with @resource, :status => :created | ||
end | ||
|
||
end | ||
|
||
ActionController::Routing::Routes.draw do |map| | ||
map.connect ':controller/:action/:id' | ||
end | ||
|
||
describe CreationController, :type => :controller do | ||
|
||
before(:each) do | ||
request.accept = "application/atom+xml" | ||
end | ||
|
||
context "creating a resource" do | ||
|
||
it "should return 201 with location" do | ||
uri = "http://newlocation.com/uri" | ||
controller.should_receive(:url_for).and_return uri | ||
post :create | ||
controller.response.code.should == "201" | ||
controller.response.headers["Location"].should == uri | ||
end | ||
|
||
end | ||
end |