From 0979e7b9af360d508d0a2405450c9d037409f439 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 2 Jun 2014 13:55:01 +1000 Subject: [PATCH] BUGFIX: tracking categories was not implemented --- app/models/category_user.rb | 8 ++++++++ app/models/topic_user.rb | 3 ++- config/locales/client.en.yml | 1 + lib/topic_creator.rb | 1 + spec/models/category_user_spec.rb | 9 +++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/category_user.rb b/app/models/category_user.rb index e445c2cce..914a0c8e5 100644 --- a/app/models/category_user.rb +++ b/app/models/category_user.rb @@ -15,6 +15,14 @@ class CategoryUser < ActiveRecord::Base TopicUser.notification_levels end + def self.auto_track_new_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, diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index 15f18b1fc..36d47f771 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -27,7 +27,8 @@ class TopicUser < ActiveRecord::Base :created_post, :auto_watch, :auto_watch_category, - :auto_mute_category + :auto_mute_category, + :auto_track_category ) end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ac7f0ed9f..410aaf2c9 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -781,6 +781,7 @@ en: "3_2": 'You will receive notifications because you are watching this topic.' "3_1": 'You will receive notifications because you created this topic.' "3": 'You will receive notifications because you are watching this topic.' + "2_8": 'You will receive notifications because you are tracking this category.' "2_4": 'You will receive notifications because you posted a reply to this topic.' "2_2": 'You will receive notifications because you are tracking this topic.' "2": 'You will receive notifications because you read this topic.' diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index b361bbc36..fe17b6daf 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -40,6 +40,7 @@ class TopicCreator end CategoryUser.auto_watch_new_topic(@topic) + CategoryUser.auto_track_new_topic(@topic) end def setup_topic_params diff --git a/spec/models/category_user_spec.rb b/spec/models/category_user_spec.rb index ab64fcaba..62a7e9f14 100644 --- a/spec/models/category_user_spec.rb +++ b/spec/models/category_user_spec.rb @@ -31,15 +31,24 @@ describe CategoryUser do it 'should operate correctly' do watched_category = Fabricate(:category) muted_category = Fabricate(:category) + tracked_category = Fabricate(:category) + user = Fabricate(:user) CategoryUser.create!(user: user, category: watched_category, notification_level: CategoryUser.notification_levels[:watching]) CategoryUser.create!(user: user, category: muted_category, notification_level: CategoryUser.notification_levels[:muted]) + CategoryUser.create!(user: user, category: tracked_category, notification_level: CategoryUser.notification_levels[:tracking]) watched_post = create_post(category: watched_category) muted_post = create_post(category: muted_category) + tracked_post = create_post(category: tracked_category) Notification.where(user_id: user.id, topic_id: watched_post.topic_id).count.should == 1 + Notification.where(user_id: user.id, topic_id: tracked_post.topic_id).count.should == 0 + + tu = TopicUser.get(tracked_post.topic, user) + tu.notification_level.should == TopicUser.notification_levels[:tracking] + tu.notifications_reason_id.should == TopicUser.notification_reasons[:auto_track_category] tu = TopicUser.get(muted_post.topic, user) tu.notification_level.should == TopicUser.notification_levels[:muted]