adds email digest for proposal notifications

This commit is contained in:
rgarcia
2016-06-14 17:53:36 +02:00
parent 0fba15b1e5
commit 6e800c5120
13 changed files with 199 additions and 38 deletions

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
feature 'Direct messages' do
scenario "Create", :focus do
scenario "Create" do
sender = create(:user, :level_two)
receiver = create(:user, :level_two)

View File

@@ -204,4 +204,51 @@ feature 'Emails' do
end
end
context "Proposal notification digest" do
scenario "notifications for proposals that I have supported" do
user = create(:user, email_digest: true)
proposal1 = create(:proposal)
proposal2 = create(:proposal)
proposal3 = create(:proposal)
create(:vote, votable: proposal1, voter: user)
create(:vote, votable: proposal2, voter: user)
reset_mailer
notification1 = create_proposal_notification(proposal1)
notification2 = create_proposal_notification(proposal2)
notification3 = create_proposal_notification(proposal3)
email_digest = EmailDigest.new
email_digest.create
email = open_last_email
expect(email).to have_subject("Email digest")
expect(email).to deliver_to(user.email)
expect(email).to have_body_text(proposal1.title)
expect(email).to have_body_text(notification1.notifiable.title)
expect(email).to have_body_text(notification1.notifiable.body)
expect(email).to have_body_text(proposal1.author.name)
expect(email).to have_body_text(/#{notification_path(notification1)}/)
expect(email).to have_body_text(/#{proposal_path(proposal1, anchor: 'comments')}/)
expect(email).to have_body_text(/#{proposal_path(proposal1, anchor: 'social-share')}/)
expect(email).to have_body_text(proposal2.title)
expect(email).to have_body_text(notification2.notifiable.title)
expect(email).to have_body_text(notification2.notifiable.body)
expect(email).to have_body_text(/#{notification_path(notification2)}/)
expect(email).to have_body_text(/#{proposal_path(proposal2, anchor: 'comments')}/)
expect(email).to have_body_text(/#{proposal_path(proposal2, anchor: 'social-share')}/)
expect(email).to have_body_text(proposal2.author.name)
expect(email).to_not have_body_text(proposal3.title)
end
end
end

View File

@@ -51,6 +51,53 @@ feature 'Proposal Notifications' do
expect(page).to have_link("the proposal's page", href: proposal_path(proposal))
end
context "Receivers" do
scenario "Only send a digest to users that have the option set in their profile" do
user1 = create(:user, email_digest: true)
user2 = create(:user, email_digest: true)
user3 = create(:user, email_digest: false)
proposal = create(:proposal)
[user1, user2, user3].each do |user|
create(:vote, votable: proposal, voter: user)
end
create_proposal_notification(proposal)
reset_mailer
email_digest = EmailDigest.new
email_digest.create
expect(unread_emails_for(user1.email).size).to eql parse_email_count(1)
expect(unread_emails_for(user2.email).size).to eql parse_email_count(1)
expect(unread_emails_for(user3.email).size).to eql parse_email_count(0)
end
scenario "Only send a digest to users that have voted for a proposal" do
user1 = create(:user, email_digest: true)
user2 = create(:user, email_digest: true)
user3 = create(:user, email_digest: true)
proposal = create(:proposal)
[user1, user2].each do |user|
create(:vote, votable: proposal, voter: user)
end
create_proposal_notification(proposal)
reset_mailer
email_digest = EmailDigest.new
email_digest.create
expect(unread_emails_for(user1.email).size).to eql parse_email_count(1)
expect(unread_emails_for(user2.email).size).to eql parse_email_count(1)
expect(unread_emails_for(user3.email).size).to eql parse_email_count(0)
end
end
context "Permissions" do
scenario "Link to send the message" do