Skip to content

Commit

Permalink
Make sure special email addresses are only ever used for legal entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Feb 14, 2016
1 parent 64d2a60 commit c6a0abb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ def pickup_time
end

def email_for_invoicing
if invoicing_email.empty?
if self.is_a?(PrivateUser) || invoicing_email.empty?
email
else
invoicing_email
end
end

def email_for_order_notifications
if order_notifications_email.empty?
if self.is_a?(PrivateUser) || order_notifications_email.empty?
email
else
order_notifications_email
Expand Down
27 changes: 23 additions & 4 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

describe User do
let(:user) { FactoryGirl.create(:user) }
let(:private_stubbed) { FactoryGirl.build_stubbed(:private_user) }
let(:le_stubbed) { FactoryGirl.build_stubbed(:legal_entity) }
subject { User.new }

Expand Down Expand Up @@ -251,25 +252,43 @@
end

describe '#email_for_invoicing' do
it 'should use invoicing email if present' do
it 'for legal entities, should use invoicing email if present' do
le_stubbed.email_for_invoicing.must_equal le_stubbed.invoicing_email
end

it 'should use standard email address if no invoicing email is present' do
it 'for legal entities, should use standard email if no invoicing email is present' do
le_stubbed.invoicing_email = ''
le_stubbed.email_for_invoicing.must_equal le_stubbed.email
end

it 'for private users, should use standard email if no invoicing email is present' do
private_stubbed.email_for_invoicing.must_equal private_stubbed.email
end

it 'for private users, should use standard email even if invoicing email is present' do
private_stubbed.invoicing_email = 'invoices@example.com'
private_stubbed.email_for_invoicing.must_equal private_stubbed.email
end
end

describe '#email_for_order_notifications' do
it 'should use order notifications email if present' do
it 'for legal entities, should use order notifications email if present' do
le_stubbed.email_for_order_notifications.must_equal le_stubbed.order_notifications_email
end

it 'should use standard email address if no order notifications email is present' do
it 'for legal entities, should use standard email if no order notifications email is present' do
le_stubbed.order_notifications_email = ''
le_stubbed.email_for_order_notifications.must_equal le_stubbed.email
end

it 'for private users, should use standard email if no order notifications email is present' do
private_stubbed.email_for_order_notifications.must_equal private_stubbed.email
end

it 'for private users, should use standard email even if order notifications email is present' do
private_stubbed.order_notifications_email = 'orders@example.com'
private_stubbed.email_for_order_notifications.must_equal private_stubbed.email
end
end
end

Expand Down

0 comments on commit c6a0abb

Please sign in to comment.