2011-09-03 11:45:07 -04:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class DiscoveryTest < ActionView::TestCase
|
|
|
|
# Setup new inputs and remove them after the test.
|
|
|
|
def discovery(value=false)
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, cache_discovery: value do
|
2011-09-03 11:45:07 -04:00
|
|
|
begin
|
2011-09-03 12:49:54 -04:00
|
|
|
load "support/discovery_inputs.rb"
|
2011-09-03 11:45:07 -04:00
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
SimpleForm::FormBuilder.discovery_cache.clear
|
|
|
|
Object.send :remove_const, :StringInput
|
|
|
|
Object.send :remove_const, :NumericInput
|
|
|
|
Object.send :remove_const, :CustomizedInput
|
2012-04-21 22:21:36 -04:00
|
|
|
Object.send :remove_const, :CollectionSelectInput
|
2011-09-03 11:45:07 -04:00
|
|
|
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
|
2013-01-28 16:02:59 -05:00
|
|
|
with_form_for @user, :name, as: :customized
|
2011-09-03 11:45:07 -04:00
|
|
|
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'
|
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, inputs_discovery: false do
|
2011-09-03 11:45:07 -04:00
|
|
|
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
|
2012-04-21 22:21:36 -04:00
|
|
|
|
|
|
|
test 'new inputs can override the input_html_options' do
|
|
|
|
discovery do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_form_for @user, :active, as: :select
|
2012-04-21 22:21:36 -04:00
|
|
|
assert_select 'form select#user_active.select.chosen'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|