Skip to content

Commit

Permalink
Mostra contagem de notificações
Browse files Browse the repository at this point in the history
-Conta somente com status de não lida
-Ao clicar em notificações marca todas como lida

Co-authored-by: ana resgalla <[email protected]>
  • Loading branch information
hreis1 and anaresgalla committed Feb 12, 2024
1 parent 1cec192 commit 5778287
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class NotificationsController < ApplicationController

def index
@notifications = current_user.profile.notifications.order(created_at: :desc)
@notifications.update_all(read: true)
end
end
4 changes: 3 additions & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
</li>
<li class="dropdown-item">
<%= link_to notifications_path, class: 'nav-link' do %>
Notificações <span class="badge bg-primary"><%= current_user.profile.notifications.count %></span>
Notificações <span class="badge bg-primary">
<%= current_user.profile.notifications.where(read: false).count if current_user.profile.notifications.where(read: false).count > 0 %>
</span>
<% end %>
</li>
<% if current_user.admin? %>
Expand Down
13 changes: 13 additions & 0 deletions spec/system/notifications/user_sees_notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@
expect(page).to have_content 'Nenhuma notificação'
expect(Notification.count).to eq 0
end

it 'contagem de notificações muda ao ir para página de notificações' do
user = create(:user)
invitation = create(:invitation, profile: user.profile)

login_as user
visit notifications_path
click_button class: 'dropdown-toggle'

expect(page).not_to have_content 'Notificações 1'
expect(page).to have_content 'Notificações'
expect(user.profile.notifications.count).to eq 1
end
end

0 comments on commit 5778287

Please sign in to comment.