Implemented strong_parameters for PostAction/PostActionsController.

PostActionsController now uses strong_parameters' #require to require certain parameters. ActionController::ParameterMissing is now thrown when a reqired parameter is missing, rather than Discourse::InvalidParameters.
This commit is contained in:
Ian Christian Myers 2013-06-05 00:23:51 -07:00
parent 3b245031a4
commit f50b648844
3 changed files with 9 additions and 8 deletions

View File

@ -70,7 +70,7 @@ class PostActionsController < ApplicationController
private
def fetch_post_from_params
requires_parameter(:id)
params.require(:id)
finder = Post.where(id: params[:id])
# Include deleted posts if the user is a moderator (to guardian ?)
@ -81,7 +81,7 @@ class PostActionsController < ApplicationController
end
def fetch_post_action_type_id_from_params
requires_parameter(:post_action_type_id)
params.require(:post_action_type_id)
@post_action_type_id = params[:post_action_type_id].to_i
end
end

View File

@ -5,6 +5,7 @@ require_dependency 'trashable'
class PostAction < ActiveRecord::Base
class AlreadyActed < StandardError; end
include ActiveModel::ForbiddenAttributesProtection
include RateLimiter::OnCreateRecord
include Trashable

View File

@ -14,11 +14,11 @@ describe PostActionsController do
end
it 'raises an error when the id is missing' do
lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(Discourse::InvalidParameters)
lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(ActionController::ParameterMissing)
end
it 'raises an error when the post_action_type_id index is missing' do
lambda { xhr :post, :create, id: @post.id }.should raise_error(Discourse::InvalidParameters)
lambda { xhr :post, :create, id: @post.id }.should raise_error(ActionController::ParameterMissing)
end
it "fails when the user doesn't have permission to see the post" do
@ -70,7 +70,7 @@ describe PostActionsController do
let!(:user) { log_in }
it 'raises an error when the post_action_type_id is missing' do
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(Discourse::InvalidParameters)
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(ActionController::ParameterMissing)
end
it "returns 404 when the post action type doesn't exist for that user" do
@ -116,7 +116,7 @@ describe PostActionsController do
let!(:user) { log_in(:moderator) }
it "raises an error without a post_action_type_id" do
-> { xhr :post, :clear_flags, id: flagged_post.id }.should raise_error(Discourse::InvalidParameters)
-> { xhr :post, :clear_flags, id: flagged_post.id }.should raise_error(ActionController::ParameterMissing)
end
it "raises an error when the user doesn't have access" do
@ -160,13 +160,13 @@ describe PostActionsController do
it 'raises an error without an id' do
lambda {
xhr :get, :users, post_action_type_id: PostActionType.types[:like]
}.should raise_error(Discourse::InvalidParameters)
}.should raise_error(ActionController::ParameterMissing)
end
it 'raises an error without a post action type' do
lambda {
xhr :get, :users, id: post.id
}.should raise_error(Discourse::InvalidParameters)
}.should raise_error(ActionController::ParameterMissing)
end
it "fails when the user doesn't have permission to see the post" do