Skip to content
This repository
Browse code

add :include_blank and :prompt support for select_input with specs.

  • Loading branch information...
commit e9544811f0bff15b681c482f3e4d9601b7180141 1 parent 26b1248
Louis T. authored
4  lib/justin_french/formtastic.rb
@@ -256,9 +256,11 @@ def method_required?(attribute, required_option) #:nodoc:
256 256
       def select_input(method, options)
257 257
         options[:label_method] ||= :to_label
258 258
         options[:collection] ||= find_parent_objects_for_column(method)
  259
+        options[:include_blank] ||= false
  260
+        options[:prompt] ||= nil
259 261
 
260 262
         choices = options[:collection].map {|o| [o.send(options[:label_method]), o.id]}
261  
-        input_label(method, options) + template.select(@object_name, method, choices)
  263
+        input_label(method, options) + template.select(@object_name, method, choices, {:include_blank => options[:include_blank], :prompt => options[:prompt]})
262 264
       end
263 265
       
264 266
       # Outputs a fieldset containing a legend for the label text, and an ordered list (ol) of list
14  spec/formtastic_spec.rb
@@ -721,6 +721,20 @@ class Author; end
721 721
                     
722 722
         end
723 723
         
  724
+        describe ':as => :select, :include_blank => true, :prompt => "choose something"' do
  725
+          before do
  726
+            semantic_form_for(@new_post) do |builder|
  727
+              concat(builder.input(:author_id, :as => :select, :include_blank => true, :prompt => "choose author"))
  728
+            end
  729
+          end
  730
+          
  731
+          it 'should have a blank select option' do
  732
+             output_buffer.should have_tag("form li select option[@value='']", / /)
  733
+           end
  734
+          it 'should have a select with prompt' do
  735
+             output_buffer.should have_tag("form li select option[@value='']", /choose author/)
  736
+           end
  737
+        end
724 738
       end
725 739
 
726 740
       describe ':as => :password' do

0 notes on commit e954481

Please sign in to comment.
Something went wrong with that request. Please try again.