A platform for community discussion. Free, open, simple.
FIX: update flag reason message with default value (#30026)
Krzysztof Kotlarek28b4ff6cb694
diff --git a/app/models/post.rb b/app/models/post.rbindex 066d618fea1..832e427e0f3 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -658,6 +658,7 @@ class Post < ActiveRecord::Base"flag_reasons.#{post_action_type_view.types[post_action_type_id]}",locale: SiteSetting.default_locale,base_path: Discourse.base_path,+ default: PostActionType.names[post_action_type_id],),}diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex b7b8a6be840..f4dc3b1188c 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -413,6 +413,7 @@ class PostDestroyer"flag_reasons#{".responder" if notify_responders}.#{flag_type}",locale: SiteSetting.default_locale,base_path: Discourse.base_path,+ default: PostActionType.flags.find { |flag| flag[:name_key] == flag_type.to_s }[:name],),},)diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rbindex daedd7630ef..8cb10a50497 100644--- a/spec/lib/post_destroyer_spec.rb+++ b/spec/lib/post_destroyer_spec.rb@@ -954,6 +954,29 @@ RSpec.describe PostDestroyer doexpect(Jobs::SendSystemMessage.jobs.size).to eq(0)expect(ReviewableFlaggedPost.pending.count).to eq(0)end++ context "when custom flags" do+ fab!(:custom_flag) { Fabricate(:flag, name: "custom flag", notify_type: true) }+ let(:third_post) { Fabricate(:post, topic_id: post.topic_id) }++ it "should send message to user with correct translation" do+ PostActionCreator.new(+ moderator,+ third_post,+ custom_flag.id,+ is_warning: false,+ flag_topic: true,+ ).perform+ PostDestroyer.new(moderator, third_post, { reviewable: Reviewable.last }).destroy+ jobs = Jobs::SendSystemMessage.jobs+ expect(jobs.size).to eq(1)++ Jobs::SendSystemMessage.new.execute(jobs[0]["args"][0].with_indifferent_access)++ expect(Post.last.raw).to match("custom flag")+ custom_flag.destroy!+ end+ endenddescribe "user actions" dodiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex abcf5fbfc50..403bcd53b15 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1498,6 +1498,19 @@ RSpec.describe Post do).to(true)end+ it "should inform the user when custom flag" do+ custom_flag = Fabricate(:flag, name: "custom flag")+ post.hide!(PostActionType.types[:custom_custom_flag])++ jobs = Jobs::SendSystemMessage.jobs+ expect(jobs.size).to eq(1)++ Jobs::SendSystemMessage.new.execute(jobs[0]["args"][0].with_indifferent_access)+ expect(Post.last.raw).to match("custom flag")++ custom_flag.destroy!+ end+it "should decrease user_stat topic_count for first post" doexpect do post.hide!(PostActionType.types[:off_topic]) end.to change {post.user.user_stat.reload.topic_count