Sha256: 1b08b6ed9d987615f8ba4430975ba47e484f237e4b9adaf8476cb5b13f4daa2c

Contents?: true

Size: 1.83 KB

Versions: 27

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

class FakesController < ApplicationController
  include Spree::Core::ControllerHelpers::Auth
  def index; render text: 'index'; end
end

describe Spree::Core::ControllerHelpers::Auth, type: :controller do
  controller(FakesController) {}

  describe '#current_ability' do
    it 'returns Spree::Ability instance' do
      expect(controller.current_ability.class).to eq Spree::Ability
    end
  end

  describe '#redirect_back_or_default' do
    controller(FakesController) do
      def index; redirect_back_or_default('/'); end
    end
    it 'redirects to session url' do
      session[:spree_user_return_to] = '/redirect'
      get :index
      expect(response).to redirect_to('/redirect')
    end
    it 'redirects to default page' do
      get :index
      expect(response).to redirect_to('/')
    end
  end

  describe '#set_guest_token' do
    controller(FakesController) do
      def index
        set_guest_token
        render text: 'index'
      end
    end
    it 'sends cookie header' do
      get :index
      expect(response.cookies['guest_token']).not_to be_nil
    end
  end

  describe '#store_location' do
    it 'sets session return url' do
      allow(controller).to receive_messages(request: double(fullpath: '/redirect'))
      controller.store_location
      expect(session[:spree_user_return_to]).to eq '/redirect'
    end
  end

  describe '#try_spree_current_user' do
    it 'calls spree_current_user when define spree_current_user method' do
      expect(controller).to receive(:spree_current_user)
      controller.try_spree_current_user
    end
    it 'calls current_spree_user when define current_spree_user method' do
      expect(controller).to receive(:current_spree_user)
      controller.try_spree_current_user
    end
    it 'returns nil' do
      expect(controller.try_spree_current_user).to eq nil
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
solidus_core-1.4.2 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.2 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.2.3 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.1.4 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.0.7 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.4.1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.4.0 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.4.0.rc1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.4.0.beta1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.0 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.0.rc2 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.0.rc1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.3.0.beta1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.0.6 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.2.2 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.2.1 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.1.3 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.0.5 spec/lib/spree/core/controller_helpers/auth_spec.rb
solidus_core-1.2.0 spec/lib/spree/core/controller_helpers/auth_spec.rb