From 126252d47aa1538a7fc4abefde8723a68fb9f567 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Thu, 19 Jun 2014 00:19:11 +0200 Subject: [PATCH] Add test for mention notifications --- app/controllers/posts_controller.rb | 2 +- spec/controllers/posts_controller_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d2464bf60..2f14fb638 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -91,7 +91,7 @@ class PostsController < ApplicationController end # For mentions - mention = @post.mentions.where(person_id: current_user.id).first + mention = @post.mentions.where(person_id: current_user.person_id).first Notification.where(recipient_id: current_user.id, target_type: "Mention", target_id: mention.id, unread: true).first.try(:set_read_state, true) if mention end end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 581cef719..fb1145f62 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -50,6 +50,17 @@ describe PostsController do }.to change(Notification.where(:unread => true), :count).by(-2) end + it 'marks a corresponding mention notification as read' do + status_msg = bob.post(:status_message, {text: "this is a text mentioning @{Mention User ; #{alice.diaspora_handle}} ... have fun testing!", :public => true, :to => 'all'}) + mention = status_msg.mentions.where(person_id: alice.person.id).first + note = FactoryGirl.create(:notification, :recipient => alice, :target_type => "Mention", :target_id => mention.id, :unread => true) + + expect { + get :show, :id => status_msg.id + note.reload + }.to change(Notification.where(:unread => true), :count).by(-1) + end + it '404 if the post is missing' do expect { get :show, :id => 1234567