FIX: Bulk updating category failed when topic title was too short

This commit is contained in:
Gerhard Schlager 2018-08-14 16:06:52 +02:00
parent 7290765a62
commit c358421ca5
2 changed files with 7 additions and 1 deletions

View File

@ -682,7 +682,7 @@ class Topic < ActiveRecord::Base
old_category = category
if self.category_id != new_category.id
self.update!(category_id: new_category.id)
self.update_attribute(:category_id, new_category.id)
if old_category
Category

View File

@ -1181,6 +1181,12 @@ describe Topic do
topic.change_category_to_id(12312312)
expect(topic.category_id).to eq(SiteSetting.uncategorized_category_id)
end
it "changes the category even when the topic title is invalid" do
SiteSetting.min_topic_title_length = 5
topic.update_column(:title, "xyz")
expect { topic.change_category_to_id(category.id) }.to change { topic.category_id }.to(category.id)
end
end
describe 'with a previous category' do