spec/resource_spec.rb in rlivsey-voorhees-0.1.4 vs spec/resource_spec.rb in rlivsey-voorhees-0.2.0
- old
+ new
@@ -34,17 +34,23 @@
end
describe "json_request" do
before :each do
+ @json_string= "{}"
+ @json_hash = {}
+
@request = mock(:request, :null_object => true)
@response = mock(:response, :null_object => true)
@objects = [mock(:object)]
Voorhees::Request.stub!(:new).and_return(@request)
@request.stub!(:perform).and_return(@response)
+
@response.stub!(:to_objects).and_return(@objects)
+ @response.stub!(:json).and_return(@json_hash)
+ @response.stub!(:body).and_return(@json_string)
end
def perform_request
User.json_request{}
end
@@ -55,11 +61,11 @@
perform_request
end
it "should call Request.new with the specified class if a class is passed" do
Voorhees::Request.should_receive(:new).with(Message).and_return(@request)
- User.json_request(Message) do |request|
+ User.json_request(:class => Message) do |request|
# ...
end
end
@@ -78,12 +84,29 @@
it "should implicitly call Request#perform" do
@request.should_receive(:perform).once
perform_request
end
- it "should return the result of Response#to_objects" do
+ it "should return the result of Response#to_objects if :returning is not set" do
perform_request.should == @objects
end
+
+ it "should return the JSON string if :returning is set to :raw" do
+ User.json_request(:returning => :raw){}.should == @json_string
+ end
+
+ it "should return the JSON hash if :returning is set to :json" do
+ User.json_request(:returning => :json){}.should == @json_hash
+ end
+
+ it "should return the objects string if :returning is set to :objects" do
+ User.json_request(:returning => :objects){}.should == @objects
+ end
+
+ it "should return the response if :returning is set to :response" do
+ User.json_request(:returning => :response){}.should == @response
+ end
+
end
describe "json_service" do
before :each do