<commit_before>require "abstract_unit"
require "action_controller/metal/strong_parameters"
require "active_support/core_ext/string/strip"

class ParametersSerializationTest < ActiveSupport::TestCase
  setup do
    @old_permitted_parameters = ActionController::Parameters.permit_all_parameters
    ActionController::Parameters.permit_all_parameters = false
  end

  teardown do
    ActionController::Parameters.permit_all_parameters = @old_permitted_parameters
  end

  test "yaml serialization" do
    params = ActionController::Parameters.new(key: :value)
    assert_equal <<-end_of_yaml.strip_heredoc, YAML.dump(params)
      --- !ruby/object:ActionController::Parameters
      parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
        key: :value
      permitted: false
    end_of_yaml
  end

  test "yaml deserialization" do
    params = ActionController::Parameters.new(key: :value)
    roundtripped = YAML.load(YAML.dump(params))

    assert_equal params, roundtripped
    assert_not roundtripped.permitted?
  end
<commit_msg>Soften this test since YAML.dump may produce keys in other orders.<commit_after>require "abstract_unit"
require "action_controller/metal/strong_parameters"
require "active_support/core_ext/string/strip"

class ParametersSerializationTest < ActiveSupport::TestCase
  setup do
    @old_permitted_parameters = ActionController::Parameters.permit_all_parameters
    ActionController::Parameters.permit_all_parameters = false
  end

  teardown do
    ActionController::Parameters.permit_all_parameters = @old_permitted_parameters
  end

  test "yaml serialization" do
    params = ActionController::Parameters.new(key: :value)
    yaml_dump = YAML.dump(params)
    assert_match("--- !ruby/object:ActionController::Parameters", yaml_dump)
    assert_match(/parameters: !ruby\/hash:ActiveSupport::HashWithIndifferentAccess\n\s+key: :value/, yaml_dump)
    assert_match("permitted: false", yaml_dump)
  end

  test "yaml deserialization" do
    params = ActionController::Parameters.new(key: :value)
    roundtripped = YAML.load(YAML.dump(params))

    assert_equal params, roundtripped
    assert_not roundtripped.permitted?
  end

{'fraction_non_alphanumeric': 0.08709677419354839, 'fraction_numerical': 0.0, 'mean_word_length': 5.366568914956011, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6437689', 'n_tokens_mistral': 645, 'n_tokens_neox': 621, 'n_words': 121}