From 2e021941d1048401481f423fba03f126909f6047 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 10 Apr 2015 11:14:56 +1000 Subject: [PATCH] Fix bug where new enterprises should be created as hubs, but aren't --- app/controllers/admin/enterprises_controller.rb | 2 +- spec/controllers/admin/enterprises_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 408fa63e02..d4b3244525 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -150,7 +150,7 @@ module Admin def override_sells unless spree_current_user.admin? has_hub = spree_current_user.owned_enterprises.is_hub.any? - new_enterprise_is_producer = !!params[:enterprise][:is_primary_producer] + new_enterprise_is_producer = Enterprise.new(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 4604520c00..3a40c8e501 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -20,7 +20,7 @@ module Admin describe "creating an enterprise" do let(:country) { Spree::Country.find_by_name 'Australia' } let(:state) { Spree::State.find_by_name 'Victoria' } - let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', email: "bob@example.com", address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} } + let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', is_primary_producer: '0', email: "bob@example.com", address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} } it "grants management permission if the current user is an enterprise user" do controller.stub spree_current_user: distributor_manager