Sha256: 0ee8c43bde7f9db99a3f079d64e65885e83fa20146021d5a035b8d16e94d8b57

Contents?: true

Size: 1.44 KB

Versions: 33

Compression:

Stored size: 1.44 KB

Contents

module Spree
  module TestingSupport
    module AuthorizationHelpers
      module Controller
        def stub_authorization!
          before do
            controller.stub :authorize! => true
          end
        end
      end

      module Request
        class SuperAbility
          include CanCan::Ability

          def initialize(user)
            # allow anyone to perform anything on anything
            can :manage, :all
          end
        end

        def stub_authorization!
          after(:all) do
            ability = Spree::TestingSupport::AuthorizationHelpers::Request::SuperAbility
            Spree::Ability.remove_ability(ability)
          end
          before(:all) do
            ability = Spree::TestingSupport::AuthorizationHelpers::Request::SuperAbility
            Spree::Ability.register_ability(ability)
          end
        end

        def custom_authorization!(&block)
          ability = Class.new do
            include CanCan::Ability
            define_method(:initialize, block)
          end
          after(:all) do
            Spree::Ability.remove_ability(ability)
          end
          before(:all) do
            Spree::Ability.register_ability(ability)
          end
        end
      end
    end
  end
end

RSpec.configure do |config|
  config.extend Spree::TestingSupport::AuthorizationHelpers::Controller, :type => :controller
  config.extend Spree::TestingSupport::AuthorizationHelpers::Request, :type => :feature
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
spree_core-2.2.9 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.12 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.8 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.11 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.7 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.10 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.0.13 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.9 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.6 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.5 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.8 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.0.12 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.4 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.3 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.2 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.7 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.0.11 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.0.10 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.1.6 lib/spree/testing_support/authorization_helpers.rb
spree_core-2.2.1 lib/spree/testing_support/authorization_helpers.rb