diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index f45453fcd..8b300f85c 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -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 diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 127c87bb5..b3000594e 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -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) diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index c2e0ac708..f9d60ffb3 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -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) diff --git a/spec/lib/email_digests_spec.rb b/spec/lib/email_digests_spec.rb index af70ede35..15c9d743e 100644 --- a/spec/lib/email_digests_spec.rb +++ b/spec/lib/email_digests_spec.rb @@ -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)