diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 794bc58..c94645c 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -41,46 +41,22 @@ describe FakesController do end describe "action raise unauthorized" do - context "when xhr" do - before { allow(request).to receive(:xhr?).and_return(true) } + it "redirects to login page" do + expect(@controller).to receive(:store_location) - it "responds with 401" do - get :foo - - expect(response.status).to eq(401) - end - end + get :foo - context "when normal request" do - it "redirects to login page" do - expect(@controller).to receive(:store_location) - - get :foo - - expect(flash[:notice]).to eq("Please log in to proceed") - should redirect_to(new_login_path) - end + expect(flash[:notice]).to eq("Please log in to proceed") + should redirect_to(new_login_path) end end context "when action raises Pundit::NotAuthorizedError" do - context "when xhr" do - before { allow(request).to receive(:xhr?).and_return(true) } + it "redirects to root_path" do + get :bar - it "responds with 403" do - get :bar - - expect(response.status).to eq(403) - end - end - - context "when normal request" do - it "redirects to root_path" do - get :bar - - expect(flash[:alert]).to_not be(nil) - should redirect_to(root_path) - end + expect(flash[:alert]).to_not be(nil) + should redirect_to(root_path) end end