Sha256: d2a9a88783757faf71d6161d0a859e242c0a1673e3e9e5ab32ff50f657e3521d

Contents?: true

Size: 1.89 KB

Versions: 30

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
require_relative 'common'

describe 'Config' do
  make_my_diffs_pretty!
  parallelize_me!

  def verify_deeply_frozen(config)
    config.must_be :frozen?

    if Hash === config
      config.each_value {|v| verify_deeply_frozen(v) }
    elsif Set === config || Array === config
      config.each {|v| verify_deeply_frozen(v) }
    end
  end

  it 'built-in configs should be deeply frozen' do
    verify_deeply_frozen Sanitize::Config::DEFAULT
    verify_deeply_frozen Sanitize::Config::BASIC
    verify_deeply_frozen Sanitize::Config::RELAXED
    verify_deeply_frozen Sanitize::Config::RESTRICTED
  end

  describe '.freeze_config' do
    it 'should deeply freeze and return a configuration Hash' do
      a = {:one => {:one_one => [0, '1', :a], :one_two => false, :one_three => Set.new([:a, :b, :c])}}
      b = Sanitize::Config.freeze_config(a)

      b.must_be_same_as a
      verify_deeply_frozen a
    end
  end

  describe '.merge' do
    it 'should deeply merge a configuration Hash' do
      # Freeze to ensure that we get an error if either Hash is modified.
      a = Sanitize::Config.freeze_config({:one => {:one_one => [0, '1', :a], :one_two => false, :one_three => Set.new([:a, :b, :c])}})
      b = Sanitize::Config.freeze_config({:one => {:one_two => true, :one_three => 3}, :two => 2})

      c = Sanitize::Config.merge(a, b)

      c.wont_be_same_as a
      c.wont_be_same_as b

      c.must_equal(
        :one => {
          :one_one   => [0, '1', :a],
          :one_two   => true,
          :one_three => 3
        },

        :two => 2
      )

      c[:one].wont_be_same_as a[:one]
      c[:one][:one_one].wont_be_same_as a[:one][:one_one]
    end

    it 'should raise an ArgumentError if either argument is not a Hash' do
      proc { Sanitize::Config.merge('foo', {}) }.must_raise ArgumentError
      proc { Sanitize::Config.merge({}, 'foo') }.must_raise ArgumentError
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/sanitize-6.0.0/test/test_config.rb
sanitize-6.0.0 test/test_config.rb
sanitize-5.2.3 test/test_config.rb
sanitize-5.2.2 test/test_config.rb
sanitize-5.2.1 test/test_config.rb
sanitize-5.2.0 test/test_config.rb
sanitize-5.1.0 test/test_config.rb
sanitize-5.0.0 test/test_config.rb
sanitize-4.6.6 test/test_config.rb
sanitize-4.6.5 test/test_config.rb
sanitize-4.6.4 test/test_config.rb
sanitize-4.6.3 test/test_config.rb
sanitize-4.6.2 test/test_config.rb
sanitize-4.6.1 test/test_config.rb
sanitize-4.6.0 test/test_config.rb
sanitize-4.5.0 test/test_config.rb
sanitize-4.4.0 test/test_config.rb
sanitize-4.3.0 test/test_config.rb
sanitize-4.2.0 test/test_config.rb
sanitize-4.1.0 test/test_config.rb