Sha256: b8d997f0d1c8afe38916d0ec7cc293dd24b4772bf13222369ef7bd6c1913f7eb

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

class DiscoveryTest < ActionView::TestCase
  # Setup new inputs and remove them after the test.
  def discovery(value=false)
    swap SimpleForm, cache_discovery: value do
      begin
        load "support/discovery_inputs.rb"
        yield
      ensure
        SimpleForm::FormBuilder.discovery_cache.clear
        Object.send :remove_const, :StringInput
        Object.send :remove_const, :NumericInput
        Object.send :remove_const, :CustomizedInput
        Object.send :remove_const, :CollectionSelectInput
      end
    end
  end

  test 'builder should not discover new inputs if cached' do
    with_form_for @user, :name
    assert_select 'form input#user_name.string'

    discovery(true) do
      with_form_for @user, :name
      assert_no_select 'form section input#user_name.string'
    end
  end

  test 'builder should discover new inputs' do
    discovery do
      with_form_for @user, :name, as: :customized
      assert_select 'form section input#user_name.string'
    end
  end

  test 'builder should not discover new inputs if discovery is off' do
    with_form_for @user, :name
    assert_select 'form input#user_name.string'

    swap SimpleForm, inputs_discovery: false do
      discovery do
        with_form_for @user, :name
        assert_no_select 'form section input#user_name.string'
      end
    end
  end

  test 'builder should discover new inputs from mappings if not cached' do
    discovery do
      with_form_for @user, :name
      assert_select 'form section input#user_name.string'
    end
  end

  test 'builder should discover new inputs from internal fallbacks if not cached' do
    discovery do
      with_form_for @user, :age
      assert_select 'form section input#user_age.numeric.integer'
    end
  end

  test 'new inputs can override the input_html_options' do
    discovery do
      with_form_for @user, :active, as: :select
      assert_select 'form select#user_active.select.chosen'
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple_form-3.0.4 test/inputs/discovery_test.rb
simple_form-3.0.3 test/inputs/discovery_test.rb
simple_form-3.0.2 test/inputs/discovery_test.rb
simple_form-3.0.1 test/inputs/discovery_test.rb
simple_form-3.0.0 test/inputs/discovery_test.rb
simple_form-3.0.0.rc test/inputs/discovery_test.rb
simple_form-3.0.0.beta1 test/inputs/discovery_test.rb