spec/lib/connection_spec.rb in api_resource-0.6.18 vs spec/lib/connection_spec.rb in api_resource-0.6.19

- old
+ new

@@ -1,25 +1,25 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') include ApiResource describe Connection do - + it "should be able to set the token directly on ApiResource" do ApiResource.token = "123" ApiResource::Base.token.should eql "123" end - + it "should be able to set a default token value, which is passed through each request" do - ApiResource::Mocks::Connection.expects(:get).with("/test_resources/1.json", {"Accept"=>"application/json", "Lifebooker-Token" => "abc"}).returns(ApiResource::Mocks::MockResponse.new({})) + ApiResource::Mocks::Connection.expects(:get).with("/test_resources/1.json", {}, {"Accept"=>"application/json", "Lifebooker-Token" => "abc"}).returns(ApiResource::Mocks::MockResponse.new({})) ApiResource::Base.token = "abc" TestResource.find(1) end it "should set the Lifebooker-Token if one is present for GET requests" do token = Kernel.rand(100000).to_s - ApiResource::Mocks::Connection.expects(:get).with("/test_resources/1.json", {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) + ApiResource::Mocks::Connection.expects(:get).with("/test_resources/1.json", {}, {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) ApiResource::Base.token = token TestResource.connection.get("/test_resources/1.json") end @@ -42,20 +42,20 @@ TestResource.connection.head("/test_resources/1.json") end it "should set the Lifebooker-Token if one is present for POST requests" do token = Kernel.rand(100000).to_s - ApiResource::Mocks::Connection.expects(:post).with("/test_resources/1.json", {}, {"Content-Type"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) + ApiResource::Mocks::Connection.expects(:post).with("/test_resources/1.json", '{}', {"Content-Type"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) ApiResource::Base.token = token TestResource.connection.post("/test_resources/1.json") end it "should set the Lifebooker-Token if one is present for PUT requests" do token = Kernel.rand(100000).to_s - ApiResource::Mocks::Connection.expects(:put).with("/test_resources/1.json", {}, {"Content-Type"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) + ApiResource::Mocks::Connection.expects(:put).with("/test_resources/1.json", '{}', {"Content-Type"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({})) ApiResource::Base.token = token TestResource.connection.put("/test_resources/1.json") end @@ -73,11 +73,11 @@ ApiResource::Base.token = token TestResource.connection.headers.include?("Lifebooker-Token").should eql true TestResource.connection.headers["Lifebooker-Token"] = token end - + it "should be able to set a token for a given block" do ApiResource::Base.token = "123456" begin ApiResource.with_token("testing") do ApiResource::Base.token.should eql "testing" @@ -86,18 +86,18 @@ rescue => e # should still reset the token end ApiResource::Base.token.should eql "123456" end - + it "should provider a method to regenerate its connection" do conn = ApiResource::Base.connection conn.should be ApiResource::Base.connection ApiResource.reset_connection conn.should_not be ApiResource::Base.connection end - + context "No Mocks" do before(:all) do ApiResource::Mocks.remove end after(:all) do @@ -109,29 +109,29 @@ ApiResource.timeout = 1 ApiResource.timeout.should eql 1 ApiResource.open_timeout = 1 ApiResource.open_timeout.should eql 1 - ApiResource::Base.connection.send(:http, "/test").options[:timeout].should eql 1 - ApiResource::Base.connection.send(:http, "/test").options[:open_timeout].should eql 1 - + ApiResource::Base.connection.send(:http).receive_timeout.should eql 1 + ApiResource::Base.connection.send(:http).connect_timeout.should eql 1 + ApiResource.timeout = 100 - ApiResource::Base.connection.send(:http, "/test").options[:timeout].should eql 100 + ApiResource::Base.connection.send(:http).receive_timeout.should eql 100 end - - it "should time out if RestClient takes too long" do - + + it "should time out if HttpClient takes too long" do + # hopefully google won't actually respond this fast :) ApiResource.timeout = 0.001 ApiResource::Base.site = "http://www.google.com" lambda{ ApiResource::Base.connection.get("/") }.should raise_error(ApiResource::RequestTimeout) - + end - + end context "headers" do it "should include the Lifebooker-Token in its headers" do @@ -148,9 +148,9 @@ TestResource.connection.headers["Lifebooker-Token"].should eql(old_token) end end - - + + end \ No newline at end of file