Add Proc support to CollectionInput

This commit is contained in:
Jeff Kreeftmeijer 2011-10-26 17:28:15 +02:00
parent 5ea7d40014
commit 0824802cb1
2 changed files with 8 additions and 1 deletions

View File

@ -27,7 +27,8 @@ module SimpleForm
private
def collection
@collection ||= (options.delete(:collection) || self.class.boolean_collection).to_a
collection = (options.delete(:collection) || self.class.boolean_collection)
@collection ||= collection.is_a?(Proc) ? collection.call : collection.to_a
end
# Select components does not allow the required html tag.

View File

@ -161,6 +161,12 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'label.collection_radio', 'Carlos'
end
test 'input should allow using a collection with a Proc' do
with_input_for @user, :name, :radio, :collection => Proc.new { ['Jose', 'Carlos' ] }
assert_select 'label.collection_radio', 'Jose'
assert_select 'label.collection_radio', 'Carlos'
end
test 'input should allow overriding only label method for collections' do
with_input_for @user, :name, :radio,
:collection => ['Jose' , 'Carlos'],