Sha256: 69694570456be49a15d32b305d7b3b782f1973a5de245de8b012df0e5fa183ae

Contents?: true

Size: 1.3 KB

Versions: 47

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "abstract_unit"
require "action_controller/metal/strong_parameters"

class MultiParameterAttributesTest < ActiveSupport::TestCase
  test "permitted multi-parameter attribute keys" do
    params = ActionController::Parameters.new(
      book: {
        "shipped_at(1i)"   => "2012",
        "shipped_at(2i)"   => "3",
        "shipped_at(3i)"   => "25",
        "shipped_at(4i)"   => "10",
        "shipped_at(5i)"   => "15",
        "published_at(1i)" => "1999",
        "published_at(2i)" => "2",
        "published_at(3i)" => "5",
        "price(1)"         => "R$",
        "price(2f)"        => "2.02"
      })

    permitted = params.permit book: [ :shipped_at, :price ]

    assert_predicate permitted, :permitted?

    assert_equal "2012", permitted[:book]["shipped_at(1i)"]
    assert_equal "3", permitted[:book]["shipped_at(2i)"]
    assert_equal "25", permitted[:book]["shipped_at(3i)"]
    assert_equal "10", permitted[:book]["shipped_at(4i)"]
    assert_equal "15", permitted[:book]["shipped_at(5i)"]

    assert_equal "R$", permitted[:book]["price(1)"]
    assert_equal "2.02", permitted[:book]["price(2f)"]

    assert_nil permitted[:book]["published_at(1i)"]
    assert_nil permitted[:book]["published_at(2i)"]
    assert_nil permitted[:book]["published_at(3i)"]
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

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