Sha256: 00d900f428c8b5e4449b19b03cca4a975c9ec8da03f6d72b6b14ee59b6775b0e

Contents?: true

Size: 1.94 KB

Versions: 17

Compression:

Stored size: 1.94 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

17 entries across 17 versions & 3 rubygems

Version Path
simple_form-2.1.3 test/inputs/discovery_test.rb
simple_form-2.1.2 test/inputs/discovery_test.rb
simple_form-2.1.1 test/inputs/discovery_test.rb
simple_form_awesome-2.5.0 test/inputs/discovery_test.rb
simple_form_awesome-2.4.0 test/inputs/discovery_test.rb
simple_form_awesome-2.3.0 test/inputs/discovery_test.rb
simple_form_awesome-2.2.0 test/inputs/discovery_test.rb
simple_form-2.1.0 test/inputs/discovery_test.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.4/test/inputs/discovery_test.rb
simple_form-2.0.4 test/inputs/discovery_test.rb
simple_form-2.0.3 test/inputs/discovery_test.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/test/inputs/discovery_test.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/test/inputs/discovery_test.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/test/inputs/discovery_test.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/test/inputs/discovery_test.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/test/inputs/discovery_test.rb
simple_form-2.0.2 test/inputs/discovery_test.rb