Sha256: a80b2a31fe26ce466972be5b2638139a1800d64805d4c4fac1451046dd5a4339

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

module PushType
  class SelectFieldTest < ActiveSupport::TestCase

    let(:field) { PushType::SelectField.new :foo, opts }
    let(:val)   { 'a' }

    describe 'default' do
      let(:opts) { {} }
      it { field.template.must_equal 'select' }
      it { field.multiple?.must_equal false }
      it { field.param.must_equal :foo }
      it { field.choices.must_equal [] }
      it { field.field_options.must_be_instance_of Hash }
      it { field.field_options.keys.must_include :include_blank }
      it { field.html_options.keys.must_include :multiple }
      it { field.to_json(val).must_equal val }
      it { field.from_json(val).must_equal val }
    end

    describe 'with options' do
      let(:opts) { { choices: ['a', 'b'], multiple: true } }
      let(:val)   { ['a', 'b'] }
      it { field.multiple?.must_equal true }
      it { field.choices.must_equal ['a', 'b'] }
      it { field.to_json(val).must_be_instance_of Array }
      it { field.to_json(val)[0].must_equal 'a' }
      it { field.from_json(val).must_be_instance_of Array }
      it { field.from_json(val)[0].must_equal 'a' }
    end

    describe 'with choices as proc' do
      let(:opts) { { choices: -> { [1,2,3] } } }
      it { field.choices.must_equal [1,2,3] }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
push_type_core-0.5.3 test/fields/push_type/select_field_test.rb
push_type_core-0.5.2 test/fields/push_type/select_field_test.rb