When an enterprise user with a hub creates a new producer, it does not default to sells any #453

This commit is contained in:
Rohan Mitchell
2015-03-27 11:53:13 +11:00
parent d8656a36c6
commit 09a102bd8b
2 changed files with 13 additions and 2 deletions

View File

@@ -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

View File

@@ -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)