diff --git a/app/controllers/proposal_notifications_controller.rb b/app/controllers/proposal_notifications_controller.rb
index bd83c941c..fe6add7e2 100644
--- a/app/controllers/proposal_notifications_controller.rb
+++ b/app/controllers/proposal_notifications_controller.rb
@@ -10,6 +10,9 @@ class ProposalNotificationsController < ApplicationController
@notification = ProposalNotification.new(notification_params)
@proposal = Proposal.find(notification_params[:proposal_id])
if @notification.save
+ @proposal.voters.each do |voter|
+ Mailer.proposal_notification(@notification, voter).deliver_later
+ end
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
else
render :new
diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb
index 82abbb205..b8ca433ce 100644
--- a/app/mailers/mailer.rb
+++ b/app/mailers/mailer.rb
@@ -42,6 +42,14 @@ class Mailer < ApplicationMailer
end
end
+ def proposal_notification(notification, voter)
+ @notification = notification
+
+ with_user(voter) do
+ mail(to: voter.email, subject: @notification.title)
+ end
+ end
+
private
def with_user(user, &block)
diff --git a/app/models/proposal.rb b/app/models/proposal.rb
index d2b97f1c5..f9ef60303 100644
--- a/app/models/proposal.rb
+++ b/app/models/proposal.rb
@@ -97,6 +97,10 @@ class Proposal < ActiveRecord::Base
cached_votes_up + physical_votes
end
+ def voters
+ votes_for.voters
+ end
+
def editable?
total_votes <= Setting["max_votes_for_proposal_edit"].to_i
end
diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb
new file mode 100644
index 000000000..30e8d8bc6
--- /dev/null
+++ b/app/views/mailer/proposal_notification.html.erb
@@ -0,0 +1,2 @@
+
<%= @notification.proposal.title %>
+<%= @notification.body %>
diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb
index c6f0d3708..81e6560ff 100644
--- a/spec/features/emails_spec.rb
+++ b/spec/features/emails_spec.rb
@@ -148,4 +148,40 @@ feature 'Emails' do
expect(email).to have_body_text(spending_proposal.feasible_explanation)
end
+ scenario "Proposal notification" do
+ author = create(:user)
+
+ noelia = create(:user)
+ vega = create(:user)
+ cristina = create(:user)
+
+ proposal = create(:proposal, author: author)
+
+ create(:vote, voter: noelia, votable: proposal, vote_flag: true)
+ create(:vote, voter: vega, votable: proposal, vote_flag: true)
+
+ reset_mailer
+
+ login_as(author)
+ visit root_path
+
+ visit new_proposal_notification_path(proposal_id: proposal.id)
+
+ fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
+ fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
+ click_button "Send"
+
+ expect(page).to have_content "Your message has been sent correctly."
+
+ expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1)
+ expect(unread_emails_for(vega.email).size).to eql parse_email_count(1)
+ expect(unread_emails_for(cristina.email).size).to eql parse_email_count(0)
+ expect(unread_emails_for(author.email).size).to eql parse_email_count(0)
+
+ email = open_last_email
+ expect(email).to have_subject("Thank you for supporting my proposal")
+ expect(email).to have_body_text("Please share it with others so we can make it happen!")
+ expect(email).to have_body_text(proposal.title)
+ end
+
end
diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb
index d10beb6f4..b014aa162 100644
--- a/spec/features/proposal_notifications_spec.rb
+++ b/spec/features/proposal_notifications_spec.rb
@@ -3,9 +3,6 @@ require 'rails_helper'
feature 'Proposal Notifications' do
scenario "Send a notification" do
- noelia = create(:user)
- vega = create(:user)
-
author = create(:user)
proposal = create(:proposal, author: author)