Permalink
Browse files

Test that permitted? is sticky on accessors, mutators, and merges

  • Loading branch information...
1 parent 1a0f14e commit 478d80fd5788a4b3e7c8482bfd3713eef7d00884 @bquorning bquorning committed Nov 6, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 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" }

0 comments on commit 478d80f

Please sign in to comment.