spec/railtie_spec.rb in api-auth-1.4.1 vs spec/railtie_spec.rb in api-auth-1.5.0
- old
+ new
@@ -114,20 +114,45 @@
self.format = :xml
end
it "should send signed requests automagically" do
timestamp = Time.parse("Mon, 23 Jan 1984 03:29:56 GMT")
- expect(Time).to receive(:now).at_least(1).times.and_return(timestamp)
+ allow(Time).to receive(:now).at_least(1).times.and_return(timestamp)
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/test_resources/1.xml",
{
'Authorization' => 'APIAuth 1044:IbTx7VzSOGU55HNbV4y2jZDnVis=',
'Accept' => 'application/xml',
'DATE' => "Mon, 23 Jan 1984 03:29:56 GMT"
},
{ :id => "1" }.to_xml(:root => 'test_resource')
end
+ expect(ApiAuth).to receive(:sign!).with(anything, "1044", API_KEY_STORE["1044"], { :with_http_method => false }).and_call_original
TestResource.find(1)
+ end
+
+ context "when telling it to include the http method in the signature" do
+ class TestResourceForHttpMethod < ActiveResource::Base
+ with_api_auth "1044", API_KEY_STORE["1044"], :sign_with_http_method => true
+ self.site = "http://localhost/"
+ self.format = :xml
+ end
+
+ it "signs with the http method" do
+ timestamp = Time.parse("Mon, 23 Jan 1984 03:29:56 GMT")
+ allow(Time).to receive(:now).at_least(1).times.and_return(timestamp)
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/test_resource_for_http_methods/1.xml",
+ {
+ 'Authorization' => 'APIAuth 1044:Gq190cxgKm7oWH1fc+y8+wmD9ts=',
+ 'Accept' => 'application/xml',
+ 'DATE' => "Mon, 23 Jan 1984 03:29:56 GMT"
+ },
+ { :id => "1" }.to_xml(:root => 'test_resource')
+ end
+ expect(ApiAuth).to receive(:sign!).with(anything, "1044", API_KEY_STORE["1044"], { :with_http_method => true }).and_call_original
+ TestResourceForHttpMethod.find(1)
+ end
end
end
end