adds notifications for proposals
This commit is contained in:
@@ -9,7 +9,7 @@ class NotificationsController < ApplicationController
|
||||
|
||||
def show
|
||||
@notification = current_user.notifications.find(params[:id])
|
||||
redirect_to url_for(@notification.notifiable)
|
||||
redirect_to url_for(@notification.linkable_resource)
|
||||
end
|
||||
|
||||
def mark_all_as_read
|
||||
|
||||
@@ -11,6 +11,7 @@ class ProposalNotificationsController < ApplicationController
|
||||
@proposal = Proposal.find(notification_params[:proposal_id])
|
||||
if @notification.save
|
||||
@proposal.voters.each do |voter|
|
||||
Notification.add(voter.id, @notification)
|
||||
if voter.email_on_proposal_notification?
|
||||
Mailer.proposal_notification(@notification, voter).deliver_later
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
module NotificationsHelper
|
||||
|
||||
def notification_action(notification)
|
||||
notification.notifiable_type == "Comment" ? "replies_to" : "comments_on"
|
||||
case notification.notifiable_type
|
||||
when "ProposalNotification"
|
||||
"proposal_notification"
|
||||
when "Comment"
|
||||
"replies_to"
|
||||
else
|
||||
"comments_on"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,4 +21,19 @@ class Notification < ActiveRecord::Base
|
||||
Notification.create!(user_id: user_id, notifiable: notifiable)
|
||||
end
|
||||
end
|
||||
|
||||
def notifiable_title
|
||||
case notifiable.class.name
|
||||
when "ProposalNotification"
|
||||
notifiable.proposal.title
|
||||
when "Comment"
|
||||
notifiable.commentable.title
|
||||
else
|
||||
notifiable.title
|
||||
end
|
||||
end
|
||||
|
||||
def linkable_resource
|
||||
notifiable.is_a?(ProposalNotification) ? notifiable.proposal : notifiable
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,13 @@
|
||||
<li id="<%= dom_id(notification) %>" class="notification">
|
||||
<%= link_to notification do %>
|
||||
<p>
|
||||
<em><%= t("notifications.index.#{notification_action(notification)}", count: notification.counter) %></em>
|
||||
<strong><%= notification.notifiable.is_a?(Comment) ? notification.notifiable.commentable.title : notification.notifiable.title %></strong>
|
||||
<em>
|
||||
<%= t("notifications.index.#{notification_action(notification)}",
|
||||
count: notification.counter) %>
|
||||
</em>
|
||||
<strong><%= notification.notifiable_title %></strong>
|
||||
</p>
|
||||
|
||||
<p class="time"><%= l notification.timestamp, format: :datetime %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
@@ -223,6 +223,9 @@ en:
|
||||
other: There are %{count} new comments on
|
||||
empty_notifications: You don't have new notifications.
|
||||
mark_all_as_read: Mark all as read
|
||||
proposal_notification:
|
||||
one: There is one new notification on
|
||||
other: There are %{count} new notifications on
|
||||
replies_to:
|
||||
one: Someone replied to your comment on
|
||||
other: There are %{count} new replies to your comment on
|
||||
|
||||
@@ -223,6 +223,9 @@ es:
|
||||
other: Hay %{count} comentarios nuevos en
|
||||
empty_notifications: No tienes notificaciones nuevas.
|
||||
mark_all_as_read: Marcar todas como leídas
|
||||
proposal_notification:
|
||||
one: Hay una nueva notificación en
|
||||
other: Hay %{count} nuevas notificaciones en
|
||||
replies_to:
|
||||
one: Hay una respuesta nueva a tu comentario en
|
||||
other: Hay %{count} nuevas respuestas a tu comentario en
|
||||
|
||||
@@ -149,6 +149,64 @@ feature "Notifications" do
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
context "Proposal notification" do
|
||||
|
||||
scenario "Voters should receive a notification", :js do
|
||||
author = create(:user)
|
||||
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
user3 = create(:user)
|
||||
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
create(:vote, voter: user1, votable: proposal, vote_flag: true)
|
||||
create(:vote, voter: user2, votable: proposal, vote_flag: true)
|
||||
|
||||
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 message"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
|
||||
logout
|
||||
login_as user1
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
|
||||
|
||||
logout
|
||||
login_as user2
|
||||
visit root_path
|
||||
|
||||
find(".icon-notification").click
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "There is one new notification on #{proposal.title}"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.first)}']"
|
||||
|
||||
logout
|
||||
login_as user3
|
||||
visit root_path
|
||||
|
||||
find(".icon-no-notification").click
|
||||
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
pending "group notifications for the same proposal"
|
||||
|
||||
end
|
||||
|
||||
context "mark as read" do
|
||||
|
||||
scenario "mark a single notification as read" do
|
||||
|
||||
Reference in New Issue
Block a user