diff --git a/lib/formtastic.rb b/lib/formtastic.rb index 92dd14fe2..76bb96f7d 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -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)] } diff --git a/spec/label_spec.rb b/spec/label_spec.rb index b21904cb6..8117d6539 100644 --- a/spec/label_spec.rb +++ b/spec/label_spec.rb @@ -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|