2011-09-03 12:49:54 -04:00
|
|
|
# encoding: UTF-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
2012-01-26 14:00:56 -05:00
|
|
|
class CollectionSelectInputTest < ActionView::TestCase
|
2011-09-03 12:49:54 -04:00
|
|
|
setup do
|
2012-01-26 14:00:56 -05:00
|
|
|
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should generate a boolean select with options by default for select types' do
|
|
|
|
with_input_for @user, :active, :select
|
|
|
|
assert_select 'select.select#user_active'
|
|
|
|
assert_select 'select option[value=true]', 'Yes'
|
|
|
|
assert_select 'select option[value=false]', 'No'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input as select should use i18n to translate select boolean options' do
|
2013-01-28 16:02:59 -05:00
|
|
|
store_translations(:en, simple_form: { yes: 'Sim', no: 'Não' }) do
|
2011-09-03 12:49:54 -04:00
|
|
|
with_input_for @user, :active, :select
|
|
|
|
assert_select 'select option[value=true]', 'Sim'
|
|
|
|
assert_select 'select option[value=false]', 'Não'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow overriding collection for select types' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.select#user_name'
|
|
|
|
assert_select 'select option', 'Jose'
|
|
|
|
assert_select 'select option', 'Carlos'
|
|
|
|
end
|
|
|
|
|
2012-01-24 12:04:37 -05:00
|
|
|
test 'input should do automatic collection translation for select 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-24 12:04:37 -05:00
|
|
|
} } } ) do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :select, collection: [:male, :female]
|
2012-01-24 12:04:37 -05:00
|
|
|
assert_select 'select.select#user_gender'
|
|
|
|
assert_select 'select option', 'Male'
|
|
|
|
assert_select 'select option', 'Female'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should do automatic collection translation for select 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-24 12:04:37 -05:00
|
|
|
} } } ) do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :gender, :select, collection: [:male, :female]
|
2011-10-03 20:07:40 -04:00
|
|
|
assert_select 'select.select#user_gender'
|
|
|
|
assert_select 'select option', 'Male'
|
|
|
|
assert_select 'select option', 'Female'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-03 12:49:54 -04:00
|
|
|
test 'input should mark the selected value by default' do
|
|
|
|
@user.name = "Carlos"
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[selected=selected]', 'Carlos'
|
|
|
|
end
|
|
|
|
|
2013-06-18 15:55:27 -04:00
|
|
|
test 'input should accept html options as the last element of collection' do
|
|
|
|
with_input_for @user, :name, :select, collection: [['Jose', class: 'foo']]
|
|
|
|
assert_select 'select.select#user_name'
|
|
|
|
assert_select 'select option.foo', 'Jose'
|
|
|
|
end
|
|
|
|
|
2011-09-03 12:49:54 -04:00
|
|
|
test 'input should mark the selected value also when using integers' do
|
|
|
|
@user.age = 18
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..60
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[selected=selected]', '18'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should mark the selected value when using booleans and select' do
|
|
|
|
@user.active = false
|
|
|
|
with_input_for @user, :active, :select
|
|
|
|
assert_no_select 'select option[selected][value=true]', 'Yes'
|
|
|
|
assert_select 'select option[selected][value=false]', 'No'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should set the correct value when using a collection that includes floats' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value="2.0"]'
|
|
|
|
assert_select 'select option[value="2.5"]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should set the correct values when using a collection that uses mixed values' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value="Hello Kitty"]'
|
|
|
|
assert_select 'select option[value="2"]'
|
|
|
|
assert_select 'select option[value="4.5"]'
|
|
|
|
assert_select 'select option[value="johnny"]'
|
|
|
|
assert_select 'select option[value=""]'
|
|
|
|
assert_select 'select option[value="true"]'
|
|
|
|
assert_select 'select option[value="false"]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should include a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: [nil], include_blank: false
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=""]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should automatically set include blank' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
|
2013-02-06 05:42:20 -05:00
|
|
|
test 'input should translate include blank when set to :translate' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
|
|
age: 'Rather not say'
|
2014-04-03 14:22:09 -04:00
|
|
|
} } }) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', 'Rather not say'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-03 14:22:09 -04:00
|
|
|
test 'input should translate include blank with a default' do
|
|
|
|
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
2013-02-06 06:40:27 -05:00
|
|
|
age: 'Rather not say',
|
2014-04-03 14:22:09 -04:00
|
|
|
} } }) do
|
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
2013-02-06 06:06:38 -05:00
|
|
|
assert_select 'select option[value=]', 'Rather not say'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 05:42:20 -05:00
|
|
|
test 'input should not translate include blank when set to a string' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
|
|
age: 'Rather not say'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: 'Young at heart'
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', 'Young at heart'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not translate include blank when automatically set' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
|
|
age: 'Rather not say'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not translate include blank when set to true' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
|
|
age: 'Rather not say'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: true
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not translate include blank when set to false' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { include_blanks: { user: {
|
|
|
|
age: 'Rather not say'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_no_select 'select option[value=]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-03 12:49:54 -04:00
|
|
|
test 'input should not set include blank if otherwise is told' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: false
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_no_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not set include blank if prompt is given' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_no_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not set include blank if multiple is given' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, input_html: { multiple: true }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_no_select 'select option[value=]', ''
|
|
|
|
end
|
|
|
|
|
2013-02-06 05:42:20 -05:00
|
|
|
test 'input should translate prompt when set to :translate' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { prompts: { user: {
|
|
|
|
age: 'Select age:'
|
2014-04-03 14:22:09 -04:00
|
|
|
} } }) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', 'Select age:'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-03 14:22:09 -04:00
|
|
|
test 'input should translate prompt with a default' do
|
|
|
|
store_translations(:en, simple_form: { prompts: { defaults: {
|
2013-02-06 06:40:27 -05:00
|
|
|
age: 'Select age:',
|
2014-04-03 14:22:09 -04:00
|
|
|
} } }) do
|
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
2013-02-06 06:06:38 -05:00
|
|
|
assert_select 'select option[value=]', 'Select age:'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 05:42:20 -05:00
|
|
|
test 'input should not translate prompt when set to a string' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { prompts: { user: {
|
|
|
|
age: 'Select age:'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: 'Do it:'
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', 'Do it:'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not translate prompt when set to false' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, simple_form: { prompts: { user: {
|
|
|
|
age: 'Select age:'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: false
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_no_select 'select option[value=]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should use Rails prompt translation as a fallback' do
|
2013-02-06 06:40:27 -05:00
|
|
|
store_translations(:en, helpers: { select: {
|
|
|
|
prompt: 'Select value:'
|
2013-02-06 05:42:20 -05:00
|
|
|
} } ) do
|
2013-02-06 06:40:27 -05:00
|
|
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
2013-02-06 05:42:20 -05:00
|
|
|
assert_select 'select option[value=]', "Select value:"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-03 12:49:54 -04:00
|
|
|
test 'input should detect label and value on collections' do
|
2013-06-24 14:41:58 -04:00
|
|
|
users = [User.build(id: 1, name: "Jose"), User.build(id: 2, name: "Carlos")]
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :select, collection: users
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=1]', 'Jose'
|
|
|
|
assert_select 'select option[value=2]', 'Carlos'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should disable the anothers components when the option is a object' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
|
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
|
|
assert_select 'select[disabled=disabled]'
|
|
|
|
assert_select 'div.disabled'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should not disable the anothers components when the option is a object' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
|
|
|
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
|
|
assert_no_select 'select[disabled=disabled]'
|
|
|
|
assert_no_select 'div.disabled'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow overriding label and value method using a lambda for collection selects' do
|
|
|
|
with_input_for @user, :name, :select,
|
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 }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=jose]', "JOSE"
|
|
|
|
assert_select 'select option[value=carlos]', "CARLOS"
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow overriding only label but not value method using a lambda for collection select' do
|
|
|
|
with_input_for @user, :name, :select,
|
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 }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Jose]', "JOSE"
|
|
|
|
assert_select 'select option[value=Carlos]', "CARLOS"
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow overriding only value but not label method using a lambda for collection select' do
|
|
|
|
with_input_for @user, :name, :select,
|
2013-04-13 18:50:14 -04:00
|
|
|
collection: ['Jose', 'Carlos'],
|
2013-01-28 16:02:59 -05:00
|
|
|
value_method: lambda { |i| i.downcase }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=jose]', "Jose"
|
|
|
|
assert_select 'select option[value=carlos]', "Carlos"
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow symbols for collections' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: [:jose, :carlos]
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.select#user_name'
|
|
|
|
assert_select 'select option[value=jose]', 'jose'
|
|
|
|
assert_select 'select option[value=carlos]', 'carlos'
|
|
|
|
end
|
|
|
|
|
2011-12-01 13:40:01 -05:00
|
|
|
test 'collection input with select type should generate required html attribute only with blank option' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
2011-12-01 13:40:01 -05:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[required]'
|
|
|
|
end
|
|
|
|
|
2013-11-03 06:19:52 -05:00
|
|
|
test 'collection input with select type should generate required html attribute only with blank option or prompt' do
|
|
|
|
with_input_for @user, :name, :select, prompt: 'Name...', collection: ['Jose', 'Carlos']
|
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[required]'
|
|
|
|
end
|
|
|
|
|
2011-12-01 13:40:01 -05:00
|
|
|
test 'collection input with select type should not generate required html attribute without blank option' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_no_select 'select[required]'
|
2013-04-07 13:57:07 -04:00
|
|
|
assert_no_select 'select[aria-required=true]'
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|
|
|
|
|
2011-12-01 13:40:01 -05:00
|
|
|
test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
2011-12-01 13:40:01 -05:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[required]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'collection input with select type with multiple attribute should generate required html attribute with blank option' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
2011-12-01 13:40:01 -05:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[required]'
|
|
|
|
end
|
|
|
|
|
2013-04-07 13:57:07 -04:00
|
|
|
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
2013-04-07 13:57:07 -04:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[aria-required=true]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
2013-04-07 13:57:07 -04:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_no_select 'select[aria-required]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
2013-04-07 13:57:07 -04:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[aria-required=true]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
|
2013-04-13 18:50:14 -04:00
|
|
|
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
2013-04-07 13:57:07 -04:00
|
|
|
assert_select 'select.required'
|
|
|
|
assert_select 'select[aria-required]'
|
|
|
|
end
|
|
|
|
|
2011-09-03 12:49:54 -04:00
|
|
|
test 'input should allow disabled options with a lambda for collection select' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
disabled: lambda { |x| x == "Carlos" }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
|
|
|
assert_select 'select option[value=Antonio]', 'Antonio'
|
|
|
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow disabled and label method with lambdas for collection select' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
|
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
|
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow a non lambda disabled option with lambda label method for collections' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
disabled: "Carlos", label_method: lambda { |x| x.upcase }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
|
|
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
|
|
assert_no_select 'select option[value=Antonio][disabled]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow selected and label method with lambdas for collection select' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
|
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
|
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'input should allow a non lambda selected option with lambda label method for collection select' do
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
selected: "Carlos", label_method: lambda { |x| x.upcase }
|
2011-09-03 12:49:54 -04:00
|
|
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
|
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
|
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
|
|
end
|
2011-09-15 19:17:23 -04:00
|
|
|
|
|
|
|
test 'input should not override default selection through attribute value with label method as lambda for collection select' do
|
|
|
|
@user.name = "Carlos"
|
2013-01-28 16:02:59 -05:00
|
|
|
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
|
|
|
label_method: lambda { |x| x.upcase }
|
2011-09-15 19:17:23 -04:00
|
|
|
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
|
|
|
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
|
|
|
assert_no_select 'select option[value=Antonio][selected]'
|
|
|
|
end
|
2011-09-03 12:49:54 -04:00
|
|
|
end
|