diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 0dbeac2e8..0c37bf28c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -15,6 +15,8 @@ class NotificationsController < ApplicationController # GET /notifications/1.json def show @notification = Notification.find(params[:id]) + @notification.read = true + @notification.save respond_to do |format| format.html # show.html.erb diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 3d5e2dd1e..bb365e90d 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -11,9 +11,25 @@ - @notifications.each do |n| - if can? :read, n %tr - %td= link_to n.sender - %td= link_to n.subject, notification_path(n) - %td= n.created_at.to_s(:date) - %td= link_to 'Delete', n, method: :delete, data: { confirm: 'Are you sure?' } + %td + - if n.read + = link_to n.sender + - else + %strong= link_to n.sender + %td + - if n.read + = link_to n.subject, notification_path(n) + - else + %strong= link_to n.subject, notification_path(n) + %td + - if n.read + = n.created_at.to_s(:date) + - else + %strong= n.created_at.to_s(:date) + %td + - if n.read + = link_to 'Delete', n, method: :delete, data: { confirm: 'Are you sure?' } + - else + %strong= link_to 'Delete', n, method: :delete, data: { confirm: 'Are you sure?' } - else You have no messages. diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index b62dfad83..939ddb443 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -26,6 +26,14 @@ describe NotificationsController do get :show, {:id => notification.to_param} assigns(:notification).should eq(notification) end + + it "marks notifications as read" do + notification = Notification.create! valid_attributes + get :show, {:id => notification.to_param} + # we need to fetch it from the db again, can't test against the old one + n = Notification.find(notification.id) + n.read.should eq true + end end describe "DELETE destroy" do