From e3c8dece8f02d7150d8c203f32d8b8f6614c2243 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 11 Dec 2017 13:13:13 +0100 Subject: [PATCH 1/4] Makes the code aware of notifications for hidden commentables --- .../notifications/_notification.html.erb | 34 ++++++++++++------- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + spec/features/notifications_spec.rb | 14 +++++++- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/views/notifications/_notification.html.erb b/app/views/notifications/_notification.html.erb index 99b4b7def..449edabae 100644 --- a/app/views/notifications/_notification.html.erb +++ b/app/views/notifications/_notification.html.erb @@ -1,13 +1,23 @@ -
  • - <%= 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 %>

    - <% end %> -
  • \ No newline at end of file +

    <%= 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/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 From 8c85611ec9ea95749a7609516210c7b3385cca03 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 11 Dec 2017 13:13:30 +0100 Subject: [PATCH 2/4] Adds missing specs for notification titles --- spec/models/notification_spec.rb | 58 +++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 20 deletions(-) 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 From c63c734ec28d1ccbdb92c4c786a7868f380f3627 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Dec 2017 11:04:05 +0100 Subject: [PATCH 3/4] fixes specs --- spec/controllers/installation_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) 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, From 7465a8ef8e9bef6d1e22f085bf6dbf4b752cbb30 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Dec 2017 13:36:38 +0100 Subject: [PATCH 4/4] Refactors li element --- app/views/notifications/_notification.html.erb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/views/notifications/_notification.html.erb b/app/views/notifications/_notification.html.erb index 449edabae..29bf00823 100644 --- a/app/views/notifications/_notification.html.erb +++ b/app/views/notifications/_notification.html.erb @@ -1,5 +1,5 @@ -<% if notification.notifiable.present? %> -
  • +
  • + <% if notification.notifiable.present? %> <%= link_to notification do %>

    @@ -11,13 +11,11 @@

    <%= l notification.timestamp, format: :datetime %>

    <% end %> -
  • -<% else %> -
  • + <% else %>

    <%= t("notifications.index.notifiable_hidden") %>

    -
  • -<% end %> \ No newline at end of file + <% end %> + \ No newline at end of file