/
challenge_mailer_spec.rb
62 lines (48 loc) · 1.71 KB
/
challenge_mailer_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'spec_helper'
describe ChallengeMailer do
let(:challenge) { double 'challenge' }
describe '#new_challenge' do
let(:mailer_delay) { double 'ChallengeMailer.delay' }
before do
ChallengeMailer.stub(:delay) { mailer_delay }
end
it 'sends multiple emails' do
users = [
create(:user, challenge_notification: true),
create(:user, challenge_notification: true),
]
users.each do |user|
mailer_delay.should_receive(:new_challenge_for_user).with(challenge, user)
end
ChallengeMailer.new_challenge challenge
end
it 'does not send emails to unsubscribed users' do
create(:user, challenge_notification: false)
users = [
create(:user, challenge_notification: true),
create(:user, challenge_notification: true),
]
users.each do |user|
mailer_delay.should_receive(:new_challenge_for_user).with(challenge, user)
end
ChallengeMailer.new_challenge challenge
end
end
describe '#new_challenge_for_user' do
subject { ChallengeMailer.new_challenge_for_user(challenge, user) }
let(:user) { double 'user' }
let(:time) { Time.now }
before do
user.stub first_name: 'John',
email: 'john@doe.com'
challenge.stub name: 'Challenge name',
closes_at: time
end
it { should have_subject 'Ново предизвикателство - Challenge name' }
it { should deliver_to 'john@doe.com' }
it { should have_body_text 'John' }
it { should have_body_text 'Challenge name' }
it { should have_body_text challenge_url(challenge) }
it { should have_body_text time.strftime('%d.%m.%Y %H:%M') }
end
end