diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index f6d6399b92c..3cef663c565 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -6,6 +6,8 @@ class PostActionsController < ApplicationController before_filter :fetch_post_action_type_id_from_params def create + raise Discourse::NotFound if @post.blank? + taken = PostAction.counts_for([@post], current_user)[@post.id] guardian.ensure_post_can_act!( diff --git a/spec/controllers/post_actions_controller_spec.rb b/spec/controllers/post_actions_controller_spec.rb index 336300072d7..141e99ca9ff 100644 --- a/spec/controllers/post_actions_controller_spec.rb +++ b/spec/controllers/post_actions_controller_spec.rb @@ -31,6 +31,11 @@ describe PostActionsController do expect { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.to raise_error(ActionController::ParameterMissing) end + it 'fails when the id is invalid' do + xhr :post, :create, post_action_type_id: PostActionType.types[:like], id: -1 + expect(response.status).to eq(404) + end + it 'raises an error when the post_action_type_id index is missing' do expect { xhr :post, :create, id: @post.id }.to raise_error(ActionController::ParameterMissing) end