A platform for community discussion. Free, open, simple.
FEATURE: Update the topic excerpt when the OP is rebaked (#9852)
Martin Brennanf9d55b494169
diff --git a/app/models/post.rb b/app/models/post.rbindex 30ebaf01630..e1a3a1f391e 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -650,6 +650,10 @@ class Post < ActiveRecord::Basebaked_version: BAKED_VERSION)+ if is_first_post?+ topic.update_excerpt(excerpt_for_topic)+ end+if invalidate_broken_imagescustom_fields.delete(BROKEN_IMAGES)save_custom_fieldsdiff --git a/app/models/topic.rb b/app/models/topic.rbindex f02b4fc030f..38affdb327b 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -1476,6 +1476,13 @@ class Topic < ActiveRecord::Baseprivate_topicend+ def update_excerpt(excerpt)+ update_column(:excerpt, excerpt)+ if archetype == "banner"+ ApplicationController.banner_json_cache.clear+ end+ end+def pm_with_non_human_user?sql = <<~SQLSELECT 1 FROM topicsdiff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 3c9ec277cdb..d610fccf375 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -567,11 +567,7 @@ class PostRevisorenddef update_topic_excerpt- excerpt = @post.excerpt_for_topic- @topic.update_column(:excerpt, excerpt)- if @topic.archetype == "banner"- ApplicationController.banner_json_cache.clear- end+ @topic.update_excerpt(@post.excerpt_for_topic)enddef update_category_descriptiondiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex d0e2aba6319..5bc5206bced 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1195,6 +1195,25 @@ describe Post doexpect(post.cooked).to eq(first_cooked)expect(result).to eq(true)end++ it "updates the topic excerpt at the same time if it is the OP" do+ post = create_post+ post.topic.update(excerpt: "test")+ DB.exec("UPDATE posts SET cooked = 'frogs' WHERE id = ?", [ post.id ])+ post.reload+ result = post.rebake!+ post.topic.reload+ expect(post.topic.excerpt).not_to eq("test")+ end++ it "does not update the topic excerpt if the post is not the OP" do+ post = create_post+ post2 = create_post+ post.topic.update(excerpt: "test")+ result = post2.rebake!+ post.topic.reload+ expect(post.topic.excerpt).to eq("test")+ endenddescribe "#set_owner" do