Sha256: 3ea464fff4ede06fd4ed5d6d7d2a837e1761b2a0558b20ff5e85a5a34dd86f81

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'

module Workarea
  module Configuration
    class ParamsTest < TestCase
      def test_to_h
        Workarea.config.admin_definition = Administrable::Definition.new
        Workarea::Configuration.define_fields do
          field 'foo', type: :string
          field 'bar', type: :string, default: 'test'
          field 'baz', type: :string, allow_blank: true

          field 'foo_hash', type: :hash, values_type: :integer
          field 'foo_array', type: :array, values_type: :integer
          field 'bar_array', type: :array
          field 'baz_duration', type: :duration
        end

        params = {
          foo: 'string value',
          bar: nil,
          baz: '',
          foo_hash: ['one', '1', 'two', '', '', ''],
          foo_array: '1,2,3',
          bar_array: 'one, two, three',
          baz_duration: %w(20 minutes)
        }

        result = Params.new(params).to_h
        assert_equal('string value', result[:foo])
        assert_equal('test', result[:bar])
        assert_equal('', result[:baz])
        assert_equal({ 'one' => 1 }, result[:foo_hash])
        assert_equal([1, 2, 3], result[:foo_array])
        assert_equal(%w(one two three), result[:bar_array])
        assert_equal(20.minutes, result[:baz_duration])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.26 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.25 test/models/workarea/configuration/params_test.rb