From 6057e17ae70b10980bf82bd8576db9b4ed6dde23 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 20 Mar 2017 12:06:37 +0800 Subject: [PATCH] Fix weird test failure. --- app/models/notification.rb | 5 ++++- spec/models/notification_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index d8ca8553df2..96e3e43f9e5 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -13,7 +13,10 @@ class Notification < ActiveRecord::Base .where('topics.id IS NULL OR topics.deleted_at IS NULL') } after_commit :send_email - after_commit :refresh_notification_count + # This is super weird because the tests fail if we don't specify `on: :destroy` + # TODO: Revert back to default in Rails 5 + after_commit :refresh_notification_count, on: :destroy + after_commit :refresh_notification_count, on: [:create, :update] def self.ensure_consistency! Notification.exec_sql(" diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 02ee99917c7..fa45deb0e74 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -133,7 +133,7 @@ describe Notification do it 'updates the notification count on destroy' do Notification.any_instance.expects(:refresh_notification_count).returns(nil) - notification.destroy + notification.destroy! end end