diff options
Diffstat (limited to 'actionpack/test/controller/required_params_test.rb')
-rw-r--r-- | actionpack/test/controller/required_params_test.rb | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb index b6efcd6f9a..4a83d07e7d 100644 --- a/actionpack/test/controller/required_params_test.rb +++ b/actionpack/test/controller/required_params_test.rb @@ -1,4 +1,6 @@ -require 'abstract_unit' +# frozen_string_literal: true + +require "abstract_unit" class BooksController < ActionController::Base def create @@ -32,7 +34,6 @@ class ActionControllerRequiredParamsTest < ActionController::TestCase end class ParametersRequireTest < ActiveSupport::TestCase - test "required parameters should accept and return false value" do assert_equal(false, ActionController::Parameters.new(person: false).require(:person)) end @@ -50,17 +51,17 @@ class ParametersRequireTest < ActiveSupport::TestCase end test "require array when all required params are present" do - safe_params = ActionController::Parameters.new(person: {first_name: 'Gaurish', title: 'Mjallo', city: 'Barcelona'}) + safe_params = ActionController::Parameters.new(person: { first_name: "Gaurish", title: "Mjallo", city: "Barcelona" }) .require(:person) .require([:first_name, :title]) assert_kind_of Array, safe_params - assert_equal ['Gaurish', 'Mjallo'], safe_params + assert_equal ["Gaurish", "Mjallo"], safe_params end test "require array when a required param is missing" do assert_raises(ActionController::ParameterMissing) do - ActionController::Parameters.new(person: {first_name: 'Gaurish', title: nil}) + ActionController::Parameters.new(person: { first_name: "Gaurish", title: nil }) .require(:person) .require([:first_name, :title]) end @@ -73,9 +74,27 @@ class ParametersRequireTest < ActiveSupport::TestCase assert params.value?("cinco") end - test "Deprecated methods are deprecated" do - assert_deprecated do - ActionController::Parameters.new(foo: "bar").merge!({bar: "foo"}) + test "to_param works like in a Hash" do + params = ActionController::Parameters.new(nested: { key: "value" }).permit! + assert_equal({ nested: { key: "value" } }.to_param, params.to_param) + + params = { root: ActionController::Parameters.new(nested: { key: "value" }).permit! } + assert_equal({ root: { nested: { key: "value" } } }.to_param, params.to_param) + + assert_raise(ActionController::UnfilteredParameters) do + ActionController::Parameters.new(nested: { key: "value" }).to_param + end + end + + test "to_query works like in a Hash" do + params = ActionController::Parameters.new(nested: { key: "value" }).permit! + assert_equal({ nested: { key: "value" } }.to_query, params.to_query) + + params = { root: ActionController::Parameters.new(nested: { key: "value" }).permit! } + assert_equal({ root: { nested: { key: "value" } } }.to_query, params.to_query) + + assert_raise(ActionController::UnfilteredParameters) do + ActionController::Parameters.new(nested: { key: "value" }).to_query end end end |