spec/satisfaction/loader_spec.rb in ruby-satisfaction-0.6.5 vs spec/satisfaction/loader_spec.rb in ruby-satisfaction-0.6.7
- old
+ new
@@ -6,20 +6,20 @@
describe "#get" do
before(:each) do
@response = nil
@status_code = '200'
+ @loader = Sfn::Loader.new
@get = lambda do
FakeWeb.register_uri(
:get,
'http://test',
:body => @response_body,
:status => [@status_code]
)
- loader = Sfn::Loader.new
- stub(loader).add_authentication {}
- @response = loader.get('http://test')
+ stub(@loader).add_authentication {}
+ @response = @loader.get('http://test')
end
end
describe "when the status is successful (2xx)" do
before(:each) do
@@ -31,10 +31,25 @@
it "should return a status of :ok and the response body" do
@response.should == [:ok, @response_body]
end
end
+ describe "when the status is not modified (304)" do
+ before(:each) do
+ @status_code = '304'
+ @cached_body = {:id => "123", :domain => "foo.bar"}.to_json
+ @response_body = nil
+ stub(@loader.cache).get(anything) { Sfn::Loader::CacheRecord.new('http://test', 'etag-foo', @cached_body) }
+
+ @get.call
+ end
+
+ it "should return a status of :ok and the cached response body" do
+ @response.should == [:ok, @cached_body]
+ end
+ end
+
describe "when we are in a redirect loop" do
attr_reader :loader
before(:each) do
@url = 'http://loop/'
@@ -152,10 +167,31 @@
e.class.should == Sfn::Error
e.message.should == "Encountered error. Body of response:\n" + @response_body
end
end
end
+
+ # ---- GATEWAY -----------------------------------------------------------------------------------------------
+ describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
+ before(:each) do
+ @status_code = '502'
+ end
+
+ it "should raise an Sfn::BadGateway error" do
+ @get.should raise_error(Sfn::BadGateway, "Bad Gateway")
+ end
+ end
+
+ describe "when the status is 504 (GatewayTimeOut)" do
+ before(:each) do
+ @status_code = '504'
+ end
+
+ it "should raise an Sfn::GatewayTimeOut error" do
+ @get.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
+ end
+ end
end
# ==== POST ==================================================================================================
describe "#post" do
before(:each) do
@@ -297,9 +333,30 @@
@post.call
rescue Sfn::Error => e
e.class.should == Sfn::Error
e.message.should == "Encountered error. Body of response:\n" + @response_body
end
+ end
+ end
+
+ # ---- GATEWAY -----------------------------------------------------------------------------------------------
+ describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
+ before(:each) do
+ @status_code = '502'
+ end
+
+ it "should raise an Sfn::BadGateway error" do
+ @post.should raise_error(Sfn::BadGateway, "Bad Gateway")
+ end
+ end
+
+ describe "when the status is 504 (GatewayTimeOut)" do
+ before(:each) do
+ @status_code = '504'
+ end
+
+ it "should raise an Sfn::GatewayTimeOut error" do
+ @post.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
end
end
end