mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
When an enterprise user with a hub creates a new producer, it does not default to sells any #453
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user