diff --git a/app/views/notifications/_notification.html.erb b/app/views/notifications/_notification.html.erb
index 99b4b7def..29bf00823 100644
--- a/app/views/notifications/_notification.html.erb
+++ b/app/views/notifications/_notification.html.erb
@@ -1,13 +1,21 @@
- <%= link_to notification do %>
-
-
- <%= t("notifications.index.#{notification.notifiable_action}",
- count: notification.counter) %>
-
- <%= notification.notifiable_title %>
-
+ <% if notification.notifiable.present? %>
+ <%= link_to notification do %>
+
+
+ <%= t("notifications.index.#{notification.notifiable_action}",
+ count: notification.counter) %>
+
+ <%= notification.notifiable_title %>
+
- <%= l notification.timestamp, format: :datetime %>
+ <%= l notification.timestamp, format: :datetime %>
+ <% end %>
+ <% else %>
+
+
+ <%= t("notifications.index.notifiable_hidden") %>
+
+
<% end %>
\ No newline at end of file
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index 6e87e6983..9d1ad1560 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -264,6 +264,7 @@ en:
one: Someone commented on
other: There are %{count} new comments on
empty_notifications: You don't have new notifications.
+ notifiable_hidden: This resource is not available anymore.
mark_all_as_read: Mark all as read
proposal_notification:
one: There is one new notification on
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 0d0b4b849..a90d6837e 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -264,6 +264,7 @@ es:
one: Hay un nuevo comentario en
other: Hay %{count} comentarios nuevos en
empty_notifications: No tienes notificaciones nuevas.
+ notifiable_hidden: Este elemento ya no está disponible.
mark_all_as_read: Marcar todas como leídas
proposal_notification:
one: Hay una nueva notificación en
diff --git a/spec/controllers/installation_controller_spec.rb b/spec/controllers/installation_controller_spec.rb
index 68c2e7c07..7cb9a3af1 100644
--- a/spec/controllers/installation_controller_spec.rb
+++ b/spec/controllers/installation_controller_spec.rb
@@ -8,6 +8,7 @@ describe InstallationController, type: :request do
'debates' => nil,
'spending_proposals' => 't',
'polls' => nil,
+ 'proposals' => 't',
'twitter_login' => nil,
'facebook_login' => nil,
'google_login' => nil,
diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb
index fee0da813..01c6ec934 100644
--- a/spec/features/notifications_spec.rb
+++ b/spec/features/notifications_spec.rb
@@ -298,7 +298,6 @@ feature "Notifications" do
end
pending "group notifications for the same proposal"
-
end
context "mark as read" do
@@ -334,6 +333,19 @@ feature "Notifications" do
end
+ scenario "Notifiable hidden", :js do
+ create(:notification, notifiable: debate, user: author)
+ debate.hide
+
+ login_as author
+ visit root_path
+ find(".icon-notification").click
+
+ expect(page).to have_css ".notification", count: 1
+ expect(page).to have_content "This resource is not available anymore"
+ expect(page).to_not have_xpath "//a[@href='#{notification_path(Notification.last)}']"
+ end
+
scenario "no notifications" do
login_as user
visit notifications_path
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
index fcf7cab4b..12d315421 100644
--- a/spec/models/notification_spec.rb
+++ b/spec/models/notification_spec.rb
@@ -48,33 +48,51 @@ describe Notification do
end
describe "#notification_action" do
+ it "returns correct text when someone comments on your commentable" do
+ debate = create(:debate)
+ notification = create(:notification, notifiable: debate)
- context "when action was comment on a debate" do
- it "returns correct text when someone comments on your debate" do
- debate = create(:debate)
- notification = create :notification, notifiable: debate
-
- expect(notification.notifiable_action).to eq "comments_on"
- end
+ expect(notification.notifiable_action).to eq "comments_on"
end
- context "when action was comment on a debate" do
- it "returns correct text when someone replies to your comment" do
- debate = create(:debate)
- debate_comment = create :comment, commentable: debate
- notification = create :notification, notifiable: debate_comment
+ it "returns correct text when someone replies to your comment" do
+ debate = create(:debate)
+ debate_comment = create(:comment, commentable: debate)
+ notification = create(:notification, notifiable: debate_comment)
- expect(notification.notifiable_action).to eq "replies_to"
- end
+ expect(notification.notifiable_action).to eq "replies_to"
end
- context "when action was proposal notification" do
- it "returns correct text when the author created a proposal notification" do
- proposal_notification = create(:proposal_notification)
- notification = create :notification, notifiable: proposal_notification
+ it "returns correct text when the author created a proposal notification" do
+ proposal_notification = create(:proposal_notification)
+ notification = create(:notification, notifiable: proposal_notification)
- expect(notification.notifiable_action).to eq "proposal_notification"
- end
+ expect(notification.notifiable_action).to eq "proposal_notification"
+ end
+ end
+
+ describe "#notification_title" do
+ it "returns the commentable title when it's a root comment" do
+ debate = create(:debate, title: "Save the whales")
+ notification = create(:notification, notifiable: debate)
+
+ expect(notification.notifiable_title).to eq "Save the whales"
+ end
+
+ it "returns the commentable title when it's a reply to a root comment" do
+ debate = create(:debate, title: "Save the whales")
+ debate_comment = create(:comment, commentable: debate)
+ notification = create(:notification, notifiable: debate_comment)
+
+ expect(notification.notifiable_title).to eq "Save the whales"
+ end
+
+ it "returns the commentable title when it's an author's proposals notification" do
+ proposal = create(:proposal, title: "Save the whales")
+ proposal_notification = create(:proposal_notification, proposal: proposal)
+ notification = create(:notification, notifiable: proposal_notification)
+
+ expect(notification.notifiable_title).to eq "Save the whales"
end
end