Sha256: aae596d2ffb69b0014af65a48de63934541713b0f9d109c823f03e60c774df50

Contents?: true

Size: 1.81 KB

Versions: 47

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require "abstract_unit"
require "action_controller/metal/strong_parameters"
require "active_support/core_ext/object/deep_dup"

class ParametersDupTest < ActiveSupport::TestCase
  setup do
    ActionController::Parameters.permit_all_parameters = false

    @params = ActionController::Parameters.new(
      person: {
        age: "32",
        name: {
          first: "David",
          last: "Heinemeier Hansson"
        },
        addresses: [{ city: "Chicago", state: "Illinois" }]
      }
    )
  end

  test "a duplicate maintains the original's permitted status" do
    @params.permit!
    dupped_params = @params.dup
    assert_predicate dupped_params, :permitted?
  end

  test "a duplicate maintains the original's parameters" do
    @params.permit!
    dupped_params = @params.dup
    assert_equal @params.to_h, dupped_params.to_h
  end

  test "changes to a duplicate's parameters do not affect the original" do
    dupped_params = @params.dup
    dupped_params.delete(:person)
    assert_not_equal @params, dupped_params
  end

  test "changes to a duplicate's permitted status do not affect the original" do
    dupped_params = @params.dup
    dupped_params.permit!
    assert_not_equal @params, dupped_params
  end

  test "deep_dup content" do
    dupped_params = @params.deep_dup
    dupped_params[:person][:age] = "45"
    dupped_params[:person][:addresses].clear

    assert_not_equal @params[:person][:age], dupped_params[:person][:age]
    assert_not_equal @params[:person][:addresses], dupped_params[:person][:addresses]
  end

  test "deep_dup @permitted" do
    dupped_params = @params.deep_dup
    dupped_params.permit!

    assert_not_predicate @params, :permitted?
  end

  test "deep_dup @permitted is being copied" do
    @params.permit!
    assert_predicate @params.deep_dup, :permitted?
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.9.7 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.6 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.5 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.4 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.3 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.2 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.1 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.9.0 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.14 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.13 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.12 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.11 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.10 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.9 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.8 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.7 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.6 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.5 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.4 vendor/rails/actionpack/test/controller/parameters/dup_test.rb
jets-1.8.3 vendor/rails/actionpack/test/controller/parameters/dup_test.rb