Add more tests for grouped collection select

This commit is contained in:
Carlos Antonio da Silva 2012-01-24 11:39:45 -02:00
parent e68094e652
commit 03103ac344
2 changed files with 52 additions and 4 deletions

View File

@ -27,7 +27,7 @@ module SimpleForm
label = options.delete(:group_label_method)
unless label
common_method_for = detect_common_display_methods( detect_collection_classes(group_collection) )
common_method_for = detect_common_display_methods(detect_collection_classes(group_collection))
label = common_method_for[:label]
end

View File

@ -2,10 +2,11 @@
require 'test_helper'
class GroupedCollectionInputTest < ActionView::TestCase
test 'input should have grouped options' do
test 'grouped collection accepts array collection form' do
with_input_for @user, :name, :grouped_select,
:collection => [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
:group_method => :last
:collection => [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
:group_method => :last
assert_select 'select.grouped_select#user_name' do
assert_select 'optgroup[label=Authors]' do
assert_select 'option', 'Jose'
@ -18,4 +19,51 @@ class GroupedCollectionInputTest < ActionView::TestCase
end
end
end
test 'grouped collection accepts hash collection form' do
with_input_for @user, :name, :grouped_select,
:collection => { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
:group_method => :last
assert_select 'select.grouped_select#user_name' do
assert_select 'optgroup[label=Authors]' do
assert_select 'option', 'Jose'
assert_select 'option', 'Carlos'
end
assert_select 'optgroup[label=General]' do
assert_select 'option', 'Bob'
assert_select 'option', 'John'
end
end
end
test 'grouped collection accepts group_label_method option' do
with_input_for @user, :name, :grouped_select,
:collection => { ['Jose', 'Carlos'] => 'Authors' },
:group_method => :first,
:group_label_method => :last
assert_select 'select.grouped_select#user_name' do
assert_select 'optgroup[label=Authors]' do
assert_select 'option', 'Jose'
assert_select 'option', 'Carlos'
end
end
end
test 'grouped collection accepts label and value methods options' do
with_input_for @user, :name, :grouped_select,
:collection => { 'Authors' => ['Jose', 'Carlos'] },
:group_method => :last,
:label_method => :upcase,
:value_method => :downcase
assert_select 'select.grouped_select#user_name' do
assert_select 'optgroup[label=Authors]' do
assert_select 'option[value=jose]', 'JOSE'
assert_select 'option[value=carlos]', 'CARLOS'
end
end
end
end