diff --git a/app/models/topic.rb b/app/models/topic.rb index 4982259baea..4bd6180d515 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -474,6 +474,8 @@ class Topic < ActiveRecord::Base Category.where(id: new_category.id).update_all("topic_count = topic_count + 1") CategoryFeaturedTopic.feature_topics_for(old_category) unless @import_mode CategoryFeaturedTopic.feature_topics_for(new_category) unless @import_mode || old_category.id == new_category.id + CategoryUser.auto_watch_new_topic(self) + CategoryUser.auto_track_new_topic(self) end true diff --git a/spec/models/category_user_spec.rb b/spec/models/category_user_spec.rb index fdb4ed9af9b..f6ceb862126 100644 --- a/spec/models/category_user_spec.rb +++ b/spec/models/category_user_spec.rb @@ -49,7 +49,20 @@ describe CategoryUser do tu = TopicUser.get(tracked_post.topic, user) expect(tu.notification_level).to eq TopicUser.notification_levels[:tracking] expect(tu.notifications_reason_id).to eq TopicUser.notification_reasons[:auto_track_category] + end + it "watches categories that have been changed" do + watched_category = Fabricate(:category) + user = Fabricate(:user) + CategoryUser.create!(user: user, category: watched_category, notification_level: CategoryUser.notification_levels[:watching]) + + post = create_post + TopicUser.get(post.topic, user).should be_blank + + # Now, change the topic's category + post.topic.change_category_to_id(watched_category.id) + tu = TopicUser.get(post.topic, user) + expect(tu.notification_level).to eq TopicUser.notification_levels[:watching] end end