Skip to content

Commit 199206a

Browse files
committed
fixed remaining tests.
1 parent 6f2b296 commit 199206a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

app/mailers/notifier_mailer.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ def new_badge(username)
6060
track_campaign("new_badge_earned")
6161
@user = User.find_by_username(username)
6262
@user.touch(:last_email_sent)
63-
@user.reload
6463
@badge = next_badge_to_send(@user)
6564

66-
unless @badge.nil?
65+
if @badge.present?
6766
SentMail.create!(user: @user, sent_at: @user.last_email_sent, mailable: @badge)
6867
subject, @message = *new_badge_message_for_user(@user, @badge)
6968
mail to: @user.email, subject: "You've #{subject} on Coderwall!"

spec/mailers/notifier_mailer_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
user.update_attributes last_request_at: 1.day.ago
3737
expect(user.achievements_unlocked_since_last_visit.count).to eq(1)
3838

39-
email = NotifierMailer.new_badge(user.reload.username)
39+
email = NotifierMailer.new_badge(user.reload.username).deliver_now
4040
check_badge_message(email, badge)
41-
expect(email.body.encoded).to include(user_achievement_url(username: user.username, id: badge.id, host: 'coderwall.com'))
41+
expect(email.body.encoded).to include(user_achievement_url(username: user.username, id: badge.id, host: 'www.coderwall.com'))
4242
end
4343

4444
it 'should send one achievement email at a time until user visits' do
@@ -48,15 +48,15 @@
4848
user.update_attributes last_request_at: 1.day.ago
4949

5050
expect(user.achievements_unlocked_since_last_visit.count).to eq(3)
51-
email = NotifierMailer.new_badge(user.reload.username)
51+
email = NotifierMailer.new_badge(user.reload.username).deliver_now
5252
check_badge_message(email, badge1)
5353
expect(user.achievements_unlocked_since_last_visit.count).to eq(3)
54-
email = NotifierMailer.new_badge(user.reload.username)
54+
email = NotifierMailer.new_badge(user.reload.username).deliver_now
5555
check_badge_message(email, badge2)
5656
user.last_request_at = Time.now + 3.second
5757
user.save
5858
expect(user.achievements_unlocked_since_last_visit.count).to eq(0)
59-
expect { NotifierMailer.new_badge(user.reload.username) }.to raise_error(NotifierMailer::NothingToSendException)
59+
expect { NotifierMailer.new_badge(user.reload.username).deliver_now }.to raise_error(NotifierMailer::NothingToSendException)
6060
end
6161

6262
def check_badge_message(email, badge)

0 commit comments

Comments
 (0)