marcar notificaciones como leidas despues de ser vistas
This commit is contained in:
@@ -4,6 +4,7 @@ class NotificationsController < ApplicationController
|
||||
|
||||
def index
|
||||
@notifications = current_user.notifications.unread.recent.for_render
|
||||
@notifications.each { |notification| notification.mark_as_read! }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -9,4 +9,8 @@ class Notification < ActiveRecord::Base
|
||||
def timestamp
|
||||
activity.trackable.created_at
|
||||
end
|
||||
|
||||
def mark_as_read!
|
||||
update_attribute :read, true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,13 +4,18 @@ describe NotificationsController do
|
||||
|
||||
describe "#index" do
|
||||
let(:user) { create :user }
|
||||
let(:notification) { create :notification, user: user }
|
||||
|
||||
it "assigns @notifications" do
|
||||
it "mark all notifications as read" do
|
||||
notifications = [create(:notification, user: user), create(:notification, user: user)]
|
||||
Notification.all.each do |notification|
|
||||
expect(notification.read).to be false
|
||||
end
|
||||
|
||||
sign_in user
|
||||
|
||||
get :index, debate: { title: 'A sample debate', description: 'this is a sample debate', terms_of_service: 1 }
|
||||
expect(assigns(:notifications)).to eq user.notifications.unread.recent.for_render
|
||||
get :index
|
||||
Notification.all.each do |notification|
|
||||
expect(notification.read).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,4 +41,14 @@ describe Notification do
|
||||
expect(notification.timestamp).to eq comment.created_at
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mark_as_read" do
|
||||
it "set up read flag to true" do
|
||||
notification = create :notification
|
||||
expect(notification.read).to be false
|
||||
|
||||
notification.mark_as_read!
|
||||
expect(notification.read).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user