Show unread notifications as bold

The view here isn't as DRY as we'd like, but all the options were kind
of ugly, and this one was easiest.
This commit is contained in:
Skud
2013-02-22 16:37:23 +11:00
parent cdee808933
commit d3d0ff42b2
3 changed files with 30 additions and 4 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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