Permalink
Browse files

Downcasing values before apply them as classes or ids and added more …

…tests to radio_input.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
josevalim authored and justinfrench committed Mar 6, 2009
1 parent f2973cb commit d89dc8d91113bffcf3955575818e1c2727306221
Showing with 16 additions and 3 deletions.
  1. +3 −3 lib/formtastic.rb
  2. +13 −0 spec/formtastic_spec.rb
View
@@ -462,10 +462,10 @@ def radio_input(method, options)
li_content = template.content_tag(:label,
"#{template.radio_button(@object_name, input_name, value, set_options(options))} #{label}",
- :for => generate_html_id(input_name, value)
+ :for => generate_html_id(input_name, value.to_s.downcase)
)
- li_options = value_as_class ? { :class => value.to_s } : {}
+ li_options = value_as_class ? { :class => value.to_s.downcase } : {}
template.content_tag(:li, li_content, li_options)
}
)
@@ -818,7 +818,7 @@ def generate_html_id(method_name, value='input')
end
sanitized_method_name = method_name.to_s.sub(/\?$/,"")
- "#{sanitized_object_name}#{index}_#{sanitized_method_name}_#{value.to_s}"
+ "#{sanitized_object_name}#{index}_#{sanitized_method_name}_#{value}"
end
def sanitized_object_name
View
@@ -1054,6 +1054,19 @@ def custom(arg1, arg2, options = {})
end
end
+ it 'should generate a sanitized label for attribute' do
+ @bob.stub!(:category_name).and_return(@categories)
+ semantic_form_for(@new_post) do |builder|
+ builder.semantic_fields_for(@bob) do |bob_builder|
+ concat(bob_builder.input(:category_name, :as => :radio, :collection => @categories))
+ end
+ end
+
+ @categories.each do |item|
+ output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_#{item.downcase}']")
+ end
+ end
+
end
describe 'and the :collection is a hash of strings' do

0 comments on commit d89dc8d

Please sign in to comment.