FIX: `Topic#fancy_title` should not write in readonly mode.

This commit is contained in:
Guo Xiang Tan 2017-10-19 15:41:03 +08:00
parent 9d6449ae92
commit 5b9ddaf972
2 changed files with 22 additions and 2 deletions

View File

@ -311,11 +311,10 @@ class Topic < ActiveRecord::Base
return ERB::Util.html_escape(title) unless SiteSetting.title_fancy_entities?
unless fancy_title = read_attribute(:fancy_title)
fancy_title = Topic.fancy_title(title)
write_attribute(:fancy_title, fancy_title)
unless new_record?
if !new_record? && !Discourse.readonly_mode?
# make sure data is set in table, this also allows us to change algorithm
# by simply nulling this column
exec_sql("UPDATE topics SET fancy_title = :fancy_title where id = :id", id: self.id, fancy_title: fancy_title)

View File

@ -327,6 +327,27 @@ describe Topic do
topic.title = "this is another edge case"
expect(topic.fancy_title).to eq("this is another edge case")
end
context 'readonly mode' do
before do
Discourse.enable_readonly_mode
end
after do
Discourse.disable_readonly_mode
end
it 'should not attempt to update `fancy_title`' do
topic.save!
expect(topic.fancy_title).to eq('&ldquo;this topic&rdquo; &ndash; has &ldquo;fancy stuff&rdquo;')
topic.title = "This is a test testing testing"
expect(topic.fancy_title).to eq("This is a test testing testing")
expect(topic.reload.read_attribute(:fancy_title))
.to eq('&ldquo;this topic&rdquo; &ndash; has &ldquo;fancy stuff&rdquo;')
end
end
end
end