From afa6119ec1aa6e9f8a3d38e2e0620574aa02345a Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Wed, 22 Oct 2014 14:53:20 +1100 Subject: [PATCH] better coverage for enterprise abilities, hide products from non producers --- spec/models/spree/ability_spec.rb | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index c44601bb86..caf09853f1 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -12,30 +12,63 @@ module Spree let(:enterprise_any) { create(:enterprise, sells: 'any') } let(:enterprise_own) { create(:enterprise, sells: 'own') } let(:enterprise_none) { create(:enterprise, sells: 'none') } + let(:enterprise_any_producer) { create(:enterprise, sells: 'any', is_primary_producer: true) } + let(:enterprise_own_producer) { create(:enterprise, sells: 'own', is_primary_producer: true) } + let(:enterprise_none_producer) { create(:enterprise, sells: 'none', is_primary_producer: true) } - context "as manager of a 'any' type enterprise" do + context "as manager of an enterprise who sells 'any'" do before do user.enterprise_roles.create! enterprise: enterprise_any end - it { subject.can_manage_products?(user).should be_true } + it { subject.can_manage_products?(user).should be_false } it { subject.can_manage_enterprises?(user).should be_true } it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'own' type enterprise" do + context "as manager of an enterprise who sell 'own'" do before do user.enterprise_roles.create! enterprise: enterprise_own end + it { subject.can_manage_products?(user).should be_false } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_true } + end + + context "as manager of an enterprise who sells 'none'" do + before do + user.enterprise_roles.create! enterprise: enterprise_none + end + + it { subject.can_manage_products?(user).should be_false } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_false } + end + + context "as manager of a producer enterprise who sells 'any'" do + before do + user.enterprise_roles.create! enterprise: enterprise_any_producer + end + it { subject.can_manage_products?(user).should be_true } it { subject.can_manage_enterprises?(user).should be_true } it { subject.can_manage_orders?(user).should be_true } end - context "as manager of a 'none' type enterprise" do + context "as manager of a producer enterprise who sell 'own'" do before do - user.enterprise_roles.create! enterprise: enterprise_none + user.enterprise_roles.create! enterprise: enterprise_own_producer + end + + it { subject.can_manage_products?(user).should be_true } + it { subject.can_manage_enterprises?(user).should be_true } + it { subject.can_manage_orders?(user).should be_true } + end + + context "as manager of a producer enterprise who sells 'none'" do + before do + user.enterprise_roles.create! enterprise: enterprise_none_producer end it { subject.can_manage_products?(user).should be_true }