SPEC: make sure digest doesn't pick any topics in categories that are muted

This commit is contained in:
Régis Hanol 2014-11-03 16:57:50 +01:00
parent a7fa1b33e5
commit fd5677808c
4 changed files with 34 additions and 32 deletions

View file

@ -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,

View file

@ -16,16 +16,14 @@ class CategoryUser < ActiveRecord::Base
end
def self.auto_track_new_topic(topic)
apply_default_to_topic(
topic,
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,
apply_default_to_topic(topic,
TopicUser.notification_levels[:watching],
TopicUser.notification_reasons[:auto_watch_category]
)
@ -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,22 +58,20 @@ 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 = <<SQL
sql = <<-SQL
INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
SELECT user_id, :topic_id, :level, :reason
FROM category_users
WHERE notification_level = :level AND
category_id = :category_id AND
NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = :topic_id AND user_id = category_users.user_id)
WHERE notification_level = :level
AND category_id = :category_id
AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = :topic_id AND user_id = category_users.user_id)
SQL
exec_sql(
sql,
exec_sql(sql,
topic_id: topic.id,
category_id: topic.category_id,
level: level,
reason: reason
)
end

View file

@ -1181,6 +1181,16 @@ describe Topic do
Topic.for_digest(user, 1.year.ago, top_order: true).should == [topic]
end
it "doesn't return topics from muted categories" do
user = Fabricate(:user)
category = Fabricate(:category)
topic = Fabricate(:topic, category: category)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
Topic.for_digest(user, 1.year.ago, top_order: true).should be_blank
end
end
describe 'secured' do