diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 033b4b79d7..93cfcfe5df 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -397,7 +397,7 @@ class Enterprise < ActiveRecord::Base end def ensure_email_set - self.email = owner.email if email.blank? + self.email = owner.email if email.blank? && owner.present? end def enforce_ownership_limit diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index aed96b5a91..46a0105bb4 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -47,7 +47,7 @@ feature %q{ fill_in 'enterprise_contact', :with => 'Kirsten or Ren' fill_in 'enterprise_phone', :with => '0413 897 321' - fill_in 'enterprise_email', :with => 'info@eaterprises.com.au' + fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au' fill_in 'enterprise_website', :with => 'http://eaterprises.com.au' fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St' @@ -130,7 +130,7 @@ feature %q{ click_link "Contact" fill_in 'enterprise_contact', :with => 'Kirsten or Ren' fill_in 'enterprise_phone', :with => '0413 897 321' - fill_in 'enterprise_email', :with => 'info@eaterprises.com.au' + fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au' fill_in 'enterprise_website', :with => 'http://eaterprises.com.au' click_link "Social" @@ -286,7 +286,7 @@ feature %q{ click_link 'Enterprises' click_link 'New Enterprise' fill_in 'enterprise_name', with: 'zzz' - fill_in 'enterprise_email', with: 'bob@example.com' + fill_in 'enterprise_email_address', with: 'bob@example.com' fill_in 'enterprise_address_attributes_address1', with: 'z' fill_in 'enterprise_address_attributes_city', with: 'z' fill_in 'enterprise_address_attributes_zipcode', with: 'z' diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 08c10dd31e..b8360094ec 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -180,7 +180,6 @@ describe Enterprise do describe "validations" do subject { FactoryGirl.create(:distributor_enterprise) } it { should validate_presence_of(:name) } - it { should validate_presence_of(:email) } it { should validate_uniqueness_of(:permalink) } it { should ensure_length_of(:description).is_at_most(255) } @@ -210,9 +209,15 @@ describe Enterprise do end it "does not prohibit the saving of an enterprise with no name clash" do - enterprise.email = 'new@email.com' enterprise.should be_valid end + + it "takes the owner's email address as default email" do + enterprise.email = nil + enterprise.should be_valid + enterprise.email.should be_present + enterprise.email.should eq owner.email + end end describe "preferred_shopfront_taxon_order" do