From 09a102bd8b410f19167b1c641f48bebe82ec790f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 27 Mar 2015 11:53:13 +1100 Subject: [PATCH] When an enterprise user with a hub creates a new producer, it does not default to sells any #453 --- app/controllers/admin/enterprises_controller.rb | 3 ++- .../controllers/admin/enterprises_controller_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 94522da36f..d2b25c55df 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -133,7 +133,8 @@ module Admin def override_sells unless spree_current_user.admin? has_hub = spree_current_user.enterprises.is_hub.any? - params[:enterprise][:sells] = has_hub ? 'any' : 'none' + new_enterprise_is_producer = !!params[:enterprise][:is_primary_producer] + params[:enterprise][:sells] = (has_hub && !new_enterprise_is_producer) ? 'any' : 'none' end end diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 86b128af38..6f108da003 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -48,7 +48,7 @@ module Admin end context "when I already have a hub" do - it "creates the new enterprise as a hub" do + it "creates new non-producers as hubs" do controller.stub spree_current_user: distributor_manager enterprise_params[:enterprise][:owner_id] = distributor_manager @@ -57,6 +57,16 @@ module Admin enterprise.sells.should == 'any' end + it "creates new producers as sells none" do + controller.stub spree_current_user: distributor_manager + enterprise_params[:enterprise][:owner_id] = distributor_manager + enterprise_params[:enterprise][:is_primary_producer] = '1' + + spree_put :create, enterprise_params + enterprise = Enterprise.find_by_name 'zzz' + enterprise.sells.should == 'none' + end + it "doesn't affect the hub status for super admins" do admin_user.enterprises << create(:distributor_enterprise)