Add Proc support to CollectionInput
This commit is contained in:
parent
5ea7d40014
commit
0824802cb1
|
@ -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.
|
||||
|
|
|
@ -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'],
|
||||
|
|
Loading…
Reference in New Issue