2012-01-26 14:06:59 -05:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
2012-01-27 13:30:19 -05:00
|
|
|
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
2012-01-26 14:06:59 -05:00
|
|
|
setup do
|
2012-01-27 13:30:19 -05:00
|
|
|
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input generates boolean radio buttons by default for radio types' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
|
|
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
|
|
|
assert_select 'input[type=radio][value=false].radio_buttons#user_active_false'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input as radio generates internal labels by default' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'label[for=user_active_true]', 'Yes'
|
|
|
|
assert_select 'label[for=user_active_false]', 'No'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input as radio generates internal labels with accurate `for` values with nested boolean style' do
|
2013-12-06 05:22:39 -05:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
with_input_for @user, :active, :radio_buttons
|
|
|
|
assert_select 'label[for=user_active_true]', 'Yes'
|
|
|
|
assert_select 'label[for=user_active_false]', 'No'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'nested label does not duplicate input id' do
|
2014-03-26 21:16:40 -04:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
with_input_for @user, :active, :radio_buttons, id: 'nested_id'
|
|
|
|
assert_select 'input#user_active_true'
|
|
|
|
assert_no_select 'label#user_active_true'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input as radio uses i18n to translate internal labels' do
|
2013-01-28 16:02:59 -05:00
|
|
|
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'label[for=user_active_true]', 'Sim'
|
|
|
|
assert_select 'label[for=user_active_false]', 'Não'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input radio does not include for attribute by default' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
2012-01-26 16:30:45 -05:00
|
|
|
assert_select 'label'
|
|
|
|
assert_no_select 'label[for=user_gender]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input radio includes for attribute when giving as html option' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], label_html: { for: 'gender' }
|
2012-01-26 16:30:45 -05:00
|
|
|
assert_select 'label[for=gender]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input marks the checked value when using boolean and radios' do
|
2012-01-26 14:06:59 -05:00
|
|
|
@user.active = false
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'input[type=radio][value=true][checked]'
|
|
|
|
assert_select 'input[type=radio][value=false][checked]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows overriding collection for radio types' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=Jose]'
|
|
|
|
assert_select 'input[type=radio][value=Carlos]'
|
2013-11-18 15:01:00 -05:00
|
|
|
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
|
|
|
assert_select 'label.collection_radio_buttons[for=user_name_carlos]', 'Carlos'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input does automatic collection translation for radio types using defaults key' do
|
2013-01-28 16:02:59 -05:00
|
|
|
store_translations(:en, simple_form: { options: { defaults: {
|
|
|
|
gender: { male: 'Male', female: 'Female'}
|
2012-01-26 14:06:59 -05:00
|
|
|
} } } ) do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=male]'
|
|
|
|
assert_select 'input[type=radio][value=female]'
|
2013-11-18 15:01:00 -05:00
|
|
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
|
|
|
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input does automatic collection translation for radio types using specific object key' do
|
2013-01-28 16:02:59 -05:00
|
|
|
store_translations(:en, simple_form: { options: { user: {
|
|
|
|
gender: { male: 'Male', female: 'Female'}
|
2012-01-26 14:06:59 -05:00
|
|
|
} } } ) do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=male]'
|
|
|
|
assert_select 'input[type=radio][value=female]'
|
2013-11-18 15:01:00 -05:00
|
|
|
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
|
|
|
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input does automatic collection translation and preserve html markup' do
|
2014-04-04 13:49:18 -04:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
store_translations(:en, simple_form: { options: { user: {
|
|
|
|
gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
|
|
|
|
} } } ) do
|
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
|
|
assert_select 'input[type=radio][value=male]'
|
|
|
|
assert_select 'input[type=radio][value=female]'
|
2014-07-10 13:09:15 -04:00
|
|
|
assert_select 'label[for=user_gender_male] strong', 'Male'
|
|
|
|
assert_select 'label[for=user_gender_female] strong', 'Female'
|
2014-04-04 13:49:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input does automatic collection translation with keys prefixed with _html and a string value' do
|
2014-04-04 16:14:39 -04:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
store_translations(:en, simple_form: { options: { user: {
|
|
|
|
gender: { male_html: 'Male', female_html: 'Female' }
|
|
|
|
} } } ) do
|
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
|
|
assert_select 'input[type=radio][value=male]'
|
|
|
|
assert_select 'input[type=radio][value=female]'
|
|
|
|
assert_select 'label[for=user_gender_male]', 'Male'
|
|
|
|
assert_select 'label[for=user_gender_female]', 'Female'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input marks the current radio value by default' do
|
2012-01-26 14:06:59 -05:00
|
|
|
@user.name = "Carlos"
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input accepts html options as the last element of collection' do
|
2013-06-18 15:55:27 -04:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose', class: 'foo']]
|
|
|
|
assert_select 'input.foo[type=radio][value=jose]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows using a collection with text/value arrays' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose'], ['Carlos', 'carlos']]
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=jose]'
|
|
|
|
assert_select 'input[type=radio][value=carlos]'
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
|
|
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows using a collection with a Proc' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: Proc.new { ['Jose', 'Carlos' ] }
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_select 'label.collection_radio_buttons', 'Jose'
|
|
|
|
assert_select 'label.collection_radio_buttons', 'Carlos'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows overriding only label method for collections' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons,
|
2013-04-13 18:50:14 -04:00
|
|
|
collection: ['Jose', 'Carlos'],
|
2013-01-28 16:02:59 -05:00
|
|
|
label_method: :upcase
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
|
|
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows overriding only value method for collections' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons,
|
2013-04-13 18:50:14 -04:00
|
|
|
collection: ['Jose', 'Carlos'],
|
2013-01-28 16:02:59 -05:00
|
|
|
value_method: :upcase
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=JOSE]'
|
|
|
|
assert_select 'input[type=radio][value=CARLOS]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows overriding label and value method for collections' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons,
|
2013-04-13 18:50:14 -04:00
|
|
|
collection: ['Jose', 'Carlos'],
|
2013-01-28 16:02:59 -05:00
|
|
|
label_method: :upcase,
|
|
|
|
value_method: :downcase
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=jose]'
|
|
|
|
assert_select 'input[type=radio][value=carlos]'
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
|
|
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'input allows overriding label and value method using a lambda for collections' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :name, :radio_buttons,
|
2013-04-13 18:50:14 -04:00
|
|
|
collection: ['Jose', 'Carlos'],
|
2013-01-28 16:02:59 -05:00
|
|
|
label_method: lambda { |i| i.upcase },
|
|
|
|
value_method: lambda { |i| i.downcase }
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio][value=jose]'
|
|
|
|
assert_select 'input[type=radio][value=carlos]'
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
|
|
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'collection input with radio type generates required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_select 'input[type=radio].required'
|
|
|
|
assert_select 'input[type=radio][required]'
|
|
|
|
end
|
|
|
|
|
2014-05-14 13:19:06 -04:00
|
|
|
test 'collection input with radio type generates aria-required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
2013-04-07 13:54:45 -04:00
|
|
|
assert_select 'input[type=radio].required'
|
|
|
|
assert_select 'input[type=radio][aria-required=true]'
|
|
|
|
end
|
|
|
|
|
2012-01-26 14:06:59 -05:00
|
|
|
test 'input radio does not wrap the collection by default' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form ul'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio wraps the collection in the configured collection wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form ul input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio does not wrap the collection when configured with falsy values' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: false do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form ul'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows overriding the collection wrapper tag at input level' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
|
|
with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: :section
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form section input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form ul'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows disabling the collection wrapper tag at input level' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
|
|
with_input_for @user, :active, :radio_buttons, collection_wrapper_tag: false
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form ul'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio renders the wrapper tag with the configured wrapper class' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form ul.inputs-list input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows giving wrapper class at input level only' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul do
|
|
|
|
with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form ul.items-list input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio uses both configured and given wrapper classes for wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, collection_wrapper_tag: :ul, collection_wrapper_class: 'inputs-list' do
|
|
|
|
with_input_for @user, :active, :radio_buttons, collection_wrapper_class: 'items-list'
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form ul.inputs-list.items-list input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio wraps each item in the configured item wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :li do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form li input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio does not wrap items when configured with falsy values' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: false do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form li'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows overriding the item wrapper tag at input level' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :li do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :dl
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form dl input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form li'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows disabling the item wrapper tag at input level' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :ul do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: false
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
assert_no_select 'form li'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio wraps items in a span tag by default' do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form span input[type=radio]', count: 2
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
|
2012-01-27 14:42:01 -05:00
|
|
|
test 'input radio renders the item wrapper tag with a default class "radio"' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form li.radio input[type=radio]', count: 2
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio renders the item wrapper tag with the configured item wrapper class' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
2012-01-27 14:42:01 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form li.radio.item input[type=radio]', count: 2
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio allows giving item wrapper class at input level only' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :li do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'item'
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form li.radio.item input[type=radio]', count: 2
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio uses both configured and given item wrapper classes for item wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, item_wrapper_tag: :li, item_wrapper_class: 'item' do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_class: 'inline'
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-01-28 16:02:59 -05:00
|
|
|
assert_select 'form li.radio.item.inline input[type=radio]', count: 2
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-26 14:06:59 -05:00
|
|
|
test 'input radio respects the nested boolean style config, generating nested label > input' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
2012-01-27 13:30:19 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
2012-01-26 14:06:59 -05:00
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
assert_select 'span.radio > label > input#user_active_true[type=radio]'
|
|
|
|
assert_select 'span.radio > label', 'Yes'
|
|
|
|
assert_select 'span.radio > label > input#user_active_false[type=radio]'
|
|
|
|
assert_select 'span.radio > label', 'No'
|
2012-01-27 13:30:19 -05:00
|
|
|
assert_no_select 'label.collection_radio_buttons'
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|
|
|
|
end
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
test 'input radio with nested style does not overrides configured item wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: :li do
|
2012-01-27 14:42:01 -05:00
|
|
|
with_input_for @user, :active, :radio_buttons
|
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
assert_select 'li.radio > label > input'
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
test 'input radio with nested style does not overrides given item wrapper tag' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_tag: :li
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
assert_select 'li.radio > label > input'
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio with nested style accepts giving extra wrapper classes' do
|
2013-01-28 16:02:59 -05:00
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_wrapper_class: "inline"
|
2012-01-27 14:42:01 -05:00
|
|
|
|
2013-11-26 17:53:51 -05:00
|
|
|
assert_select 'span.radio.inline > label > input'
|
2012-01-27 14:42:01 -05:00
|
|
|
end
|
|
|
|
end
|
2013-11-12 17:18:52 -05:00
|
|
|
|
2014-05-07 02:35:07 -04:00
|
|
|
test 'input radio with nested style renders item labels with specified class' do
|
|
|
|
swap SimpleForm, boolean_style: :nested do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_label_class: "test"
|
|
|
|
|
|
|
|
assert_select 'span.radio > label.test > input'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio with nested style and falsey input wrapper renders item labels with specified class' do
|
|
|
|
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
|
|
|
with_input_for @user, :active, :radio_buttons, item_label_class: "radio-inline"
|
|
|
|
|
|
|
|
assert_select 'label.radio-inline > input'
|
|
|
|
assert_no_select 'span.radio'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 17:18:52 -05:00
|
|
|
test 'input radio wrapper class are not included when set to falsey' do
|
|
|
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
|
|
|
|
|
|
|
assert_no_select 'label.radio'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-25 14:59:32 -05:00
|
|
|
test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
|
2013-11-12 17:18:52 -05:00
|
|
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
|
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
|
|
|
|
|
|
|
|
assert_no_select 'label.radio'
|
2013-12-09 08:11:50 -05:00
|
|
|
assert_select 'span.custom'
|
2013-11-12 17:18:52 -05:00
|
|
|
end
|
|
|
|
end
|
2014-11-25 14:59:32 -05:00
|
|
|
|
|
|
|
test 'input radio with nested style and namespace uses the right for attribute' do
|
|
|
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
|
|
with_concat_form_for @user, namespace: :foo do |f|
|
|
|
|
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_select 'label[for=foo_user_gender_male]'
|
|
|
|
assert_select 'label[for=foo_user_gender_female]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input radio with nested style and index uses the right for attribute' do
|
|
|
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
|
|
|
with_concat_form_for @user, index: 1 do |f|
|
|
|
|
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_select 'label[for=user_1_gender_male]'
|
|
|
|
assert_select 'label[for=user_1_gender_female]'
|
|
|
|
end
|
|
|
|
end
|
2012-01-26 14:06:59 -05:00
|
|
|
end
|