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

- old
+ new

@@ -73,27 +73,62 @@ lambda { ApiClient::Base.post('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(:post, "http://api.example.com/user/5", :status => "201", :body => '{"a": "a", "b": "b"}') - User.stub(:new).and_return(user) + context "without a specified port" do + before :each do + FakeWeb.register_uri(:post, "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.post('http://api.example.com/user/5', {}).should == user + end end - it "should return a object initialized with the response" do - User.post('http://api.example.com/user/5', {}).should == user + context "with a specified port" do + before :each do + FakeWeb.register_uri(:post, "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.post('http://api.example.com:3001/user/5', {}).should == user + end end - end - context "with a specified port" do - before :each do - FakeWeb.register_uri(:post, "http://api.example.com:3001/user/5", :status => "201", :body => '{"a": "a", "b": "b"}') - User.stub(:new).and_return(user) + context "with a specified remote object name" do + before :each do + FakeWeb.register_uri(:post, "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.post('http://api.example.com/user/5', {}).should == user + end end - it "should return a object initialized with the response" do - User.post('http://api.example.com:3001/user/5', {}).should == user + context "with a collection" do + before :each do + FakeWeb.register_uri(:post, "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.post('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(:post, "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.post('http://api.example.com/user/5', {}).should == [ user, user ] + end end end end end \ No newline at end of file