Defaults passed to simple_form_for should propagate to input_field
This commit is contained in:
parent
602c634dd6
commit
6d42a0d5b2
|
@ -134,6 +134,8 @@ module SimpleForm
|
||||||
def input_field(attribute_name, options={})
|
def input_field(attribute_name, options={})
|
||||||
options = options.dup
|
options = options.dup
|
||||||
options[:input_html] = options.except(:as, :collection, :label_method, :value_method)
|
options[:input_html] = options.except(:as, :collection, :label_method, :value_method)
|
||||||
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
||||||
|
|
||||||
SimpleForm::Wrappers::Root.new([:input], :wrapper => false).render find_input(attribute_name, options)
|
SimpleForm::Wrappers::Root.new([:input], :wrapper => false).render find_input(attribute_name, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -306,49 +306,65 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
# DEFAULT OPTIONS
|
# DEFAULT OPTIONS
|
||||||
test 'builder should receive a default argument and pass it to the inputs' do
|
[:input, :input_field].each do |method|
|
||||||
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
test "builder should receive a default argument and pass it to the inputs when calling '#{method}'" do
|
||||||
f.input :name
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
||||||
|
f.send(method, :name)
|
||||||
|
end
|
||||||
|
assert_select 'input.default_class'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "builder should receive a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
|
||||||
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
||||||
|
concat(f.send(method, :name))
|
||||||
|
concat(f.send(method, :credit_limit))
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select "input.string.default_class[name='user[name]']"
|
||||||
|
assert_no_select "input.string[name='user[credit_limit]']"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "builder should receive a default argument and pass it to the inputs and nested form when calling '#{method}'" do
|
||||||
|
@user.company = Company.new(1, 'Empresa')
|
||||||
|
|
||||||
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
||||||
|
concat(f.send(method, :name))
|
||||||
|
concat(f.simple_fields_for(:company) do |company_form|
|
||||||
|
concat(company_form.send(method, :name))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select "input.string.default_class[name='user[name]']"
|
||||||
|
assert_select "input.string.default_class[name='user[company_attributes][name]']"
|
||||||
end
|
end
|
||||||
assert_select 'input.default_class'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder should receive a default argument and pass it to the inputs, respecting the specific options' do
|
test "builder should receive a default argument and pass it to the inputs when calling 'input', respecting the specific options" do
|
||||||
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
||||||
f.input :name, :input_html => { :id => 'specific_id' }
|
f.input :name, :input_html => { :id => 'specific_id' }
|
||||||
end
|
end
|
||||||
assert_select 'input.default_class#specific_id'
|
assert_select 'input.default_class#specific_id'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder should receive a default argument and pass it to the inputs, overwriting the defaults with specific options' do
|
test "builder should receive a default argument and pass it to the inputs when calling 'input_field', respecting the specific options" do
|
||||||
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
||||||
|
f.input_field :name, :id => 'specific_id'
|
||||||
|
end
|
||||||
|
assert_select 'input.default_class#specific_id'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "builder should receive a default argument and pass it to the inputs when calling 'input', overwriting the defaults with specific options" do
|
||||||
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
||||||
f.input :name, :input_html => { :id => 'specific_id' }
|
f.input :name, :input_html => { :id => 'specific_id' }
|
||||||
end
|
end
|
||||||
assert_select 'input.default_class#specific_id'
|
assert_select 'input.default_class#specific_id'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder should receive a default argument and pass it to the inputs without changing the defaults' do
|
test "builder should receive a default argument and pass it to the inputs when calling 'input_field', overwriting the defaults with specific options" do
|
||||||
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
||||||
concat(f.input :name)
|
f.input_field :name, :id => 'specific_id'
|
||||||
concat(f.input :credit_limit)
|
|
||||||
end
|
end
|
||||||
|
assert_select 'input.default_class#specific_id'
|
||||||
assert_select "input.string.default_class[name='user[name]']"
|
|
||||||
assert_no_select "input.string[name='user[credit_limit]']"
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'builder should receive a default argument and pass it to the inputs and nested form' do
|
|
||||||
@user.company = Company.new(1, 'Empresa')
|
|
||||||
|
|
||||||
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
|
|
||||||
concat(f.input :name)
|
|
||||||
concat(f.simple_fields_for(:company) do |company_form|
|
|
||||||
concat(company_form.input :name)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_select "input.string.default_class[name='user[name]']"
|
|
||||||
assert_select "input.string.default_class[name='user[company_attributes][name]']"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# WITHOUT OBJECT
|
# WITHOUT OBJECT
|
||||||
|
|
Loading…
Reference in New Issue