From 1f40807001ef95cc114387503ac2af596efc7809 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 29 Jan 2015 12:37:39 -0500 Subject: [PATCH] Add extensibility point for whenever a post is created --- app/controllers/posts_controller.rb | 3 ++- spec/controllers/posts_controller_spec.rb | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a395b98fb13..860c4c71d87 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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)] diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 9277fc0022d..651efcb362b 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -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