incorporated improvements from @maxwell from last pull request.
This commit is contained in:
parent
aae5fe04ce
commit
36fd43db4c
3 changed files with 22 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue