parent
b530ed0be0
commit
494518def1
4 changed files with 7 additions and 17 deletions
|
|
@ -37,10 +37,8 @@ class Notifier < ApplicationMailer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def invite(email, message, inviter, invitation_code, locale)
|
def invite(email, inviter, invitation_code, locale)
|
||||||
@inviter = inviter
|
@inviter = inviter
|
||||||
@message = message
|
|
||||||
@locale = locale
|
|
||||||
@invitation_code = invitation_code
|
@invitation_code = invitation_code
|
||||||
|
|
||||||
I18n.with_locale(locale) do
|
I18n.with_locale(locale) do
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
class EmailInviter
|
class EmailInviter
|
||||||
attr_accessor :emails, :message, :inviter, :locale
|
attr_accessor :emails, :inviter, :locale
|
||||||
|
|
||||||
def initialize(emails, inviter, options={})
|
def initialize(emails, inviter, options={})
|
||||||
options = options.symbolize_keys
|
options = options.symbolize_keys
|
||||||
self.message = options[:message]
|
|
||||||
self.locale = options.fetch(:locale, 'en')
|
self.locale = options.fetch(:locale, 'en')
|
||||||
self.inviter = inviter
|
self.inviter = inviter
|
||||||
self.emails = emails
|
self.emails = emails
|
||||||
|
|
@ -26,6 +25,6 @@ class EmailInviter
|
||||||
private
|
private
|
||||||
|
|
||||||
def mail(email)
|
def mail(email)
|
||||||
Notifier.invite(email, message, inviter, invitation_code, locale).deliver_now
|
Notifier.invite(email, inviter, invitation_code, locale).deliver_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
describe EmailInviter do
|
describe EmailInviter do
|
||||||
before do
|
before do
|
||||||
@user = double(:invitation_code => 'coolcodebro', :present? => true,
|
@user = double(invitation_code: "coolcodebro", present?: true, email: "foo@bar.com")
|
||||||
:email => 'foo@bar.com')
|
|
||||||
@emails = "mbs333@gmail.com, foo1@bar.com maxwell@dude.com"
|
@emails = "mbs333@gmail.com, foo1@bar.com maxwell@dude.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a list of emails' do
|
it "has a list of emails" do
|
||||||
inviter = EmailInviter.new(@emails, @user)
|
inviter = EmailInviter.new(@emails, @user)
|
||||||
expect(inviter.emails).not_to be_empty
|
expect(inviter.emails).not_to be_empty
|
||||||
end
|
end
|
||||||
|
|
@ -20,12 +19,6 @@ describe EmailInviter do
|
||||||
expect(inviter.inviter).not_to be_nil
|
expect(inviter.inviter).not_to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can have a message' do
|
|
||||||
message = "you guys suck hard"
|
|
||||||
inviter = EmailInviter.new("emails", @user, :message => message)
|
|
||||||
expect(inviter.message).to eq(message)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#emails' do
|
describe '#emails' do
|
||||||
it 'rejects the inviter email if present' do
|
it 'rejects the inviter email if present' do
|
||||||
inviter = EmailInviter.new(@emails + " #{@user.email}", @user)
|
inviter = EmailInviter.new(@emails + " #{@user.email}", @user)
|
||||||
|
|
|
||||||
|
|
@ -502,7 +502,7 @@ describe Notifier, type: :mailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".invite" do
|
describe ".invite" do
|
||||||
let(:email) { Notifier.invite(alice.email, nil, bob, "1234", "en") }
|
let(:email) { Notifier.invite(alice.email, bob, "1234", "en") }
|
||||||
|
|
||||||
it "goes to the right person" do
|
it "goes to the right person" do
|
||||||
expect(email.to).to eq([alice.email])
|
expect(email.to).to eq([alice.email])
|
||||||
|
|
@ -522,7 +522,7 @@ describe Notifier, type: :mailer do
|
||||||
|
|
||||||
it "has the inviter id if the name is nil" do
|
it "has the inviter id if the name is nil" do
|
||||||
bob.person.profile.update_attributes(first_name: "", last_name: "")
|
bob.person.profile.update_attributes(first_name: "", last_name: "")
|
||||||
mail = Notifier.invite(alice.email, nil, bob, "1234", "en")
|
mail = Notifier.invite(alice.email, bob, "1234", "en")
|
||||||
expect(email.body.encoded).to_not include("#{bob.name} (#{bob.diaspora_handle})")
|
expect(email.body.encoded).to_not include("#{bob.name} (#{bob.diaspora_handle})")
|
||||||
expect(mail.body.encoded).to include(bob.person.diaspora_handle)
|
expect(mail.body.encoded).to include(bob.person.diaspora_handle)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue