Sha256: 1a093a59b1184b31503a5c17b163b00e7a8e20baac4b40143d34f5462743b07b

Contents?: true

Size: 1.36 KB

Versions: 10

Compression:

Stored size: 1.36 KB

Contents

# 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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
solidus_auth_devise-2.5.9 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.8 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.7 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.6 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.5 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.4 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.3 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.2 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.1 spec/controllers/spree/base_controller_spec.rb
solidus_auth_devise-2.5.0 spec/controllers/spree/base_controller_spec.rb