Skip to content

Commit

Permalink
because unit tests are cute too
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Aug 18, 2010
1 parent a06bc72 commit f6be001
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/spec/server/action_controller/created_responder_spec.rb
@@ -0,0 +1,45 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Restfulie::Server::ActionController::CreatedResponder do

context "using a CreatedResponder responder" do

module ToFormatReceiver
attr_accessor :received
def to_format
@received = true
end
end

it "should superize if its not a created result" do
responder = Object.new
responder.extend ToFormatReceiver
responder.extend Restfulie::Server::ActionController::CreatedResponder
responder.should_receive(:options).and_return({:status => 300})
responder.to_format
responder.received.should be_true
end

it "should head if the response is created" do
should_head_with(:created)
end
it "should head if the response is created" do
should_head_with(201)
end
def should_head_with(what)
uri = "custom_uri"
resource = Song.new
controller = Object.new
controller.should_receive(:url_for).with(resource).and_return(uri)

responder = Object.new
responder.extend Restfulie::Server::ActionController::CreatedResponder
responder.stub(:resource).and_return(resource)
responder.should_receive(:options).and_return({:status => what})
responder.should_receive(:controller).and_return(controller)
responder.should_receive(:head).with(:status => 201, :location => uri)
responder.to_format
end
end

end

0 comments on commit f6be001

Please sign in to comment.