forked from solidusio/solidus_auth_devise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request solidusio#192 from nebulab/kennyadsl/redirect-back…
…-if-not-authorized Redirect back if not authorized
- Loading branch information
Showing
3 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Spree::Admin::BaseController, type: :controller do | ||
describe '#unauthorized_redirect' do | ||
controller(described_class) do | ||
def index; authorize!(:read, :something); end | ||
end | ||
|
||
before do | ||
stub_spree_preferences(Spree::Config, redirect_back_on_unauthorized: true) | ||
end | ||
|
||
context "when user is logged in" do | ||
before { sign_in(create(:user)) } | ||
|
||
context "when http_referrer is not present" do | ||
it "redirects to unauthorized path" do | ||
get :index | ||
expect(response).to redirect_to(spree.admin_unauthorized_path) | ||
end | ||
end | ||
|
||
context "when http_referrer is present" do | ||
before { request.env['HTTP_REFERER'] = '/redirect' } | ||
|
||
it "redirects back" do | ||
get :index | ||
expect(response).to redirect_to('/redirect') | ||
end | ||
end | ||
end | ||
|
||
context "when user is not logged in" do | ||
context "when http_referrer is not present" do | ||
it "redirects to login path" do | ||
get :index | ||
expect(response).to redirect_to(spree.admin_login_path) | ||
end | ||
end | ||
|
||
context "when http_referrer is present" do | ||
before { request.env['HTTP_REFERER'] = '/redirect' } | ||
|
||
it "redirects back" do | ||
get :index | ||
expect(response).to redirect_to('/redirect') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Spree::BaseController, type: :controller do | ||
describe '#unauthorized_redirect' do | ||
controller(described_class) do | ||
def index; authorize!(:read, :something); end | ||
end | ||
|
||
before do | ||
stub_spree_preferences(Spree::Config, redirect_back_on_unauthorized: true) | ||
end | ||
|
||
context "when user is logged in" do | ||
before { sign_in(create(:user)) } | ||
|
||
context "when http_referrer is not present" do | ||
it "redirects to unauthorized path" do | ||
get :index | ||
expect(response).to redirect_to(spree.unauthorized_path) | ||
end | ||
end | ||
|
||
context "when http_referrer is present" do | ||
before { request.env['HTTP_REFERER'] = '/redirect' } | ||
|
||
it "redirects back" do | ||
get :index | ||
expect(response).to redirect_to('/redirect') | ||
end | ||
end | ||
end | ||
|
||
context "when user is not logged in" do | ||
context "when http_referrer is not present" do | ||
it "redirects to login path" do | ||
get :index | ||
expect(response).to redirect_to(spree.login_path) | ||
end | ||
end | ||
|
||
context "when http_referrer is present" do | ||
before { request.env['HTTP_REFERER'] = '/redirect' } | ||
|
||
it "redirects back" do | ||
get :index | ||
expect(response).to redirect_to('/redirect') | ||
end | ||
end | ||
end | ||
end | ||
end |