diff --git a/app/components/layout/notification_item_component.rb b/app/components/layout/notification_item_component.rb index 4c23a2a4a..c63205f12 100644 --- a/app/components/layout/notification_item_component.rb +++ b/app/components/layout/notification_item_component.rb @@ -9,7 +9,7 @@ class Layout::NotificationItemComponent < ApplicationComponent def text if unread_notifications? - t("layouts.header.notification_item.new_notifications", count: user.notifications_count) + t("layouts.header.notification_item.new_notifications", count: unread_notifications.count) else t("layouts.header.notification_item.no_notifications") end @@ -24,6 +24,10 @@ class Layout::NotificationItemComponent < ApplicationComponent end def unread_notifications? - user.notifications.unread.count > 0 + unread_notifications.count > 0 + end + + def unread_notifications + user.notifications.unread end end diff --git a/spec/shared/system/notifiable_in_app.rb b/spec/shared/system/notifiable_in_app.rb index 08e30299d..048eb81f0 100644 --- a/spec/shared/system/notifiable_in_app.rb +++ b/spec/shared/system/notifiable_in_app.rb @@ -2,6 +2,8 @@ shared_examples "notifiable in-app" do |factory_name| let(:author) { create(:user, :verified) } let!(:notifiable) { create(factory_name, author: author) } + before { create(:notification, :read, notifiable: notifiable, user: author) } + scenario "Notification message is shown" do create(:notification, notifiable: notifiable, user: author) diff --git a/spec/system/proposal_notifications_spec.rb b/spec/system/proposal_notifications_spec.rb index 15f384763..998dd1223 100644 --- a/spec/system/proposal_notifications_spec.rb +++ b/spec/system/proposal_notifications_spec.rb @@ -198,7 +198,7 @@ describe "Proposal Notifications" do login_as user1 visit root_path - find(".unread-notifications").click + click_link "You have a new notification" expect(page).to have_css ".notification", count: 1 @@ -210,7 +210,7 @@ describe "Proposal Notifications" do login_as user2 visit root_path - find(".unread-notifications").click + click_link "You have a new notification" expect(page).to have_css ".notification", count: 1 @@ -303,7 +303,7 @@ describe "Proposal Notifications" do login_as user visit root_path - find(".unread-notifications").click + click_link "You have a new notification" expect(page).to have_css ".notification", count: 1 expect(page).to have_content "This resource is not available anymore"