Move MessageBus observer into PostCreator
This commit is contained in:
parent
c24f6d3d51
commit
aea848f164
|
@ -3,15 +3,7 @@ require_dependency 'discourse_observer'
|
|||
# This class is responsible for notifying the message bus of various
|
||||
# events.
|
||||
class MessageBusObserver < DiscourseObserver
|
||||
observe :post, :notification, :user_action, :topic
|
||||
|
||||
def after_create_post(post)
|
||||
MessageBus.publish("/topic/#{post.topic_id}",
|
||||
id: post.id,
|
||||
created_at: post.created_at,
|
||||
user: BasicUserSerializer.new(post.user).as_json(root: false),
|
||||
post_number: post.post_number)
|
||||
end
|
||||
observe :notification, :user_action, :topic
|
||||
|
||||
def after_create_notification(notification)
|
||||
refresh_notification_count(notification)
|
||||
|
|
|
@ -110,6 +110,13 @@ class PostCreator
|
|||
|
||||
# Update `last_posted_at` to match the post's created_at
|
||||
@user.update_column(:last_posted_at, post.created_at)
|
||||
|
||||
# Publish the post in the message bus
|
||||
MessageBus.publish("/topic/#{post.topic_id}",
|
||||
id: post.id,
|
||||
created_at: post.created_at,
|
||||
user: BasicUserSerializer.new(post.user).as_json(root: false),
|
||||
post_number: post.post_number)
|
||||
end
|
||||
|
||||
post
|
||||
|
|
|
@ -11,6 +11,7 @@ describe PostCreator do
|
|||
|
||||
context 'new topic' do
|
||||
let(:category) { Fabricate(:category, user: user) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
let(:basic_topic_params) { {title: 'hello world topic', raw: 'my name is fred', archetype_id: 1} }
|
||||
let(:image_sizes) { {'http://an.image.host/image.jpg' => {'width' => 111, 'height' => 222}} }
|
||||
|
||||
|
@ -38,6 +39,12 @@ describe PostCreator do
|
|||
creator.create
|
||||
end
|
||||
|
||||
it 'enqueues the post on the message bus' do
|
||||
MessageBus.stubs(:publish).with("/users/#{user.username}", anything)
|
||||
MessageBus.expects(:publish).with("/topic/#{topic.id}", instance_of(Hash))
|
||||
PostCreator.new(user, raw: basic_topic_params[:raw], topic_id: topic.id)
|
||||
end
|
||||
|
||||
it 'features topic users' do
|
||||
Jobs.stubs(:enqueue).with(:process_post, anything)
|
||||
Jobs.expects(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
|
|
|
@ -81,14 +81,6 @@ describe Post do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'message bus' do
|
||||
it 'enqueues the post on the message bus' do
|
||||
topic = self.topic
|
||||
MessageBus.expects(:publish).with("/topic/#{topic.id}", instance_of(Hash))
|
||||
Fabricate(:post, post_args)
|
||||
end
|
||||
end
|
||||
|
||||
describe "maximum images" do
|
||||
let(:post_no_images) { Fabricate.build(:post, post_args) }
|
||||
let(:post_one_image) { Fabricate.build(:post, post_args.merge(raw: "![sherlock](http://bbc.co.uk/sherlock.jpg)")) }
|
||||
|
|
Loading…
Reference in New Issue