From fd5677808cea3b4868c6bfe508eeea9a26ed49a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 3 Nov 2014 16:57:50 +0100 Subject: [PATCH] SPEC: make sure digest doesn't pick any topics in categories that are muted --- app/controllers/categories_controller.rb | 2 +- app/mailers/user_notifications.rb | 4 +- app/models/category_user.rb | 50 +++++++++++------------- spec/models/topic_spec.rb | 10 +++++ 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index f9b8b6454..c14464813 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -99,7 +99,7 @@ class CategoriesController < ApplicationController category_id = params[:category_id].to_i notification_level = params[:notification_level].to_i - CategoryUser.set_notification_level_for_category(current_user, notification_level , category_id) + CategoryUser.set_notification_level_for_category(current_user, notification_level, category_id) render json: success_json end diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index c76dbf2db..476a09039 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -250,9 +250,7 @@ class UserNotifications < ActionMailer::Base ) template = "user_notifications.user_#{notification_type}" - if post.topic.private_message? - template << "_pm" - end + template << "_pm" if post.topic.private_message? email_opts = { topic_title: title, diff --git a/app/models/category_user.rb b/app/models/category_user.rb index 4ba4a130d..d53fb804e 100644 --- a/app/models/category_user.rb +++ b/app/models/category_user.rb @@ -16,19 +16,17 @@ class CategoryUser < ActiveRecord::Base end def self.auto_track_new_topic(topic) - apply_default_to_topic( - topic, - TopicUser.notification_levels[:tracking], - TopicUser.notification_reasons[:auto_track_category] - ) + apply_default_to_topic(topic, + TopicUser.notification_levels[:tracking], + TopicUser.notification_reasons[:auto_track_category] + ) end def self.auto_watch_new_topic(topic) - apply_default_to_topic( - topic, - TopicUser.notification_levels[:watching], - TopicUser.notification_reasons[:auto_watch_category] - ) + apply_default_to_topic(topic, + TopicUser.notification_levels[:watching], + TopicUser.notification_reasons[:auto_watch_category] + ) end def self.batch_set(user, level, category_ids) @@ -49,8 +47,6 @@ class CategoryUser < ActiveRecord::Base def self.set_notification_level_for_category(user, level, category_id) record = CategoryUser.where(user: user, category_id: category_id).first - # oder CategoryUser.where(user: user, category_id: category_id).destroy_all - # und danach mir create anlegen. if record.present? record.notification_level = level @@ -62,23 +58,21 @@ class CategoryUser < ActiveRecord::Base def self.apply_default_to_topic(topic, level, reason) # Can not afford to slow down creation of topics when a pile of users are watching new topics, reverting to SQL for max perf here - sql = <