spec/api-client/base/delete_spec.rb in api-client-1.4.1 vs spec/api-client/base/delete_spec.rb in api-client-1.5.0

- old
+ new

@@ -73,16 +73,62 @@ lambda { ApiClient::Base.delete('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ServiceUnavailable) end end context "when response code is 2xx" do - before :each do - FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}') - User.stub(:new).and_return(user) + context "without any specifications" do + before :each do + FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}') + User.stub(:new).and_return(user) + end + + it "should return a object initialized with the response" do + User.delete('http://api.example.com/user/5').should == user + end end - it "should return a object intialized with the response" do - User.delete('http://api.example.com/user/5').should == user + context "with a specified port" do + before :each do + FakeWeb.register_uri(:delete, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}') + User.stub(:new).and_return(user) + end + + it "should return a object initialized with the response" do + User.delete('http://api.example.com:3001/user/5', {}).should == user + end + end + + context "with a specified remote object name" do + before :each do + FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "201", :body => '{"user": {"a": "a", "b": "b"} }') + Admin.stub(:new).and_return(user) + end + + it "should return a object initialized with the response" do + Admin.delete('http://api.example.com/user/5', {}).should == user + end + end + + context "with a collection" do + before :each do + FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }') + User.stub(:new).and_return(user) + end + + it "should return a collection of objects initialized with the response" do + User.delete('http://api.example.com/user/5', {}).should == [ user, user ] + end + end + + context "with a collection and a specified remote object name" do + before :each do + FakeWeb.register_uri(:delete, "http://api.example.com/user/5", :status => "201", :body => '{"users": [ {"a": "a", "b": "b"}, {"a": "a", "b": "b"} ] }') + Admin.stub(:new).and_return(user) + end + + it "should return a collection of objects initialized with the response" do + Admin.delete('http://api.example.com/user/5', {}).should == [ user, user ] + end end end end end \ No newline at end of file