Simplify creating notifications in specs

This commit is contained in:
Javi Martín
2019-09-28 02:33:13 +02:00
parent f535d81877
commit 1973c61552
4 changed files with 21 additions and 18 deletions

View File

@@ -21,11 +21,8 @@ describe EmailDigest do
it "returns only proposal notifications" do
user = create(:user)
proposal_notification = create(:proposal_notification)
comment = create(:comment)
notification1 = create(:notification, notifiable: proposal_notification, user: user)
notification2 = create(:notification, notifiable: comment, user: user)
notification1 = create(:notification, :for_proposal_notification, user: user)
notification2 = create(:notification, :for_comment, user: user)
email_digest = EmailDigest.new(user)
@@ -40,8 +37,7 @@ describe EmailDigest do
it "returns true when notifications have not been emailed" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user)
notification = create(:notification, :for_proposal_notification, user: user)
email_digest = EmailDigest.new(user)
expect(email_digest.pending_notifications?).to be
@@ -50,8 +46,7 @@ describe EmailDigest do
it "returns false when notifications have been emailed" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
notification = create(:notification, :for_proposal_notification, user: user, emailed_at: Time.current)
email_digest = EmailDigest.new(user)
expect(email_digest.pending_notifications?).not_to be
@@ -70,8 +65,7 @@ describe EmailDigest do
it "delivers email if notifications pending" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user)
notification = create(:notification, :for_proposal_notification, user: user)
reset_mailer
email_digest = EmailDigest.new(user)
@@ -84,8 +78,7 @@ describe EmailDigest do
it "does not deliver email if no notifications pending" do
user = create(:user)
proposal_notification = create(:proposal_notification)
create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
create(:notification, :for_proposal_notification, user: user, emailed_at: Time.current)
reset_mailer
email_digest = EmailDigest.new(user)