From 478d80fd5788a4b3e7c8482bfd3713eef7d00884 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Tue, 6 Nov 2012 21:30:12 +0100 Subject: Test that permitted? is sticky on accessors, mutators, and merges --- .../parameters/parameters_permit_test.rb | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 79ce7bb3a7..7cc71fe6dc 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -32,15 +32,39 @@ class ParametersPermitTest < ActiveSupport::TestCase assert !@params.values_at(:person).first.permitted? end + test "permitted is sticky on accessors" do + @params.permit! + assert @params.slice(:person).permitted? + assert @params[:person][:name].permitted? + assert @params[:person].except(:name).permitted? + + @params.each { |key, value| assert(value.permitted?) if key == "person" } + + assert @params.fetch(:person).permitted? + + assert @params.values_at(:person).first.permitted? + end + test "not permitted is sticky on mutators" do assert !@params.delete_if { |k| k == "person" }.permitted? assert !@params.keep_if { |k,v| k == "person" }.permitted? end + test "permitted is sticky on mutators" do + @params.permit! + assert @params.delete_if { |k| k == "person" }.permitted? + assert @params.keep_if { |k,v| k == "person" }.permitted? + end + test "not permitted is sticky beyond merges" do assert !@params.merge(a: "b").permitted? end + test "permitted is sticky beyond merges" do + @params.permit! + assert @params.merge(a: "b").permitted? + end + test "modifying the parameters" do @params[:person][:hometown] = "Chicago" @params[:person][:family] = { brother: "Jonas" } -- cgit v1.2.3