diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 366d27d1de..b17fe3ce40 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -14,8 +14,7 @@ class AbilityDecorator def can_manage_products?(user) - can_manage_enterprises? user - # ( user.enterprises.map(&:type) & %w(single full) ).any? + ( user.enterprises.map(&:type) & %w(single full) ).any? end diff --git a/spec/factories.rb b/spec/factories.rb index 7102229cff..849d38abf3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -83,6 +83,7 @@ FactoryGirl.define do factory :enterprise, :class => Enterprise do sequence(:name) { |n| "Enterprise #{n}" } + type 'full' description 'enterprise' long_description '
Hello, world!
This is a paragraph.
' email 'enterprise@example.com' diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index 3a0ea1cc28..a75eea6b8b 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -6,10 +6,12 @@ feature %q{ } do include AuthenticationWorkflow include WebHelper + include AdminHelper let!(:user) { create_enterprise_user } let!(:supplier1) { create(:supplier_enterprise, name: 'Supplier 1') } let!(:supplier2) { create(:supplier_enterprise, name: 'Supplier 2') } + let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', type: 'profile') } let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') } let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') } @@ -74,6 +76,25 @@ feature %q{ end end + describe "with only a profile-level enterprise" do + before do + user.enterprise_roles.create! enterprise: supplier_profile + login_to_admin_as user + end + + it "shows me only menu items for enterprise management" do + page.should have_admin_menu_item 'Dashboard' + page.should have_admin_menu_item 'Enterprises' + + ['Orders', 'Products', 'Reports', 'Configuration', 'Promotions', 'Users', 'Order Cycles'].each do |menu_item_name| + page.should_not have_admin_menu_item menu_item_name + end + end + + it "shows me a cut-down dashboard" + it "shows me only profile options on the enterprises page" + end + describe "system management lockdown" do before do user.enterprise_roles.create!(enterprise: supplier1) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 9705fee70e..a2d1fb5bdf 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -6,6 +6,46 @@ module Spree describe User do + describe "broad permissions" do + subject { AbilityDecorator.new(user) } + let(:user) { create(:user) } + let(:enterprise_full) { create(:enterprise, type: 'full') } + let(:enterprise_single) { create(:enterprise, type: 'single') } + let(:enterprise_profile) { create(:enterprise, type: 'profile') } + + describe "managing enterprises" do + it "can manage enterprises when the user has at least one enterprise assigned" do + user.enterprise_roles.create! enterprise: enterprise_full + subject.can_manage_enterprises?(user).should be_true + end + + it "can't otherwise" do + subject.can_manage_enterprises?(user).should be_false + end + end + + describe "managing products" do + it "can when a user manages a 'full' type enterprise" do + user.enterprise_roles.create! enterprise: enterprise_full + subject.can_manage_products?(user).should be_true + end + + it "can when a user manages a 'single' type enterprise" do + user.enterprise_roles.create! enterprise: enterprise_single + subject.can_manage_products?(user).should be_true + end + + it "can't when a user manages a 'profile' type enterprise" do + user.enterprise_roles.create! enterprise: enterprise_profile + subject.can_manage_products?(user).should be_false + end + + it "can't when the user manages no enterprises" do + subject.can_manage_products?(user).should be_false + end + end + end + describe 'Roles' do # create enterprises diff --git a/spec/support/request/admin_helper.rb b/spec/support/request/admin_helper.rb new file mode 100644 index 0000000000..ff0c50b6f5 --- /dev/null +++ b/spec/support/request/admin_helper.rb @@ -0,0 +1,5 @@ +module AdminHelper + def have_admin_menu_item(menu_item_name) + have_selector "ul[data-hook='admin_tabs'] li", text: menu_item_name + end +end