Skip to content

Commit

Permalink
Add a helper to stub authorization when visiting backend pages
Browse files Browse the repository at this point in the history
For some reason the core authorization helper is not working.
  • Loading branch information
elia committed Aug 1, 2023
1 parent f8f4378 commit 10e7b7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions admin/spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe "Accounts", type: :feature do
it "shows account info" do
user = create(:admin_user, email: '[email protected]')
stub_authorization! user
sign_in user

visit "/admin/account"
Expand Down
11 changes: 11 additions & 0 deletions admin/spec/support/solidus_admin/feature_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ module FeatureHelpers
def sign_in(user)
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
end

def stub_authorization!(user)
ability = Spree::Ability.new(user)
if block_given?
yield ability
else
ability.can :manage, :all
end
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:current_ability).and_return(ability)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
end
end
end

0 comments on commit 10e7b7f

Please sign in to comment.