Add extensibility point for whenever a post is created
This commit is contained in:
parent
2507f99135
commit
1f40807001
|
@ -85,7 +85,8 @@ class PostsController < ApplicationController
|
|||
[false, MultiJson.dump(errors: post_creator.errors.full_messages)]
|
||||
|
||||
else
|
||||
DiscourseEvent.trigger(:topic_created, post.topic, params, current_user)
|
||||
DiscourseEvent.trigger(:topic_created, post.topic, params, current_user) unless params[:topic_id]
|
||||
DiscourseEvent.trigger(:post_created, post, params, current_user)
|
||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
||||
post_serializer.draft_sequence = DraftSequence.current(current_user, post.topic.draft_key)
|
||||
[true, MultiJson.dump(post_serializer)]
|
||||
|
|
|
@ -477,15 +477,16 @@ describe PostsController do
|
|||
expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'calls the post creator' do
|
||||
it 'creates the post' do
|
||||
PostCreator.any_instance.expects(:create).returns(new_post)
|
||||
xhr :post, :create, {raw: 'test'}
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'returns JSON of the post' do
|
||||
PostCreator.any_instance.expects(:create).returns(new_post)
|
||||
# Make sure our extensibility points are triggered
|
||||
DiscourseEvent.expects(:trigger).with(:topic_created, new_post.topic, anything, user).once
|
||||
DiscourseEvent.expects(:trigger).with(:post_created, new_post, anything, user).once
|
||||
|
||||
xhr :post, :create, {raw: 'test'}
|
||||
|
||||
expect(response).to be_success
|
||||
expect(::JSON.parse(response.body)).to be_present
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue