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)
|
def update(opts=params)
|
||||||
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
|
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
|
||||||
if note
|
if note
|
||||||
note.update_attributes(:unread => false)
|
note.set_read_state(opts[:set_unread] != "true" )
|
||||||
{}
|
{ :guid => note.id, :unread => note.unread }
|
||||||
else
|
else
|
||||||
Response.new :status => 404
|
Response.new :status => 404
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ class Notification < ActiveRecord::Base
|
||||||
self.recipient.mail(self.mail_job, self.recipient_id, actor.id, target.id)
|
self.recipient.mail(self.mail_job, self.recipient_id, actor.id, target.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_read_state( read_state )
|
||||||
|
self.update_attributes( :unread => !read_state )
|
||||||
|
end
|
||||||
|
|
||||||
def mail_job
|
def mail_job
|
||||||
raise NotImplementedError.new('Subclass this.')
|
raise NotImplementedError.new('Subclass this.')
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,24 @@ describe NotificationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#update' do
|
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)
|
note = mock_model( Notification )
|
||||||
|
Notification.should_receive( :where ).and_return( [note] )
|
||||||
|
note.should_receive( :set_read_state ).with( true )
|
||||||
@controller.update :id => note.id
|
@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
|
end
|
||||||
|
|
||||||
it 'only lets you read your own notifications' do
|
it 'only lets you read your own notifications' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue