diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb index 43c1583bbb..920d41d65e 100644 --- a/app/helpers/shop_helper.rb +++ b/app/helpers/shop_helper.rb @@ -9,8 +9,14 @@ module ShopHelper end def require_customer? - current_distributor.require_login? && !( - spree_current_user.andand.customer_of current_distributor + current_distributor.require_login? && !user_is_related_to_distributor? + end + + def user_is_related_to_distributor? + spree_current_user.present? && ( + spree_current_user.admin? || + spree_current_user.enterprises.include?(current_distributor) || + spree_current_user.customer_of(current_distributor) ) end end diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index fe706c24ab..a8545af3db 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -301,6 +301,29 @@ feature "As a consumer I want to shop with a distributor", js: true do expect(page).to have_content product.name end end + + context "as a manager" do + let!(:role) { create(:enterprise_role, user: user, enterprise: distributor) } + + it "shows just products" do + visit shop_path + expect(page).to have_no_content "This shop is for customers only." + expect(page).to have_content product.name + end + end + + context "as the owner" do + before do + distributor.owner = user + distributor.save! + end + + it "shows just products" do + visit shop_path + expect(page).to have_no_content "This shop is for customers only." + expect(page).to have_content product.name + end + end end end end