mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08: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
|
||||
end
|
||||
end
|
||||
if result && result.after_commit
|
||||
result.after_commit.call
|
||||
end
|
||||
Jobs.enqueue(:notify_reviewable, reviewable_id: self.id) if update_count
|
||||
|
||||
result
|
||||
|
|
|
@ -92,7 +92,15 @@ class ReviewableQueuedPost < Reviewable
|
|||
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
|
||||
|
||||
def perform_reject_post(performed_by, args)
|
||||
|
|
|
@ -3,8 +3,14 @@ class Reviewable < ActiveRecord::Base
|
|||
include ActiveModel::Serialization
|
||||
|
||||
attr_reader :reviewable, :status, :created_post, :created_post_topic
|
||||
attr_accessor :transition_to, :remove_reviewable_ids, :errors, :recalculate_score,
|
||||
:update_flag_stats
|
||||
attr_accessor(
|
||||
:transition_to,
|
||||
:remove_reviewable_ids,
|
||||
:errors,
|
||||
:recalculate_score,
|
||||
:update_flag_stats,
|
||||
:after_commit
|
||||
)
|
||||
|
||||
def initialize(reviewable, status)
|
||||
@status = status
|
||||
|
|
|
@ -44,9 +44,16 @@ RSpec.describe ReviewableQueuedPost, type: :model do
|
|||
|
||||
it "creates a post" do
|
||||
topic_count, post_count = Topic.count, Post.count
|
||||
result = reviewable.perform(moderator, :approve_post)
|
||||
result = nil
|
||||
|
||||
Jobs.run_immediately!
|
||||
event = DiscourseEvent.track(:before_create_notifications_for_users) do
|
||||
result = reviewable.perform(moderator, :approve_post)
|
||||
end
|
||||
|
||||
expect(result.success?).to eq(true)
|
||||
expect(result.created_post).to be_present
|
||||
expect(event).to be_present
|
||||
expect(result.created_post).to be_valid
|
||||
expect(result.created_post.topic).to eq(topic)
|
||||
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
|
||||
reviewable = Fabricate(:reviewable_queued_post)
|
||||
Jobs.stubs(:enqueue)
|
||||
Jobs.expects(:enqueue).with(:notify_reviewable, has_key(:reviewable_id))
|
||||
reviewable.perform(moderator, :approve_post)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user