Permalink
Browse files

Deprecate :radio input type and collection_radio helper, update chang…

…elog
  • Loading branch information...
1 parent b21e3c5 commit 634c4430b9f5829a5d25a66cf959a823a05db46e @carlosantoniodasilva carlosantoniodasilva committed Jan 27, 2012
View
4 CHANGELOG.md
@@ -30,10 +30,14 @@
* Do not generate hidden check box field when using nested boolean style, as it is considered
invalid markup in HTML5. This will only work in Rails > 3.2.1 (not released at this time).
More info in [#215](https://github.com/plataformatec/simple_form/issues/215)
+ * Add `item_wrapper_class` configuration option for collection radio buttons / check boxes inputs.
### deprecation
* Deprecate the `translate` configuration in favor of `translate_labels`
* Deprecate the `html5` configuration in favor of a new `html5` component
+ * Deprecate `:radio` input type in favor of `:radio_buttons`
+ * Deprecate `collection_radio` form helper in favor of `collection_radio_buttons`
+ (the label class has changed as well)
### bug fix
* Fix i18n lookup with attributes with same name of models.
View
10 lib/simple_form.rb
@@ -178,19 +178,23 @@ def self.build(options={})
DEPRECATED.each do |method|
class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
- class_eval "def self.#{method}; ActiveSupport::Deprecation.warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
+ class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
end
def self.translate=(value)
- ActiveSupport::Deprecation.warn "SimpleForm.translate= is disabled in favor of translate_labels="
+ deprecation_warn "SimpleForm.translate= is disabled in favor of translate_labels="
self.translate_labels = value
end
def self.translate
- ActiveSupport::Deprecation.warn "SimpleForm.translate is disabled in favor of translate_labels"
+ deprecation_warn "SimpleForm.translate is disabled in favor of translate_labels"
self.translate_labels
end
+ def self.deprecation_warn(message)
+ ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
+ end
+
# Default way to setup SimpleForm. Run rails generate simple_form:install
# to create a fresh initializer with all configuration values.
def self.setup
View
11 lib/simple_form/action_view_extensions/builder.rb
@@ -48,6 +48,8 @@ module Builder
#
# * item_wrapper_tag => the tag to wrap each item in the collection.
#
+ # * item_wrapper_class => the CSS class to use for item_wrapper_tag
+ #
# * a block => to generate the label + radio or any other component.
#
def collection_radio_buttons(attribute, collection, value_method, text_method, options={}, html_options={})
@@ -63,6 +65,13 @@ def collection_radio_buttons(attribute, collection, value_method, text_method, o
end
end
+ # deprecated
+ def collection_radio(*args, &block)
+ SimpleForm.deprecation_warn "The `collection_radio` helper is deprecated, " \
+ "please use `collection_radio_buttons` instead."
+ collection_radio_buttons(*args, &block)
+ end
+
# Creates a collection of check boxes for each item in the collection,
# associated with a clickable label. Use value_method and text_method to
# convert items in the collection for use as text/value in check boxes.
@@ -109,6 +118,8 @@ def collection_radio_buttons(attribute, collection, value_method, text_method, o
#
# * item_wrapper_tag => the tag to wrap each item in the collection.
#
+ # * item_wrapper_class => the CSS class to use for item_wrapper_tag
+ #
# * a block => to generate the label + check box or any other component.
#
def collection_check_boxes(attribute, collection, value_method, text_method, options={}, html_options={})
View
6 lib/simple_form/form_builder.rb
@@ -347,6 +347,12 @@ def find_input(attribute_name, options={}, &block) #:nodoc:
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
+ if input_type == :radio
+ SimpleForm.deprecation_warn "Using `:as => :radio` as input type is " \
+ "deprecated, please change it to `:as => :radio_buttons`."
+ input_type = :radio_buttons
+ end
+
if block_given?
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
else
View
12 test/action_view_extensions/builder_test.rb
@@ -183,6 +183,18 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
assert_select 'form label[for=user_active_false] > input#user_active_false[type=radio]'
end
+ test 'collection_radio helper is deprecated in favor of collection_radio_buttons' do
+ assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
+ "please use `collection_radio_buttons` instead" do
+ with_concat_form_for(@user) do |f|
+ f.collection_radio :active, [true, false], :to_s, :to_s
+ end
+ end
+
+ assert_select 'input[type=radio][value=true]'
+ assert_select 'input[type=radio][value=false]'
+ end
+
# COLLECTION CHECK BOX
test 'collection check box accepts a collection and generate a serie of checkboxes for value method' do
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
View
9 test/inputs/collection_radio_buttons_input_test.rb
@@ -6,6 +6,15 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
end
+ test 'input :as => :radio is deprecated in favor of :as => :radio_buttons' do
+ assert_deprecated "[SIMPLE_FORM] Using `:as => :radio` as " \
+ "input type is deprecated, please change it to `:as => :radio_buttons`." do
+ with_input_for @user, :active, :radio
+ end
+
+ assert_select 'input[type=radio].radio_buttons', :count => 2
+ end
+
test 'input should generate boolean radio buttons by default for radio types' do
with_input_for @user, :active, :radio_buttons
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'

0 comments on commit 634c443

Please sign in to comment.