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:
Rohan Mitchell
2015-03-27 14:05:58 +11:00
parent d471368412
commit 0ed1eeffd6
2 changed files with 16 additions and 1 deletions

View File

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

View File

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