can use blank collection with grouped_collection input, closes #430

This commit is contained in:
Vasiliy Ermolovich 2012-02-03 22:17:40 +03:00
parent f67bdbb122
commit beb5158d1f
2 changed files with 10 additions and 1 deletions

View File

@ -19,7 +19,7 @@ module SimpleForm
# Sample collection
def collection
@collection ||= grouped_collection.first.try(:send, group_method)
@collection ||= grouped_collection.first.try(:send, group_method) || []
end
def group_method

View File

@ -20,6 +20,15 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
end
end
test 'grouped collection accepts empty array collection form' do
with_input_for @user, :tag_ids, :grouped_select,
:collection => [],
:group_method => :last
assert_select 'select.grouped_select#user_tag_ids'
end
test 'grouped collection accepts proc as collection' do
with_input_for @user, :tag_ids, :grouped_select,
:collection => Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },