From f2be6e8bcfa2b0abd7a0f2b0029d2455ef8c3860 Mon Sep 17 00:00:00 2001 From: Steven Fuchs Date: Thu, 22 Dec 2011 15:20:48 -0500 Subject: [PATCH] controller can accept a parameter as to whether the notification should be marked as read or unread --- app/controllers/notifications_controller.rb | 2 +- spec/controllers/notifications_controller_spec.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c27df96c7..22ac5fa5f 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -11,7 +11,7 @@ class NotificationsController < VannaController def update(opts=params) note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first if note - note.update_attributes(:unread => false) + note.update_attributes(:unread => opts[:is_unread] || false ) {} else Response.new :status => 404 diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 3f1e64b1f..baf59f870 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -14,11 +14,21 @@ describe NotificationsController do end describe '#update' do - it 'marks a notification as read' do + it 'marks a notification as read if it gets no other information' do note = Factory(:notification, :recipient => @user) @controller.update :id => note.id Notification.first.unread.should == false end + it 'marks a notification as read if it is told to' do + note = Factory(:notification, :recipient => @user) + @controller.update :id => note.id, :is_unread => false + Notification.first.unread.should == false + end + it 'marks a notification as unread if it is told to' do + note = Factory(:notification, :recipient => @user) + @controller.update :id => note.id, :is_unread => true + Notification.first.unread.should == true + end it 'only lets you read your own notifications' do user2 = bob