FIX: Return 404 if id is not valid.

This commit is contained in:
Guo Xiang Tan 2017-01-06 10:39:44 +08:00
parent d10fe51b72
commit 68300f515c
2 changed files with 7 additions and 0 deletions

View File

@ -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!(

View File

@ -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