From cca0896b9e4a278043d024c557a0b3327e9e34e6 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 16 Dec 2015 23:44:52 +0800 Subject: [PATCH] FIX: Update all does not trigger callbacks. --- app/models/notification.rb | 1 + spec/models/notification_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index bde2937907a..d37c9d1215c 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -36,6 +36,7 @@ class Notification < ActiveRecord::Base def self.mark_posts_read(user, topic_id, post_numbers) Notification.where(user_id: user.id, topic_id: topic_id, post_number: post_numbers, read: false).update_all "read = 't'" + user.publish_notifications_state end def self.interesting_after(min_date) diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 2792068d61b..eef253c2c6a 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -222,7 +222,7 @@ describe Notification do end Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '{}', notification_type: 1) - expect(Notification.mark_posts_read(user,2,[1,2,3,4])).to eq(3) + expect { Notification.mark_posts_read(user,2,[1,2,3,4]) }.to change { Notification.where(read: true).count }.by(3) end end