Skip to content

Commit

Permalink
Always use supplied label_method for collection (formtasticGH-301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Jul 13, 2010
1 parent d1df80b commit 1420c6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/formtastic.rb
Expand Up @@ -1402,7 +1402,8 @@ def find_collection_for_column(column, options) #:nodoc:

# Return if we have an Array of strings, fixnums or arrays
return collection if (collection.instance_of?(Array) || collection.instance_of?(Range)) &&
[Array, Fixnum, String, Symbol].include?(collection.first.class)
[Array, Fixnum, String, Symbol].include?(collection.first.class) &&
!options.include?(:label_method)

label, value = detect_label_and_value_method!(collection, options)
collection.map { |o| [send_or_call(label, o), send_or_call(value, o)] }
Expand Down
9 changes: 9 additions & 0 deletions spec/label_spec.rb
Expand Up @@ -30,6 +30,15 @@
end
end

describe 'when label method is given' do
it 'should ignore the shortcut for simple collections if a label_method is supplied' do
semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :value_method => :to_s, :label_method => proc {|f| ('Label_%s' % [f])}))
end
output_buffer.should have_tag('form li fieldset ol li label', :with => /Label_[abc]/, :count => 3)
end
end

describe 'when label is given' do
it 'should allow the text to be given as label option' do
semantic_form_for(@new_post) do |builder|
Expand Down

0 comments on commit 1420c6b

Please sign in to comment.