|
|
@ -41,46 +41,22 @@ describe FakesController do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "action raise unauthorized" do
|
|
|
|
describe "action raise unauthorized" do
|
|
|
|
context "when xhr" do
|
|
|
|
it "redirects to login page" do
|
|
|
|
before { allow(request).to receive(:xhr?).and_return(true) }
|
|
|
|
expect(@controller).to receive(:store_location)
|
|
|
|
|
|
|
|
|
|
|
|
it "responds with 401" do
|
|
|
|
get :foo
|
|
|
|
get :foo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(response.status).to eq(401)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when normal request" do
|
|
|
|
expect(flash[:notice]).to eq("Please log in to proceed")
|
|
|
|
it "redirects to login page" do
|
|
|
|
should redirect_to(new_login_path)
|
|
|
|
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
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context "when action raises Pundit::NotAuthorizedError" do
|
|
|
|
context "when action raises Pundit::NotAuthorizedError" do
|
|
|
|
context "when xhr" do
|
|
|
|
it "redirects to root_path" do
|
|
|
|
before { allow(request).to receive(:xhr?).and_return(true) }
|
|
|
|
get :bar
|
|
|
|
|
|
|
|
|
|
|
|
it "responds with 403" do
|
|
|
|
expect(flash[:alert]).to_not be(nil)
|
|
|
|
get :bar
|
|
|
|
should redirect_to(root_path)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|