mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 18:53:09 +08:00
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)]
|
[false, MultiJson.dump(errors: post_creator.errors.full_messages)]
|
||||||
|
|
||||||
else
|
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 = PostSerializer.new(post, scope: guardian, root: false)
|
||||||
post_serializer.draft_sequence = DraftSequence.current(current_user, post.topic.draft_key)
|
post_serializer.draft_sequence = DraftSequence.current(current_user, post.topic.draft_key)
|
||||||
[true, MultiJson.dump(post_serializer)]
|
[true, MultiJson.dump(post_serializer)]
|
||||||
|
@ -477,15 +477,16 @@ describe PostsController do
|
|||||||
expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing)
|
expect { xhr :post, :create }.to raise_error(ActionController::ParameterMissing)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls the post creator' do
|
it 'creates the post' do
|
||||||
PostCreator.any_instance.expects(:create).returns(new_post)
|
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
|
# Make sure our extensibility points are triggered
|
||||||
PostCreator.any_instance.expects(:create).returns(new_post)
|
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'}
|
xhr :post, :create, {raw: 'test'}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
expect(::JSON.parse(response.body)).to be_present
|
expect(::JSON.parse(response.body)).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user