Module: Spree::TestingSupport::AuthorizationHelpers::Request

Includes:
CustomAbility
Defined in:
lib/spree/testing_support/authorization_helpers.rb

Instance Method Summary collapse

Methods included from CustomAbility

#build_ability

Instance Method Details

#custom_authorization!(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spree/testing_support/authorization_helpers.rb', line 52

def custom_authorization!(&block)
  ability = build_ability(&block)
  ability_class = Spree::Dependencies.ability_class.constantize

  after(:all) do
    ability_class.remove_ability(ability)
  end
  before(:all) do
    ability_class.register_ability(ability)
  end
end

#stub_authorization!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spree/testing_support/authorization_helpers.rb', line 31

def stub_authorization!
  ability = build_ability
  ability_class = Spree::Dependencies.ability_class.constantize

  after(:all) do
    ability_class.remove_ability(ability)
  end

  before(:all) do
    ability_class.register_ability(ability)
  end

  let(:admin_user) { FactoryBot.create(:admin_user) }

  before do
    if defined?(Spree::Admin::BaseController)
      allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(admin_user)
    end
  end
end