Merge pull request #4513 from tgxworld/dont_cook_post_unless_raw_has_changed

FIX: Do not cook post if `Post#raw` has not been changed.
This commit is contained in:
Régis Hanol 2016-10-24 10:07:15 +02:00 committed by GitHub
commit dc0d302345
2 changed files with 20 additions and 1 deletions

View File

@ -522,7 +522,11 @@ class Post < ActiveRecord::Base
before_save do
self.last_editor_id ||= user_id
self.cooked = cook(raw, topic_id: topic_id) unless new_record?
if !new_record? && raw_changed?
self.cooked = cook(raw, topic_id: topic_id)
end
self.baked_at = Time.new
self.baked_version = BAKED_VERSION
end

View File

@ -628,6 +628,21 @@ describe Post do
end
describe 'before save' do
let(:cooked) { "<p><div class=\"lightbox-wrapper\"><a data-download-href=\"//localhost:3000/uploads/default/34784374092783e2fef84b8bc96d9b54c11ceea0\" href=\"//localhost:3000/uploads/default/original/1X/34784374092783e2fef84b8bc96d9b54c11ceea0.gif\" class=\"lightbox\" title=\"Sword reworks.gif\"><img src=\"//localhost:3000/uploads/default/optimized/1X/34784374092783e2fef84b8bc96d9b54c11ceea0_1_690x276.gif\" width=\"690\" height=\"276\"><div class=\"meta\">\n<span class=\"filename\">Sword reworks.gif</span><span class=\"informations\">1000x400 1000 KB</span><span class=\"expand\"></span>\n</div></a></div></p>" }
let(:post) do
Fabricate(:post,
raw: "<img src=\"/uploads/default/original/1X/34784374092783e2fef84b8bc96d9b54c11ceea0.gif\" width=\"690\" height=\"276\">",
cooked: cooked
)
end
it 'should not cook the post if raw has not been changed' do
post.save!
expect(post.cooked).to eq(cooked)
end
end
describe 'after save' do