From b3f894c5282244b41221f98dfac5296cea5a4485 Mon Sep 17 00:00:00 2001 From: Sebastian Sogamoso Date: Mon, 11 Mar 2013 08:00:19 -0500 Subject: Change ActionController::Parameters#require behavior when value is empty When the value for the required key is empty an ActionController::ParameterMissing is raised which gets caught by ActionController::Base and turned into a 400 Bad Request reply with a message in the body saying the key is missing, which is misleading. With these changes, ActionController::EmptyParameter will be raised which ActionController::Base will catch and turn into a 400 Bad Request reply with a message in the body saying the key value is empty. --- actionpack/test/controller/parameters/parameters_require_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller/parameters') diff --git a/actionpack/test/controller/parameters/parameters_require_test.rb b/actionpack/test/controller/parameters/parameters_require_test.rb index bdaba8d2d8..21b3eaa6b5 100644 --- a/actionpack/test/controller/parameters/parameters_require_test.rb +++ b/actionpack/test/controller/parameters/parameters_require_test.rb @@ -2,8 +2,14 @@ require 'abstract_unit' require 'action_controller/metal/strong_parameters' class ParametersRequireTest < ActiveSupport::TestCase - test "required parameters must be present not merely not nil" do + test "required parameters must be present" do assert_raises(ActionController::ParameterMissing) do + ActionController::Parameters.new(name: {}).require(:person) + end + end + + test "required parameters can't be blank" do + assert_raises(ActionController::EmptyParameter) do ActionController::Parameters.new(person: {}).require(:person) end end -- cgit v1.2.3