mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:43:38 +08:00
FIX: Notify on Reviewable update. (#7980)
If a post is flagged after an action was already performed on it, it will update the previous Reviable instance and not create a new one. The notification logic was implemented in the :create callback which was completely skipped in this case.
This commit is contained in:
parent
6d3d08daad
commit
3008ecccbd
|
@ -38,6 +38,9 @@ class Reviewable < ActiveRecord::Base
|
||||||
|
|
||||||
after_commit(on: :create) do
|
after_commit(on: :create) do
|
||||||
DiscourseEvent.trigger(:reviewable_created, self)
|
DiscourseEvent.trigger(:reviewable_created, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
after_commit(on: [:create, :update]) do
|
||||||
Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if pending?
|
Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if pending?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,7 @@ RSpec.describe Reviewable, type: :model do
|
||||||
|
|
||||||
context "message bus notifications" do
|
context "message bus notifications" do
|
||||||
fab!(:moderator) { Fabricate(:moderator) }
|
fab!(:moderator) { Fabricate(:moderator) }
|
||||||
|
let(:post) { Fabricate(:post) }
|
||||||
|
|
||||||
it "triggers a notification on create" do
|
it "triggers a notification on create" do
|
||||||
reviewable = Fabricate(:reviewable_queued_post)
|
reviewable = Fabricate(:reviewable_queued_post)
|
||||||
|
@ -245,6 +246,18 @@ RSpec.describe Reviewable, type: :model do
|
||||||
expect(job["args"].first["reviewable_id"]).to eq(reviewable.id)
|
expect(job["args"].first["reviewable_id"]).to eq(reviewable.id)
|
||||||
end
|
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" do
|
it "triggers a notification on pending -> approve" do
|
||||||
reviewable = Fabricate(:reviewable_queued_post)
|
reviewable = Fabricate(:reviewable_queued_post)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user