Permalink
Browse files

add Proc support to GroupedCollectionInput

  • Loading branch information...
1 parent 69b08c5 commit 37e90913fbef8d711922c092e981b5dfdae08f6e @nashby committed Jan 24, 2012
@@ -11,7 +11,10 @@ def input
private
def grouped_collection
- @grouped_collection ||= options.delete(:collection)
+ @grouped_collection ||= begin
+ grouped_collection = options.delete(:collection)
+ grouped_collection.respond_to?(:call) ? grouped_collection.call : grouped_collection.to_a
+ end
end
# Sample collection
@@ -20,6 +20,24 @@ class GroupedCollectionInputTest < ActionView::TestCase
end
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']]] },
+ :group_method => :last
+
+ assert_select 'select.grouped_select#user_tag_ids' 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 hash collection form' do
with_input_for @user, :tag_ids, :grouped_select,
:collection => { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },

0 comments on commit 37e9091

Please sign in to comment.