Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve AuthorizationHelpers for admin panel (#12033)

Damian Legawiecc3acd2655ac3
diff --git a/core/lib/spree/testing_support/authorization_helpers.rb b/core/lib/spree/testing_support/authorization_helpers.rb
index 668e3da875..4a09814ff3 100644
--- a/core/lib/spree/testing_support/authorization_helpers.rb
+++ b/core/lib/spree/testing_support/authorization_helpers.rb
@@ -37,12 +37,14 @@ module Spree
ability_class.register_ability(ability)
end
+ let(:user) { Spree.user_class.new }
let(:admin_app) { Spree::OauthApplication.create!(name: 'Admin Panel', scopes: 'admin') }
let(:admin_token) { Spree::OauthAccessToken.create!(application: admin_app, scopes: 'admin').token }
before do
- allow(Spree.user_class).to receive(:find_by).and_return(Spree.user_class.new)
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
if defined?(Spree::Admin)
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(user)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_application).and_return(admin_app)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_token).and_return(admin_token)
end