2011-09-03 16:49:54 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class BooleanInputTest < ActionView::TestCase
|
|
|
|
test 'input should generate a checkbox by default for boolean attributes' do
|
|
|
|
with_input_for @user, :active, :boolean
|
|
|
|
assert_select 'input[type=checkbox].boolean#user_active'
|
2012-01-26 13:30:08 +00:00
|
|
|
assert_select 'label.boolean.optional', 'Active'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input does not generate the label with the checkbox when label option is false' do
|
|
|
|
with_input_for @user, :active, :boolean, :label => false
|
|
|
|
assert_select 'input[type=checkbox].boolean#user_active'
|
|
|
|
assert_no_select 'label'
|
|
|
|
end
|
|
|
|
|
2012-01-26 17:06:33 +00:00
|
|
|
test 'input uses inline boolean style by default' do
|
2012-01-26 13:30:08 +00:00
|
|
|
with_input_for @user, :active, :boolean
|
2011-09-03 16:49:54 +00:00
|
|
|
assert_select 'input.boolean + label.boolean.optional'
|
2012-01-26 13:30:08 +00:00
|
|
|
assert_no_select 'label > input'
|
|
|
|
end
|
|
|
|
|
2012-01-26 17:06:33 +00:00
|
|
|
test 'input allows changing default boolean style config to nested, generating a default label' do
|
|
|
|
swap SimpleForm, :boolean_style => :nested do
|
2012-01-26 13:30:08 +00:00
|
|
|
with_input_for @user, :active, :boolean
|
|
|
|
assert_select 'label > input.boolean'
|
|
|
|
assert_no_select 'label.boolean'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-26 17:44:13 +00:00
|
|
|
test 'input accepts changing boolean style to nested through given options' do
|
2012-01-26 17:06:33 +00:00
|
|
|
with_input_for @user, :active, :boolean, :boolean_style => :nested
|
2012-01-26 13:30:08 +00:00
|
|
|
assert_select 'label > input.boolean'
|
|
|
|
assert_no_select 'label.boolean'
|
|
|
|
end
|
|
|
|
|
2012-01-26 17:44:13 +00:00
|
|
|
test 'input accepts changing boolean style to inline through given options, when default is nested' do
|
|
|
|
swap SimpleForm, :boolean_style => :nested do
|
|
|
|
with_input_for @user, :active, :boolean, :boolean_style => :inline
|
|
|
|
assert_select 'input.boolean + label.boolean'
|
|
|
|
assert_no_select 'label > input'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-26 13:30:08 +00:00
|
|
|
test 'input with nested style allows disabling label' do
|
2012-01-26 17:06:33 +00:00
|
|
|
swap SimpleForm, :boolean_style => :nested do
|
2012-01-26 13:30:08 +00:00
|
|
|
with_input_for @user, :active, :boolean, :label => false
|
|
|
|
assert_select 'input.boolean'
|
|
|
|
assert_no_select 'label'
|
|
|
|
end
|
2011-09-03 16:49:54 +00:00
|
|
|
end
|
2012-01-26 12:51:12 +00:00
|
|
|
end
|