Skip to content

Commit

Permalink
Remove unused parameter hide_recipients
Browse files Browse the repository at this point in the history
hide_recipients parameter is not used. We simplify gem
functionality by removing it. Related tests are also removed.
  • Loading branch information
Dragan Cabarkapa committed Nov 24, 2014
1 parent 20b9520 commit 45ef54f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 36 deletions.
7 changes: 1 addition & 6 deletions app/mailers/spree/to_friend_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ def mail_to_friend(object, mail)
@mail = mail
opts = {}

if mail.hide_recipients
opts[:to] = mail.recipients.first
opts[:bcc] = mail.recipients[1..-1] if mail.recipients.size > 1
else
opts[:to] = mail.recipients
end
opts[:to] = mail.recipients
default_url_options[:host] = mail.host
opts[:subject] = mail.subject
opts[:reply_to] = mail.sender_email
Expand Down
3 changes: 1 addition & 2 deletions app/models/spree/mail_to_friend.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Spree::MailToFriend
include ActiveModel::Validations
include ActiveModel::Conversion
attr_accessor :host, :subject, :sender_name, :sender_email, :recipient_name, :recipient_email, :message, :recipients, :invalid_recipients, :hide_recipients
attr_accessor :host, :subject, :sender_name, :sender_email, :recipient_name, :recipient_email, :message, :recipients, :invalid_recipients

EMAILREGEX = /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}\z/i

Expand Down Expand Up @@ -31,7 +31,6 @@ def initialize(opts = {})
@recipient_name = opts[:recipient_name]
@recipient_name ||= @recipients[0].split('@', 2)[0].titleize unless @recipients.empty?

@hide_recipients = opts[:hide_recipients] || false
@message = opts[:message]
end

Expand Down
1 change: 0 additions & 1 deletion spec/factories/mail_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
message 'Its totally awesome..'

recipients { Array(1..4).sample.times.map{ Faker::Internet.email } }
hide_recipients { [true,false].sample }
invalid_recipients []
end
end
30 changes: 3 additions & 27 deletions spec/mailers/to_friend_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
let!(:product) { create(:product) }

context 'mail content' do
let(:mail_object) { build(:mail, hide_recipients: true) }
let(:mail_object) { build(:mail) }
let(:email) { Spree::ToFriendMailer.mail_to_friend(product, mail_object) }

it 'is reply to the sender email' do
expect(email).to reply_to(mail_object.sender_email)
end

it 'is delivered to the recipient email' do
expect(email).to deliver_to(mail_object.recipients.first)
it 'is delivered to the recipients' do
expect(email).to deliver_to(mail_object.recipients)
end

it 'have the correct subject' do
Expand All @@ -35,28 +35,4 @@
expect(email).to have_body_text(spree.product_path(product))
end
end

describe 'using hide recipients option' do
context 'when true' do
let(:mail_object) { build(:mail, recipients: ["sue@yahoo.com", "bill@yahoo.com", "john@yahoo.com"], hide_recipients: true) }
let(:email) { Spree::ToFriendMailer.mail_to_friend(product, mail_object) }

it 'include them in bcc' do
expect(email).to reply_to(mail_object.sender_email)
expect(email).to deliver_to('sue@yahoo.com')
expect(email).to bcc_to('bill@yahoo.com', 'john@yahoo.com')
end
end

context 'when false' do
let(:mail_object) { build(:mail, recipients: ["sue@yahoo.com", "bill@yahoo.com"], hide_recipients: false) }
let(:email) { Spree::ToFriendMailer.mail_to_friend(product, mail_object) }

it 'should not include bcc' do
expect(email).to reply_to(mail_object.sender_email)
expect(email).to deliver_to('sue@yahoo.com', 'bill@yahoo.com')
expect(email).to bcc_to([])
end
end
end
end

0 comments on commit 45ef54f

Please sign in to comment.