Commit 36fd43db authored by Steven Fuchs's avatar Steven Fuchs

incorporated improvements from @maxwell from last pull request.

parent aae5fe04
......@@ -11,8 +11,8 @@ 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.set_read_state(opts[:set_unread] != "true" )
{ :guid => note.id, :unread => note.unread }
else
Response.new :status => 404
end
......
......@@ -36,6 +36,9 @@ class Notification < ActiveRecord::Base
self.recipient.mail(self.mail_job, self.recipient_id, actor.id, target.id)
end
def set_read_state( read_state )
self.update_attributes( :unread => !read_state )
end
def mail_job
raise NotImplementedError.new('Subclass this.')
......
......@@ -14,10 +14,24 @@ describe NotificationsController do
end
describe '#update' do
it 'marks a notification as read' do
note = Factory(:notification, :recipient => @user)
it 'marks a notification as read if it gets no other information' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true )
@controller.update :id => note.id
Notification.first.unread.should == false
end
it 'marks a notification as read if it is told to' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true )
@controller.update :id => note.id, :set_unread => "false"
end
it 'marks a notification as unread if it is told to' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( false )
@controller.update :id => note.id, :set_unread => "true"
end
it 'only lets you read your own notifications' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment