diff --git a/app/models/topic.rb b/app/models/topic.rb index c54ab04f77c..7a7c2ae0af7 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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 diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 9e6b5afce5c..df1b61225dc 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -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