mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
When registering a new enterprise, if user is signed in, owns a hub and is not making a producer, the new enterprise becomes a hub
This commit is contained in:
@@ -63,7 +63,9 @@ module Api
|
||||
end
|
||||
|
||||
def override_sells
|
||||
params[:enterprise][:sells] = 'unspecified'
|
||||
has_hub = current_api_user.enterprises.is_hub.any?
|
||||
new_enterprise_is_producer = !!params[:enterprise][:is_primary_producer]
|
||||
params[:enterprise][:sells] = (has_hub && !new_enterprise_is_producer) ? 'any' : 'unspecified'
|
||||
end
|
||||
|
||||
def override_visible
|
||||
|
||||
@@ -20,6 +20,19 @@ module Api
|
||||
Spree.user_class.stub :find_by_spree_api_key => enterprise_manager
|
||||
end
|
||||
|
||||
describe "creating an enterprise" do
|
||||
let(:australia) { Spree::Country.find_by_name('Australia') }
|
||||
let(:new_enterprise_params) { {enterprise: {name: 'name', email: 'email@example.com', address_attributes: {address1: '123 Abc Street', city: 'Northcote', zipcode: '3070', state_id: australia.states.first, country_id: australia.id } } } }
|
||||
|
||||
it "creates as sells=any when it is not a producer" do
|
||||
spree_post :create, new_enterprise_params
|
||||
response.should be_success
|
||||
|
||||
enterprise = Enterprise.last
|
||||
enterprise.sells.should == 'any'
|
||||
end
|
||||
end
|
||||
|
||||
describe "submitting a valid image" do
|
||||
before do
|
||||
enterprise.stub(:update_attributes).and_return(true)
|
||||
|
||||
Reference in New Issue
Block a user