From e3ad50de0598b2e18a67d518fb70dfb7534aa14d Mon Sep 17 00:00:00 2001 From: cpradio Date: Fri, 14 Apr 2017 18:30:01 -0400 Subject: [PATCH] Add spec for auto notification update It should update the topic subscription so long as what is being requested is higher than what is currently set for the user and the given topic It should not update the topic subscription if the requested subscription is less than what is currently set for the user and given topic --- spec/models/topic_user_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/models/topic_user_spec.rb b/spec/models/topic_user_spec.rb index 6b6d886f050..cb0a3813592 100644 --- a/spec/models/topic_user_spec.rb +++ b/spec/models/topic_user_spec.rb @@ -250,6 +250,28 @@ describe TopicUser do expect(topic_new_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:created_post]) end + it 'should update tracking state when you reply' do + new_user.user_option.update_column(:notification_level_when_replying, 3) + post_creator.create + TopicUser.exec_sql("UPDATE topic_users set notification_level=2 + WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id) + TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:watching]) + + tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id) + expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching]) + end + + it 'should not update tracking state when you reply' do + new_user.user_option.update_column(:notification_level_when_replying, 3) + post_creator.create + TopicUser.exec_sql("UPDATE topic_users set notification_level=3 + WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id) + TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:tracking]) + + tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id) + expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching]) + end + it 'should not automatically track topics you reply to and have set state manually' do post_creator.create TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular])