2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2012-08-29 11:08:58 -04:00
|
|
|
|
|
|
|
class PeopleController < ActionController::Base
|
|
|
|
def create
|
2015-07-17 21:48:00 -04:00
|
|
|
render plain: params[:person].permitted? ? "permitted" : "forbidden"
|
2012-08-29 11:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_with_permit
|
2015-07-17 21:48:00 -04:00
|
|
|
render plain: params[:person].permit(:name).permitted? ? "permitted" : "forbidden"
|
2012-08-29 11:08:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ActionControllerPermittedParamsTest < ActionController::TestCase
|
|
|
|
tests PeopleController
|
|
|
|
|
|
|
|
test "parameters are forbidden" do
|
2015-01-04 04:35:06 -05:00
|
|
|
post :create, params: { person: { name: "Mjallo!" } }
|
2012-08-29 11:08:58 -04:00
|
|
|
assert_equal "forbidden", response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "parameters can be permitted and are then not forbidden" do
|
2015-01-04 04:35:06 -05:00
|
|
|
post :create_with_permit, params: { person: { name: "Mjallo!" } }
|
2012-08-29 11:08:58 -04:00
|
|
|
assert_equal "permitted", response.body
|
|
|
|
end
|
|
|
|
end
|