FIX: Correct behavior of auto-notification state updating to exclude when the topic already has a state of normal/muted

This commit is contained in:
cpradio 2017-04-19 06:26:04 -04:00
parent d9ba168420
commit 2dccaff25d
2 changed files with 25 additions and 2 deletions

View File

@ -38,8 +38,9 @@ class TopicUser < ActiveRecord::Base
end end
def auto_notification(user_id, topic_id, reason, notification_level) def auto_notification(user_id, topic_id, reason, notification_level)
if TopicUser.where("user_id = ? AND topic_id = ? AND (notifications_reason_id IS NULL OR notification_level < ?)", if TopicUser.where("user_id = :user_id AND topic_id = :topic_id AND (notifications_reason_id IS NULL OR
user_id, topic_id, notification_level).exists? (notification_level < :notification_level AND notification_level > 1))",
user_id: user_id, topic_id: topic_id, notification_level: notification_level).exists?
change(user_id, topic_id, change(user_id, topic_id,
notification_level: notification_level, notification_level: notification_level,
notifications_reason_id: reason notifications_reason_id: reason

View File

@ -272,6 +272,28 @@ describe TopicUser do
expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching]) expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching])
end end
it 'should not update tracking state when state manually set to normal 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=1
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[:regular])
end
it 'should not update tracking state when state manually set to muted 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=0
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[:muted])
end
it 'should not automatically track topics you reply to and have set state manually' do it 'should not automatically track topics you reply to and have set state manually' do
post_creator.create post_creator.create
TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular]) TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular])