Sha256: a216e93af61ee9401871a8af884cbbac1e40f6d7e287110ea9ad9243a887f53e

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 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 'bar_array', type: :array
          field 'baz_duration', type: :duration
        end

        params = {
          foo: 'string value',
          bar: nil,
          baz: '',
          foo_hash: ['one', '1', 'two', '', '', ''],
          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(%w(one two three), result[:bar_array])
        assert_equal(20.minutes, result[:baz_duration])
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
workarea-core-3.5.23 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.22 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.21 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.20 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.19 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.18 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.17 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.16 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.15 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.14 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.13 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.12 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.11 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.10 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.9 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.8 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.7 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.6 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.5 test/models/workarea/configuration/params_test.rb
workarea-core-3.5.4 test/models/workarea/configuration/params_test.rb