FIX: Couldn't update category notification level

This commit is contained in:
Robin Ward 2016-08-02 11:22:02 -04:00
parent 463b536b85
commit f4c8070d09
2 changed files with 21 additions and 1 deletions

View File

@ -49,7 +49,7 @@ 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
return if record && record.notification_level = level
return if record && record.notification_level == level
if record.present?
record.notification_level = level

View File

@ -45,6 +45,26 @@ describe CategoryUser do
expect(TopicUser.get(topic, user).notification_level).to eq(regular)
end
it 'allows updating notification level' do
category = Fabricate(:category)
user = Fabricate(:user)
CategoryUser.set_notification_level_for_category(user,
NotificationLevels.all[:watching_first_post],
category.id)
expect(CategoryUser.where(user_id: user.id,
category_id: category.id,
notification_level: NotificationLevels.all[:watching_first_post]).exists?).to eq(true)
CategoryUser.set_notification_level_for_category(user,
NotificationLevels.all[:regular],
category.id)
expect(CategoryUser.where(user_id: user.id,
category_id: category.id,
notification_level: NotificationLevels.all[:regular]).exists?).to eq(true)
end
context 'integration' do
before do