mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
improve the specs to check we properly update 'user.last_emailed_at'
This commit is contained in:
parent
26bba1f481
commit
3390fa56d0
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue