-
Notifications
You must be signed in to change notification settings - Fork 43
/
created_responder_spec.rb
45 lines (38 loc) · 1.4 KB
/
created_responder_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.stub(: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.stub(: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