Simplify creating notifications in specs
This commit is contained in:
@@ -6,6 +6,18 @@ FactoryBot.define do
|
||||
trait :read do
|
||||
read_at { Time.current }
|
||||
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
|
||||
|
||||
factory :admin_notification do
|
||||
|
||||
@@ -303,13 +303,11 @@ describe "Emails" do
|
||||
|
||||
scenario "notifications moderated are not sent" do
|
||||
user = create(:user, email_digest: true)
|
||||
proposal = create(:proposal)
|
||||
proposal_notification = create(:proposal_notification, proposal: proposal)
|
||||
notification = create(:notification, notifiable: proposal_notification)
|
||||
notification = create(:notification, :for_proposal_notification)
|
||||
|
||||
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.deliver(Time.current)
|
||||
|
||||
@@ -128,7 +128,7 @@ describe "Notifications" do
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user