Simplify creating notifications in specs
This commit is contained in:
@@ -6,6 +6,18 @@ FactoryBot.define do
|
|||||||
trait :read do
|
trait :read do
|
||||||
read_at { Time.current }
|
read_at { Time.current }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :for_proposal_notification do
|
||||||
|
association :notifiable, factory: :proposal_notification
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :for_comment do
|
||||||
|
association :notifiable, factory: :comment
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :for_poll_question do
|
||||||
|
association :notifiable, factory: :poll_question
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :admin_notification do
|
factory :admin_notification do
|
||||||
|
|||||||
@@ -303,13 +303,11 @@ describe "Emails" do
|
|||||||
|
|
||||||
scenario "notifications moderated are not sent" do
|
scenario "notifications moderated are not sent" do
|
||||||
user = create(:user, email_digest: true)
|
user = create(:user, email_digest: true)
|
||||||
proposal = create(:proposal)
|
notification = create(:notification, :for_proposal_notification)
|
||||||
proposal_notification = create(:proposal_notification, proposal: proposal)
|
|
||||||
notification = create(:notification, notifiable: proposal_notification)
|
|
||||||
|
|
||||||
reset_mailer
|
reset_mailer
|
||||||
|
|
||||||
proposal_notification.moderate_system_email(create(:administrator).user)
|
notification.notifiable.moderate_system_email(create(:administrator).user)
|
||||||
|
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
email_digest.deliver(Time.current)
|
email_digest.deliver(Time.current)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ describe "Notifications" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Notification's notifiable model no longer includes Notifiable module" do
|
scenario "Notification's notifiable model no longer includes Notifiable module" do
|
||||||
create(:notification, notifiable: create(:poll_question), user: user)
|
create(:notification, :for_poll_question, user: user)
|
||||||
|
|
||||||
click_notifications_icon
|
click_notifications_icon
|
||||||
expect(page).to have_content("This resource is not available anymore.", count: 1)
|
expect(page).to have_content("This resource is not available anymore.", count: 1)
|
||||||
|
|||||||
@@ -21,11 +21,8 @@ describe EmailDigest do
|
|||||||
it "returns only proposal notifications" do
|
it "returns only proposal notifications" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
proposal_notification = create(:proposal_notification)
|
notification1 = create(:notification, :for_proposal_notification, user: user)
|
||||||
comment = create(:comment)
|
notification2 = create(:notification, :for_comment, user: user)
|
||||||
|
|
||||||
notification1 = create(:notification, notifiable: proposal_notification, user: user)
|
|
||||||
notification2 = create(:notification, notifiable: comment, user: user)
|
|
||||||
|
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
|
|
||||||
@@ -40,8 +37,7 @@ describe EmailDigest do
|
|||||||
it "returns true when notifications have not been emailed" do
|
it "returns true when notifications have not been emailed" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
proposal_notification = create(:proposal_notification)
|
notification = create(:notification, :for_proposal_notification, user: user)
|
||||||
notification = create(:notification, notifiable: proposal_notification, user: user)
|
|
||||||
|
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
expect(email_digest.pending_notifications?).to be
|
expect(email_digest.pending_notifications?).to be
|
||||||
@@ -50,8 +46,7 @@ describe EmailDigest do
|
|||||||
it "returns false when notifications have been emailed" do
|
it "returns false when notifications have been emailed" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
proposal_notification = create(:proposal_notification)
|
notification = create(:notification, :for_proposal_notification, user: user, emailed_at: Time.current)
|
||||||
notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
|
|
||||||
|
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
expect(email_digest.pending_notifications?).not_to be
|
expect(email_digest.pending_notifications?).not_to be
|
||||||
@@ -70,8 +65,7 @@ describe EmailDigest do
|
|||||||
it "delivers email if notifications pending" do
|
it "delivers email if notifications pending" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
proposal_notification = create(:proposal_notification)
|
notification = create(:notification, :for_proposal_notification, user: user)
|
||||||
notification = create(:notification, notifiable: proposal_notification, user: user)
|
|
||||||
|
|
||||||
reset_mailer
|
reset_mailer
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
@@ -84,8 +78,7 @@ describe EmailDigest do
|
|||||||
it "does not deliver email if no notifications pending" do
|
it "does not deliver email if no notifications pending" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
proposal_notification = create(:proposal_notification)
|
create(:notification, :for_proposal_notification, user: user, emailed_at: Time.current)
|
||||||
create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.current)
|
|
||||||
|
|
||||||
reset_mailer
|
reset_mailer
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user