A platform for community discussion. Free, open, simple.
FIX: Notify on Reviewable update. (#7980)
Dan Ungureanu3008ecccbd3e
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rbindex af23f150e25..b0142d1eb3f 100644--- a/app/models/reviewable.rb+++ b/app/models/reviewable.rb@@ -38,6 +38,9 @@ class Reviewable < ActiveRecord::Baseafter_commit(on: :create) doDiscourseEvent.trigger(:reviewable_created, self)+ end++ after_commit(on: [:create, :update]) doJobs.enqueue(:notify_reviewable, reviewable_id: self.id) if pending?enddiff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rbindex 6d4c5e3832c..08d36bf1a56 100644--- a/spec/models/reviewable_spec.rb+++ b/spec/models/reviewable_spec.rb@@ -237,6 +237,7 @@ RSpec.describe Reviewable, type: :model docontext "message bus notifications" dofab!(:moderator) { Fabricate(:moderator) }+ let(:post) { Fabricate(:post) }it "triggers a notification on create" doreviewable = Fabricate(:reviewable_queued_post)@@ -245,6 +246,18 @@ RSpec.describe Reviewable, type: :model doexpect(job["args"].first["reviewable_id"]).to eq(reviewable.id)end+ it "triggers a notification on update" do+ reviewable = PostActionCreator.spam(moderator, post).reviewable+ reviewable.perform(moderator, :disagree)++ expect { PostActionCreator.spam(Fabricate(:user), post) }+ .to change { reviewable.reload.status }+ .from(Reviewable.statuses[:rejected])+ .to(Reviewable.statuses[:pending])+ .and change { Jobs::NotifyReviewable.jobs.size }+ .by(1)+ end+it "triggers a notification on pending -> approve" doreviewable = Fabricate(:reviewable_queued_post)