spec/railtie_spec.rb in api-auth-1.3.2 vs spec/railtie_spec.rb in api-auth-1.4.0

- old
+ new

@@ -48,11 +48,16 @@ ActionController::Routing::Routes.draw {|map| map.resources :test } end def generated_response(request, action = :index) if defined?(ActionDispatch) - TestController.action(action).call(request.env).last + response = ActionDispatch::TestResponse.new + controller = TestController.new + controller.request = request + controller.response = response + controller.process(action) + response else request.action = action.to_s request.path = "/#{action.to_s}" TestController.new.process(request, ActionController::TestResponse.new) end @@ -61,44 +66,44 @@ it "should permit a request with properly signed headers" do request = ActionController::TestRequest.new request.env['DATE'] = Time.now.utc.httpdate ApiAuth.sign!(request, "1044", API_KEY_STORE["1044"]) response = generated_response(request, :index) - response.code.should == "200" + expect(response.code).to eq("200") end it "should forbid a request with properly signed headers but timestamp > 15 minutes" do request = ActionController::TestRequest.new request.env['DATE'] = "Mon, 23 Jan 1984 03:29:56 GMT" ApiAuth.sign!(request, "1044", API_KEY_STORE["1044"]) response = generated_response(request, :index) - response.code.should == "401" + expect(response.code).to eq("401") end it "should insert a DATE header in the request when one hasn't been specified" do request = ActionController::TestRequest.new ApiAuth.sign!(request, "1044", API_KEY_STORE["1044"]) - request.headers['DATE'].should_not be_nil + expect(request.headers['DATE']).not_to be_nil end it "should forbid an unsigned request to a protected controller action" do request = ActionController::TestRequest.new response = generated_response(request, :index) - response.code.should == "401" + expect(response.code).to eq("401") end it "should forbid a request with a bogus signature" do request = ActionController::TestRequest.new request.env['Authorization'] = "APIAuth bogus:bogus" response = generated_response(request, :index) - response.code.should == "401" + expect(response.code).to eq("401") end it "should allow non-protected controller actions to function as before" do request = ActionController::TestRequest.new response = generated_response(request, :public) - response.code.should == "200" + expect(response.code).to eq("200") end end describe "Rails ActiveResource integration" do @@ -109,10 +114,10 @@ self.format = :xml end it "should send signed requests automagically" do timestamp = Time.parse("Mon, 23 Jan 1984 03:29:56 GMT") - Time.should_receive(:now).at_least(1).times.and_return(timestamp) + expect(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',