mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-02 08:54:02 -04:00
Implemented strong_parameters for Upload/UploadsController.
The topic_id param is now required using strong_parameters' #require method. If the parameter is missing ActionController::ParameterMissing will be raised instead of Discourse::InvalidParameters.
This commit is contained in:
parent
f50b648844
commit
41528f5d11
3 changed files with 4 additions and 2 deletions
|
@ -2,7 +2,7 @@ class UploadsController < ApplicationController
|
||||||
before_filter :ensure_logged_in
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
def create
|
def create
|
||||||
requires_parameter(:topic_id)
|
params.require(:topic_id)
|
||||||
file = params[:file] || params[:files].first
|
file = params[:file] || params[:files].first
|
||||||
|
|
||||||
# only supports images for now
|
# only supports images for now
|
||||||
|
|
|
@ -5,6 +5,8 @@ require 's3'
|
||||||
require 'local_store'
|
require 'local_store'
|
||||||
|
|
||||||
class Upload < ActiveRecord::Base
|
class Upload < ActiveRecord::Base
|
||||||
|
include ActiveModel::ForbiddenAttributesProtection
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :topic
|
belongs_to :topic
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe UploadsController do
|
||||||
|
|
||||||
context 'missing params' do
|
context 'missing params' do
|
||||||
it 'raises an error without the topic_id param' do
|
it 'raises an error without the topic_id param' do
|
||||||
-> { xhr :post, :create }.should raise_error(Discourse::InvalidParameters)
|
-> { xhr :post, :create }.should raise_error(ActionController::ParameterMissing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue