Skip to content
Browse files

reflect on allow_blank option to determine required status

  • Loading branch information...
1 parent 125dc1b commit aeaf54212501a33d1d0e39cacbcc528000a38eac @asanghi asanghi committed with Nov 26, 2010
Showing with 15 additions and 0 deletions.
  1. +2 −0 lib/formtastic.rb
  2. +13 −0 spec/input_spec.rb
View
2 lib/formtastic.rb
@@ -631,6 +631,8 @@ def method_required?(attribute) #:nodoc:
# Determines whether the given options evaluate to true
def options_require_validation?(options) #nodoc
+ allow_blank = options[:allow_blank]
+ return !allow_blank unless allow_blank.nil?
if_condition = !options[:if].nil?
condition = if_condition ? options[:if] : options[:unless]
View
13 spec/input_spec.rb
@@ -332,6 +332,19 @@ def should_be_required(options)
output_buffer.should have_tag('form li.required')
output_buffer.should_not have_tag('form li.optional')
end
+
+ it 'should not be required if allow_blank is true' do
+ @new_post.class.should_receive(:validators_on).with(:published).any_number_of_times.and_return([
+ active_model_inclusion_validator([:published], {:in => [false, true], :allow_blank => true})
+ ])
+
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:published))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag('form li.required')
+ output_buffer.should have_tag('form li.optional')
+ end
end
# TODO make a matcher for this?

0 comments on commit aeaf542

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