mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 12:43:54 -06:00
FIX: Approved posts were not enqueueing alerts
This commit is contained in:
parent
b9339e15a1
commit
646cdfa449
@ -230,6 +230,9 @@ class Reviewable < ActiveRecord::Base
|
|||||||
recalculate_score if result.recalculate_score
|
recalculate_score if result.recalculate_score
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if result && result.after_commit
|
||||||
|
result.after_commit.call
|
||||||
|
end
|
||||||
Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if update_count
|
Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if update_count
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -92,7 +92,15 @@ class ReviewableQueuedPost < Reviewable
|
|||||||
post_number: created_post.post_number
|
post_number: created_post.post_number
|
||||||
)
|
)
|
||||||
|
|
||||||
create_result(:success, :approved) { |result| result.created_post = created_post }
|
create_result(:success, :approved) do |result|
|
||||||
|
result.created_post = created_post
|
||||||
|
|
||||||
|
# Do sidekiq work outside of the transaction
|
||||||
|
result.after_commit = -> {
|
||||||
|
creator.enqueue_jobs
|
||||||
|
creator.trigger_after_events
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_reject_post(performed_by, args)
|
def perform_reject_post(performed_by, args)
|
||||||
|
@ -3,8 +3,14 @@ class Reviewable < ActiveRecord::Base
|
|||||||
include ActiveModel::Serialization
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
attr_reader :reviewable, :status, :created_post, :created_post_topic
|
attr_reader :reviewable, :status, :created_post, :created_post_topic
|
||||||
attr_accessor :transition_to, :remove_reviewable_ids, :errors, :recalculate_score,
|
attr_accessor(
|
||||||
:update_flag_stats
|
:transition_to,
|
||||||
|
:remove_reviewable_ids,
|
||||||
|
:errors,
|
||||||
|
:recalculate_score,
|
||||||
|
:update_flag_stats,
|
||||||
|
:after_commit
|
||||||
|
)
|
||||||
|
|
||||||
def initialize(reviewable, status)
|
def initialize(reviewable, status)
|
||||||
@status = status
|
@status = status
|
||||||
|
@ -44,9 +44,16 @@ RSpec.describe ReviewableQueuedPost, type: :model do
|
|||||||
|
|
||||||
it "creates a post" do
|
it "creates a post" do
|
||||||
topic_count, post_count = Topic.count, Post.count
|
topic_count, post_count = Topic.count, Post.count
|
||||||
|
result = nil
|
||||||
|
|
||||||
|
Jobs.run_immediately!
|
||||||
|
event = DiscourseEvent.track(:before_create_notifications_for_users) do
|
||||||
result = reviewable.perform(moderator, :approve_post)
|
result = reviewable.perform(moderator, :approve_post)
|
||||||
|
end
|
||||||
|
|
||||||
expect(result.success?).to eq(true)
|
expect(result.success?).to eq(true)
|
||||||
expect(result.created_post).to be_present
|
expect(result.created_post).to be_present
|
||||||
|
expect(event).to be_present
|
||||||
expect(result.created_post).to be_valid
|
expect(result.created_post).to be_valid
|
||||||
expect(result.created_post.topic).to eq(topic)
|
expect(result.created_post.topic).to eq(topic)
|
||||||
expect(result.created_post.custom_fields['hello']).to eq('world')
|
expect(result.created_post.custom_fields['hello']).to eq('world')
|
||||||
|
@ -203,6 +203,7 @@ RSpec.describe Reviewable, type: :model do
|
|||||||
|
|
||||||
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)
|
||||||
|
Jobs.stubs(:enqueue)
|
||||||
Jobs.expects(:enqueue).with(:notify_reviewable, has_key(:reviewable_id))
|
Jobs.expects(:enqueue).with(:notify_reviewable, has_key(:reviewable_id))
|
||||||
reviewable.perform(moderator, :approve_post)
|
reviewable.perform(moderator, :approve_post)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user