From 3390fa56d0391c8bb7ea39c0ac18a6309d845e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 28 Jan 2016 19:30:38 +0100 Subject: [PATCH] improve the specs to check we properly update 'user.last_emailed_at' --- spec/jobs/user_email_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index 13f750cd9..a6467ad4d 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -64,19 +64,31 @@ describe Jobs::UserEmail do context "email_log" do it "creates an email log when the mail is sent" do + last_emailed_at = user.last_emailed_at + expect { Jobs::UserEmail.new.execute(type: :digest, user_id: user.id) }.to change { EmailLog.count }.by(1) + email_log = EmailLog.last expect(email_log.skipped).to eq(false) expect(email_log.user_id).to eq(user.id) + + # last_emailed_at should have changed + expect(email_log.user.last_emailed_at).to_not eq(last_emailed_at) end it "creates an email log when the mail is skipped" do + last_emailed_at = user.last_emailed_at user.update_columns(suspended_till: 1.year.from_now) + expect { Jobs::UserEmail.new.execute(type: :digest, user_id: user.id) }.to change { EmailLog.count }.by(1) + email_log = EmailLog.last expect(email_log.skipped).to eq(true) expect(email_log.skipped_reason).to be_present expect(email_log.user_id).to eq(user.id) + + # last_emailed_at doesn't change + expect(email_log.user.last_emailed_at).to eq(last_emailed_at) end end