diff --git a/lib/simple_form/inputs/grouped_collection_select_input.rb b/lib/simple_form/inputs/grouped_collection_select_input.rb index e71d89b8..bd40ee53 100644 --- a/lib/simple_form/inputs/grouped_collection_select_input.rb +++ b/lib/simple_form/inputs/grouped_collection_select_input.rb @@ -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 diff --git a/test/inputs/grouped_collection_select_input_test.rb b/test/inputs/grouped_collection_select_input_test.rb index a45937ed..3ad676d3 100644 --- a/test/inputs/grouped_collection_select_input_test.rb +++ b/test/inputs/grouped_collection_select_input_test.rb @@ -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']]] },