Browse files

Resolves #446 by not forcing :include_blank to be false on multi sele…

…cts.

Also added a heap of extra coverage.
  • Loading branch information...
1 parent 67ff7e6 commit b8f1390d8b4929074d32454be251219f973fe317 @justinfrench committed Nov 22, 2010
Showing with 23 additions and 10 deletions.
  1. +1 −6 lib/formtastic.rb
  2. +22 −4 spec/inputs/select_input_spec.rb
View
7 lib/formtastic.rb
@@ -818,12 +818,7 @@ def select_input(method, options)
if reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
html_options[:multiple] = true if html_options[:multiple].nil?
html_options[:size] ||= 5
-
- if html_options[:multiple]
- options[:include_blank] = false
- else
- options[:include_blank] ||= false
- end
+ options[:include_blank] ||= false
end
options = set_include_blank(options)
input_name = generate_association_input_name(method)
View
26 spec/inputs/select_input_spec.rb
@@ -336,20 +336,20 @@
it 'should respect the :include_blank option for single selects' do
@form = semantic_form_for(@fred) do |builder|
- concat(builder.input(:posts, :as => :select, :multiple => false, :size => 1, :include_blank => true))
+ concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
end
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag("form li select option[@value='']")
end
- it 'should ignore the :include_blank option for multiple selects' do
+ it 'should respect the :include_blank option for multiple selects' do
@form = semantic_form_for(@fred) do |builder|
concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
end
output_buffer.concat(@form) if Formtastic::Util.rails3?
- output_buffer.should_not have_tag("form li select option[@value='']")
+ output_buffer.should have_tag("form li select option[@value='']")
end
it 'should have one option with a "selected" attribute' do
@@ -392,11 +392,29 @@
end
end
- it 'should not have a blank option' do
+ it 'should not have a blank option by default' do
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should_not have_tag("form li select option[@value='']")
end
+ it 'should respect the :include_blank option for single selects' do
+ @form = semantic_form_for(@freds_post) do |builder|
+ concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
+ end
+
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li select option[@value='']")
+ end
+
+ it 'should respect the :include_blank option for multiple selects' do
+ @form = semantic_form_for(@freds_post) do |builder|
+ concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
+ end
+
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li select option[@value='']")
+ end
+
it 'should have one option with a "selected" attribute' do
output_buffer.concat(@form) if Formtastic::Util.rails3?
output_buffer.should have_tag('form li select option[@selected]', :count => 1)

0 comments on commit b8f1390

Please sign in to comment.