mark notification as read on the status message show page

This commit is contained in:
zhitomirskiyi 2011-01-31 15:26:20 -08:00
parent 7a667abc73
commit a6c1b5bf59
3 changed files with 24 additions and 7 deletions

View file

@ -73,9 +73,14 @@ class StatusMessagesController < ApplicationController
def show def show
@status_message = current_user.find_visible_post_by_id params[:id] @status_message = current_user.find_visible_post_by_id params[:id]
@object_aspect_ids = @status_message.aspects.map{|a| a.id} @object_aspect_ids = @status_message.aspects.map{|a| a.id}
# mark corresponding notification as read
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
notification.unread = false
notification.save
end
respond_with @status_message respond_with @status_message
end end

View file

@ -35,7 +35,6 @@ describe StatisticsController do
end end
end end
describe '#redirect_unauthorized' do describe '#redirect_unauthorized' do
it 'redirects for non admins' do it 'redirects for non admins' do
AppConfig[:admins] = ['bob'] AppConfig[:admins] = ['bob']

View file

@ -21,15 +21,28 @@ describe StatusMessagesController do
end end
describe '#show' do describe '#show' do
it 'succeeds' do before do
message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id @message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id
message.save! @message.save!
@user1.add_to_streams(message, [@aspect1])
@user1.dispatch_post message, :to => @aspect1.id
@user1.add_to_streams(@message, [@aspect1])
@user1.dispatch_post @message, :to => @aspect1.id
end
it 'succeeds' do
get :show, "id" => message.id.to_s get :show, "id" => message.id.to_s
response.should be_success response.should be_success
end end
it 'marks a corresponding notification as read' do
alice.comment("comment after me", :on => @message)
bob.comment("here you go", :on => @message)
note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first
lambda{
get :show, :id => @message.id
note.reload
}.should change(note, :unread).from(true).to(false)
end
end end
describe '#create' do describe '#create' do