simple_form 2.1.3 → 3.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (72) hide show
  1. data/CHANGELOG.md +6 -54
  2. data/README.md +129 -111
  3. data/lib/generators/simple_form/install_generator.rb +4 -4
  4. data/lib/generators/simple_form/templates/README +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +8 -11
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  8. data/lib/simple_form.rb +31 -47
  9. data/lib/simple_form/action_view_extensions/builder.rb +0 -319
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components.rb +1 -1
  13. data/lib/simple_form/components/errors.rb +1 -7
  14. data/lib/simple_form/components/hints.rb +2 -7
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/labels.rb +4 -4
  17. data/lib/simple_form/components/maxlength.rb +1 -8
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +144 -46
  20. data/lib/simple_form/form_builder.rb.orig +486 -0
  21. data/lib/simple_form/helpers.rb +1 -1
  22. data/lib/simple_form/inputs/base.rb +3 -10
  23. data/lib/simple_form/inputs/block_input.rb +1 -1
  24. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  25. data/lib/simple_form/inputs/collection_input.rb +7 -7
  26. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  27. data/lib/simple_form/inputs/password_input.rb +0 -1
  28. data/lib/simple_form/inputs/string_input.rb +0 -1
  29. data/lib/simple_form/railtie.rb +7 -0
  30. data/lib/simple_form/tags.rb +61 -0
  31. data/lib/simple_form/version.rb +1 -1
  32. data/lib/simple_form/version.rb.orig +7 -0
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form/wrappers/builder.rb +5 -29
  35. data/lib/simple_form/wrappers/many.rb +1 -1
  36. data/lib/simple_form/wrappers/root.rb +1 -1
  37. data/test/action_view_extensions/builder_test.rb +67 -87
  38. data/test/action_view_extensions/form_helper_test.rb +16 -16
  39. data/test/components/label_test.rb +46 -46
  40. data/test/form_builder/association_test.rb +23 -23
  41. data/test/form_builder/button_test.rb +4 -4
  42. data/test/form_builder/error_notification_test.rb +8 -8
  43. data/test/form_builder/error_test.rb +18 -65
  44. data/test/form_builder/general_test.rb +45 -65
  45. data/test/form_builder/hint_test.rb +23 -29
  46. data/test/form_builder/input_field_test.rb +12 -12
  47. data/test/form_builder/label_test.rb +6 -16
  48. data/test/form_builder/wrapper_test.rb +21 -21
  49. data/test/inputs/boolean_input_test.rb +23 -35
  50. data/test/inputs/collection_check_boxes_input_test.rb +55 -55
  51. data/test/inputs/collection_radio_buttons_input_test.rb +70 -79
  52. data/test/inputs/collection_select_input_test.rb +45 -51
  53. data/test/inputs/datetime_input_test.rb +11 -11
  54. data/test/inputs/disabled_test.rb +10 -10
  55. data/test/inputs/discovery_test.rb +4 -4
  56. data/test/inputs/file_input_test.rb +1 -1
  57. data/test/inputs/general_test.rb +12 -12
  58. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  59. data/test/inputs/hidden_input_test.rb +1 -1
  60. data/test/inputs/numeric_input_test.rb +3 -3
  61. data/test/inputs/priority_input_test.rb +3 -3
  62. data/test/inputs/readonly_test.rb +12 -12
  63. data/test/inputs/required_test.rb +5 -5
  64. data/test/inputs/string_input_test.rb +10 -25
  65. data/test/inputs/text_input_test.rb +1 -1
  66. data/test/support/misc_helpers.rb +24 -24
  67. data/test/support/mock_controller.rb +6 -6
  68. data/test/support/models.rb +37 -46
  69. data/test/test_helper.rb +20 -20
  70. metadata +49 -24
  71. checksums.yaml +0 -7
  72. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  # Helpers are made of several helpers that cannot be turned on automatically.
3
3
  # For instance, disabled cannot be turned on automatically, it requires the
4
- # user to explicitly pass the option :disabled => true so it may work.
4
+ # user to explicitly pass the option disabled: true so it may work.
5
5
  module Helpers
6
6
  autoload :Autofocus, 'simple_form/helpers/autofocus'
7
7
  autoload :Disabled, 'simple_form/helpers/disabled'
@@ -1,11 +1,8 @@
1
1
  require 'simple_form/i18n_cache'
2
- require 'active_support/core_ext/string/output_safety'
3
2
 
4
3
  module SimpleForm
5
4
  module Inputs
6
5
  class Base
7
- include ERB::Util
8
-
9
6
  extend I18nCache
10
7
 
11
8
  include SimpleForm::Helpers::Autofocus
@@ -27,7 +24,7 @@ module SimpleForm
27
24
  attr_reader :attribute_name, :column, :input_type, :reflection,
28
25
  :options, :input_html_options, :input_html_classes, :html_classes
29
26
 
30
- delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, :to => :@builder
27
+ delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, to: :@builder
31
28
 
32
29
  class_attribute :default_options
33
30
  self.default_options = {}
@@ -45,7 +42,7 @@ module SimpleForm
45
42
  end
46
43
 
47
44
  # Always enabled.
48
- enable :hint, :error
45
+ enable :hint
49
46
 
50
47
  # Usually disabled, needs to be enabled explicitly passing true as option.
51
48
  disable :maxlength, :placeholder, :pattern, :min_max
@@ -93,10 +90,6 @@ module SimpleForm
93
90
 
94
91
  private
95
92
 
96
- def add_size!
97
- input_html_options[:size] ||= [limit, SimpleForm.default_input_size].compact.min
98
- end
99
-
100
93
  def limit
101
94
  if column
102
95
  decimal_or_float? ? decimal_limit : column_limit
@@ -182,7 +175,7 @@ module SimpleForm
182
175
  lookups << :"defaults.#{reflection_or_attribute_name}"
183
176
  lookups << default
184
177
 
185
- I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence
178
+ I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
186
179
  end
187
180
  end
188
181
  end
@@ -11,4 +11,4 @@ module SimpleForm
11
11
  end
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -4,7 +4,7 @@ module SimpleForm
4
4
  def input
5
5
  if nested_boolean_style?
6
6
  build_hidden_field_for_checkbox +
7
- template.label_tag(nil, :class => "checkbox") {
7
+ template.label_tag(nil, class: "checkbox") {
8
8
  build_check_box_without_hidden_field + inline_label
9
9
  }
10
10
  else
@@ -17,7 +17,6 @@ module SimpleForm
17
17
  input
18
18
  elsif nested_boolean_style?
19
19
  html_options = label_html_options.dup
20
- html_options[:class] ||= []
21
20
  html_options[:class].push(:checkbox)
22
21
 
23
22
  build_hidden_field_for_checkbox +
@@ -35,7 +34,7 @@ module SimpleForm
35
34
  # reuse the method for nested boolean style, but with no unchecked value,
36
35
  # which won't generate the hidden checkbox. This is the default functionality
37
36
  # in Rails > 3.2.1, and is backported in SimpleForm AV helpers.
38
- def build_check_box(unchecked_value = unchecked_value())
37
+ def build_check_box(unchecked_value = unchecked_value)
39
38
  @builder.check_box(attribute_name, input_html_options, checked_value, unchecked_value)
40
39
  end
41
40
 
@@ -50,9 +49,10 @@ module SimpleForm
50
49
  # we need the hidden field to be *outside* the label (otherwise it
51
50
  # generates invalid html - html5 only).
52
51
  def build_hidden_field_for_checkbox
53
- @builder.hidden_field(attribute_name, :value => unchecked_value, :id => nil,
54
- :disabled => input_html_options[:disabled],
55
- :name => input_html_options[:name])
52
+ options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
53
+ options[:name] = input_html_options[:name] if input_html_options.has_key?(:name)
54
+
55
+ @builder.hidden_field(attribute_name, options)
56
56
  end
57
57
 
58
58
  def inline_label
@@ -7,8 +7,8 @@ module SimpleForm
7
7
  # "simple_form.no" keys. See the example locale file.
8
8
  def self.boolean_collection
9
9
  i18n_cache :boolean_collection do
10
- [ [I18n.t(:"simple_form.yes", :default => 'Yes'), true],
11
- [I18n.t(:"simple_form.no", :default => 'No'), false] ]
10
+ [ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
11
+ [I18n.t(:"simple_form.no", default: 'No'), false] ]
12
12
  end
13
13
  end
14
14
 
@@ -33,7 +33,7 @@ module SimpleForm
33
33
  end
34
34
 
35
35
  def has_required?
36
- super && (input_options[:include_blank] || input_options[:prompt] || multiple?)
36
+ super && (input_options[:include_blank] || multiple?)
37
37
  end
38
38
 
39
39
  # Check if :include_blank must be included by default.
@@ -66,14 +66,14 @@ module SimpleForm
66
66
  collection_translated = translate_collection if collection_classes == [Symbol]
67
67
 
68
68
  if collection_translated || collection_classes.include?(Array)
69
- { :label => :first, :value => :last }
69
+ { label: :first, value: :last }
70
70
  elsif collection_includes_basic_objects?(collection_classes)
71
- { :label => :to_s, :value => :to_s }
71
+ { label: :to_s, value: :to_s }
72
72
  else
73
73
  sample = collection.first || collection.last
74
74
 
75
- { :label => SimpleForm.collection_label_methods.find { |m| sample.respond_to?(m) },
76
- :value => SimpleForm.collection_value_methods.find { |m| sample.respond_to?(m) } }
75
+ { label: SimpleForm.collection_label_methods.find { |m| sample.respond_to?(m) },
76
+ value: SimpleForm.collection_value_methods.find { |m| sample.respond_to?(m) } }
77
77
  end
78
78
  end
79
79
 
@@ -4,7 +4,6 @@ module SimpleForm
4
4
  enable :placeholder, :min_max
5
5
 
6
6
  def input
7
- add_size!
8
7
  input_html_classes.unshift("numeric")
9
8
  if html5?
10
9
  input_html_options[:type] ||= "number"
@@ -14,11 +13,6 @@ module SimpleForm
14
13
  end
15
14
 
16
15
  private
17
-
18
- # Rails adds the size attr by default, if the :size key does not exist.
19
- def add_size!
20
- input_html_options[:size] ||= nil
21
- end
22
16
  end
23
17
  end
24
18
  end
@@ -4,7 +4,6 @@ module SimpleForm
4
4
  enable :placeholder, :maxlength
5
5
 
6
6
  def input
7
- add_size!
8
7
  @builder.password_field(attribute_name, input_html_options)
9
8
  end
10
9
  end
@@ -9,7 +9,6 @@ module SimpleForm
9
9
  input_html_options[:type] ||= input_type if html5?
10
10
  end
11
11
 
12
- add_size!
13
12
  @builder.text_field(attribute_name, input_html_options)
14
13
  end
15
14
 
@@ -0,0 +1,7 @@
1
+ require 'rails/railtie'
2
+
3
+ module SimpleForm
4
+ class Railtie < Rails::Railtie
5
+ config.eager_load_namespaces << SimpleForm
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ module SimpleForm
2
+ module Tags
3
+ module CollectionExtensions
4
+ private
5
+
6
+ def render_collection
7
+ item_wrapper_tag = @options.fetch(:item_wrapper_tag, :span)
8
+ item_wrapper_class = @options[:item_wrapper_class]
9
+
10
+ @collection.map do |item|
11
+ value = value_for_collection(item, @value_method)
12
+ text = value_for_collection(item, @text_method)
13
+ default_html_options = default_html_options_for_collection(item, value)
14
+
15
+ rendered_item = yield item, value, text, default_html_options
16
+
17
+ item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
18
+ end.join.html_safe
19
+ end
20
+
21
+ def wrap_rendered_collection(collection)
22
+ wrapper_tag = @options[:collection_wrapper_tag]
23
+
24
+ if wrapper_tag
25
+ wrapper_class = @options[:collection_wrapper_class]
26
+ @template_object.content_tag(wrapper_tag, collection, class: wrapper_class)
27
+ else
28
+ collection
29
+ end
30
+ end
31
+ end
32
+
33
+ class CollectionRadioButtons < ActionView::Helpers::Tags::CollectionRadioButtons
34
+ include CollectionExtensions
35
+
36
+ def render
37
+ wrap_rendered_collection(super)
38
+ end
39
+
40
+ private
41
+
42
+ def render_component(builder)
43
+ builder.radio_button + builder.label(class: "collection_radio_buttons")
44
+ end
45
+ end
46
+
47
+ class CollectionCheckBoxes < ActionView::Helpers::Tags::CollectionCheckBoxes
48
+ include CollectionExtensions
49
+
50
+ def render
51
+ wrap_rendered_collection(super)
52
+ end
53
+
54
+ private
55
+
56
+ def render_component(builder)
57
+ builder.check_box + builder.label(class: "collection_check_boxes")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "2.1.3".freeze
2
+ VERSION = "3.0.0.beta1".freeze
3
3
  end
@@ -0,0 +1,7 @@
1
+ module SimpleForm
2
+ <<<<<<< HEAD
3
+ VERSION = "2.0.4".freeze
4
+ =======
5
+ VERSION = "2.1.0.dev".freeze
6
+ >>>>>>> issue-720
7
+ end
@@ -5,4 +5,4 @@ module SimpleForm
5
5
  autoload :Root, 'simple_form/wrappers/root'
6
6
  autoload :Single, 'simple_form/wrappers/single'
7
7
  end
8
- end
8
+ end
@@ -12,18 +12,18 @@ module SimpleForm
12
12
  # b.optional :placeholder
13
13
  #
14
14
  # # Use a component with specific wrapper options
15
- # b.use :error, :wrap_with => { :tag => "span", :class => "error" }
15
+ # b.use :error, wrap_with: { tag: "span", class: "error" }
16
16
  #
17
17
  # # Use a set of components by wrapping them in a tag+class.
18
- # b.wrapper :tag => "div", :class => "another" do |ba|
18
+ # b.wrapper tag: "div", class: "another" do |ba|
19
19
  # ba.use :label
20
20
  # ba.use :input
21
21
  # end
22
22
  #
23
23
  # # Use a set of components by wrapping them in a tag+class.
24
24
  # # This wrapper is identified by :label_input, which means it can
25
- # # be turned off on demand with `f.input :name, :label_input => false`
26
- # b.wrapper :label_input, :tag => "div", :class => "another" do |ba|
25
+ # # be turned off on demand with `f.input :name, label_input: false`
26
+ # b.wrapper :label_input, tag: "div", class: "another" do |ba|
27
27
  # ba.use :label
28
28
  # ba.use :input
29
29
  # end
@@ -32,7 +32,7 @@ module SimpleForm
32
32
  # The builder also accepts default options at the root level. This is usually
33
33
  # used if you want a component to be disabled by default:
34
34
  #
35
- # config.wrappers :hint => false do |b|
35
+ # config.wrappers hint: false do |b|
36
36
  # b.use :hint
37
37
  # b.use :label_input
38
38
  # end
@@ -46,18 +46,6 @@ module SimpleForm
46
46
  end
47
47
 
48
48
  def use(name, options=nil, &block)
49
- if block_given?
50
- ActiveSupport::Deprecation.warn "Passing a block to use is deprecated. " \
51
- "Please use wrapper instead of use."
52
- return wrapper(name, options, &block)
53
- end
54
-
55
- if options && options.keys != [:wrap_with]
56
- ActiveSupport::Deprecation.warn "Passing :tag, :class and others to use is deprecated. " \
57
- "Please invoke b.use #{name.inspect}, :wrap_with => #{options.inspect} instead."
58
- options = { :wrap_with => options }
59
- end
60
-
61
49
  if options && wrapper = options[:wrap_with]
62
50
  @components << Single.new(name, wrapper)
63
51
  else
@@ -66,18 +54,6 @@ module SimpleForm
66
54
  end
67
55
 
68
56
  def optional(name, options=nil, &block)
69
- if block_given?
70
- ActiveSupport::Deprecation.warn "Passing a block to optional is deprecated. " \
71
- "Please use wrapper instead of optional."
72
- return wrapper(name, options, &block)
73
- end
74
-
75
- if options && options.keys != [:wrap_with]
76
- ActiveSupport::Deprecation.warn "Passing :tag, :class and others to optional is deprecated. " \
77
- "Please invoke b.optional #{name.inspect}, :wrap_with => #{options.inspect} instead."
78
- options = { :wrap_with => options }
79
- end
80
-
81
57
  @options[name] = false
82
58
  use(name, options, &block)
83
59
  end
@@ -17,7 +17,7 @@ module SimpleForm
17
17
  @components = components
18
18
  @defaults = defaults
19
19
  @defaults[:tag] = :div unless @defaults.key?(:tag)
20
- @defaults[:class] = Array.wrap(@defaults[:class])
20
+ @defaults[:class] = Array(@defaults[:class])
21
21
  end
22
22
 
23
23
  def render(input)
@@ -23,7 +23,7 @@ module SimpleForm
23
23
  private
24
24
 
25
25
  def html_classes(input, options)
26
- css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
26
+ css = options[:wrapper_class] ? Array(options[:wrapper_class]) : @defaults[:class]
27
27
  css += SimpleForm.additional_classes_for(:wrapper) do
28
28
  input.additional_classes + [input.input_class]
29
29
  end
@@ -58,21 +58,21 @@ class BuilderTest < ActionView::TestCase
58
58
  end
59
59
 
60
60
  test "collection radio accepts checked item" do
61
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
61
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: true
62
62
 
63
63
  assert_select 'form input[type=radio][value=true][checked=checked]'
64
64
  assert_no_select 'form input[type=radio][value=false][checked=checked]'
65
65
  end
66
66
 
67
67
  test "collection radio accepts checked item which has a value of false" do
68
- with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => false
68
+ with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, checked: false
69
69
  assert_no_select 'form input[type=radio][value=true][checked=checked]'
70
70
  assert_select 'form input[type=radio][value=false][checked=checked]'
71
71
  end
72
72
 
73
73
  test "collection radio accepts multiple disabled items" do
74
74
  collection = [[1, true], [0, false], [2, 'other']]
75
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => [true, false]
75
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: [true, false]
76
76
 
77
77
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
78
78
  assert_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -81,7 +81,7 @@ class BuilderTest < ActionView::TestCase
81
81
 
82
82
  test "collection radio accepts single disable item" do
83
83
  collection = [[1, true], [0, false]]
84
- with_collection_radio_buttons @user, :active, collection, :last, :first, :disabled => true
84
+ with_collection_radio_buttons @user, :active, collection, :last, :first, disabled: true
85
85
 
86
86
  assert_select 'form input[type=radio][value=true][disabled=disabled]'
87
87
  assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
@@ -89,50 +89,50 @@ class BuilderTest < ActionView::TestCase
89
89
 
90
90
  test "collection radio accepts html options as input" do
91
91
  collection = [[1, true], [0, false]]
92
- with_collection_radio_buttons @user, :active, collection, :last, :first, {}, :class => 'special-radio'
92
+ with_collection_radio_buttons @user, :active, collection, :last, :first, {}, class: 'special-radio'
93
93
 
94
94
  assert_select 'form input[type=radio][value=true].special-radio#user_active_true'
95
95
  assert_select 'form input[type=radio][value=false].special-radio#user_active_false'
96
96
  end
97
97
 
98
98
  test "collection radio wraps the collection in the given collection wrapper tag" do
99
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
99
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
100
100
 
101
- assert_select 'form ul input[type=radio]', :count => 2
101
+ assert_select 'form ul input[type=radio]', count: 2
102
102
  end
103
103
 
104
104
  test "collection radio does not render any wrapper tag by default" do
105
105
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s
106
106
 
107
- assert_select 'form input[type=radio]', :count => 2
107
+ assert_select 'form input[type=radio]', count: 2
108
108
  assert_no_select 'form ul'
109
109
  end
110
110
 
111
111
  test "collection radio does not wrap the collection when given falsy values" do
112
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
112
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
113
113
 
114
- assert_select 'form input[type=radio]', :count => 2
114
+ assert_select 'form input[type=radio]', count: 2
115
115
  assert_no_select 'form ul'
116
116
  end
117
117
 
118
118
  test "collection radio uses the given class for collection wrapper tag" do
119
119
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
120
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
120
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
121
121
 
122
- assert_select 'form ul.items-list input[type=radio]', :count => 2
122
+ assert_select 'form ul.items-list input[type=radio]', count: 2
123
123
  end
124
124
 
125
125
  test "collection radio uses no class for collection wrapper tag when no wrapper tag is given" do
126
126
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
127
- :collection_wrapper_class => "items-list"
127
+ collection_wrapper_class: "items-list"
128
128
 
129
- assert_select 'form input[type=radio]', :count => 2
129
+ assert_select 'form input[type=radio]', count: 2
130
130
  assert_no_select 'form ul'
131
131
  assert_no_select '.items-list'
132
132
  end
133
133
 
134
134
  test "collection radio uses no class for collection wrapper tag by default" do
135
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
135
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
136
136
 
137
137
  assert_select 'form ul'
138
138
  assert_no_select 'form ul[class]'
@@ -146,13 +146,13 @@ class BuilderTest < ActionView::TestCase
146
146
  end
147
147
 
148
148
  test "collection radio wraps each item in the given item wrapper tag" do
149
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
149
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
150
150
 
151
- assert_select 'form li input[type=radio]', :count => 2
151
+ assert_select 'form li input[type=radio]', count: 2
152
152
  end
153
153
 
154
154
  test "collection radio does not wrap each item when given explicitly falsy value" do
155
- with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
155
+ with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
156
156
 
157
157
  assert_select 'form input[type=radio]'
158
158
  assert_no_select 'form span input[type=radio]'
@@ -160,25 +160,25 @@ class BuilderTest < ActionView::TestCase
160
160
 
161
161
  test "collection radio uses the given class for item wrapper tag" do
162
162
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
163
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
163
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
164
164
 
165
- assert_select "form li.inline input[type=radio]", :count => 2
165
+ assert_select "form li.inline input[type=radio]", count: 2
166
166
  end
167
167
 
168
168
  test "collection radio uses no class for item wrapper tag when no wrapper tag is given" do
169
169
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
170
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
170
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
171
171
 
172
- assert_select 'form input[type=radio]', :count => 2
172
+ assert_select 'form input[type=radio]', count: 2
173
173
  assert_no_select 'form li'
174
174
  assert_no_select '.inline'
175
175
  end
176
176
 
177
177
  test "collection radio uses no class for item wrapper tag by default" do
178
178
  with_collection_radio_buttons @user, :active, [true, false], :to_s, :to_s,
179
- :item_wrapper_tag => :li
179
+ item_wrapper_tag: :li
180
180
 
181
- assert_select "form li", :count => 2
181
+ assert_select "form li", count: 2
182
182
  assert_no_select "form li[class]"
183
183
  end
184
184
 
@@ -209,7 +209,7 @@ class BuilderTest < ActionView::TestCase
209
209
 
210
210
  test "collection radio with block helpers accept extra html options" do
211
211
  with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
212
- b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
212
+ b.label(class: "radio_button") + b.radio_button(class: "radio_button")
213
213
  end
214
214
 
215
215
  assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]'
@@ -231,7 +231,7 @@ class BuilderTest < ActionView::TestCase
231
231
 
232
232
  test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
233
233
  with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
234
- b.label(:class => b.object) { b.radio_button + b.text }
234
+ b.label(class: b.object) { b.radio_button + b.text }
235
235
  end
236
236
 
237
237
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -245,33 +245,20 @@ class BuilderTest < ActionView::TestCase
245
245
  test "collection radio with block helpers does not leak the template" do
246
246
  with_concat_form_for(@user) do |f|
247
247
  collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
248
- b.label(:class => b.object) { b.radio_button + b.text }
248
+ b.label(class: b.object) { b.radio_button + b.text }
249
249
  end
250
250
  concat collection_input
251
251
 
252
252
  concat f.hidden_field :name
253
253
  end
254
254
 
255
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
255
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
256
256
  assert_select 'input#user_active_true[type=radio]'
257
257
  end
258
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
258
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
259
259
  assert_select 'input#user_active_false[type=radio]'
260
260
  end
261
261
  end
262
-
263
- test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
264
- assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
265
- "please use `collection_radio_buttons` instead" do
266
- with_concat_form_for(@user) do |f|
267
- f.collection_radio :active, [true, false], :to_s, :to_s
268
- end
269
- end
270
-
271
- assert_select 'input[type=radio][value=true]'
272
- assert_select 'input[type=radio][value=false]'
273
- end
274
-
275
262
  # COLLECTION CHECK BOX
276
263
  test "collection check box accepts a collection and generate a serie of checkboxes for value method" do
277
264
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
@@ -285,14 +272,7 @@ class BuilderTest < ActionView::TestCase
285
272
  collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
286
273
  with_collection_check_boxes @user, :tag_ids, collection, :id, :name
287
274
 
288
- assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
289
- end
290
-
291
- test "collection check box generates a hidden field using the given :name in :input_html" do
292
- collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
293
- with_collection_check_boxes @user, :tag_ids, collection, :id, :name, {}, {:name => "user[other_tag_ids][]"}
294
-
295
- assert_select "form input[type=hidden][name='user[other_tag_ids][]'][value=]", :count => 1
275
+ assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
296
276
  end
297
277
 
298
278
  test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
@@ -329,7 +309,7 @@ class BuilderTest < ActionView::TestCase
329
309
 
330
310
  test "collection check box accepts selected values as :checked option" do
331
311
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
332
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
312
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
333
313
 
334
314
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
335
315
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -338,7 +318,7 @@ class BuilderTest < ActionView::TestCase
338
318
 
339
319
  test "collection check boxes accepts selected string values as :checked option" do
340
320
  collection = (1..3).map{|i| [i, "Category #{i}"] }
341
- with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
321
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
342
322
 
343
323
  assert_select 'input[type=checkbox][value=1][checked=checked]'
344
324
  assert_select 'input[type=checkbox][value=3][checked=checked]'
@@ -347,7 +327,7 @@ class BuilderTest < ActionView::TestCase
347
327
 
348
328
  test "collection check box accepts a single checked value" do
349
329
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
350
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
330
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
351
331
 
352
332
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
353
333
  assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -357,7 +337,7 @@ class BuilderTest < ActionView::TestCase
357
337
  test "collection check box accepts selected values as :checked option and override the model values" do
358
338
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
359
339
  @user.tag_ids = [2]
360
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
340
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
361
341
 
362
342
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
363
343
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -366,7 +346,7 @@ class BuilderTest < ActionView::TestCase
366
346
 
367
347
  test "collection check box accepts multiple disabled items" do
368
348
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
369
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
349
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
370
350
 
371
351
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
372
352
  assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -375,7 +355,7 @@ class BuilderTest < ActionView::TestCase
375
355
 
376
356
  test "collection check box accepts single disable item" do
377
357
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
378
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
358
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
379
359
 
380
360
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
381
361
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -384,7 +364,7 @@ class BuilderTest < ActionView::TestCase
384
364
 
385
365
  test "collection check box accepts a proc to disabled items" do
386
366
  collection = (1..3).map{|i| [i, "Tag #{i}"] }
387
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
367
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
388
368
 
389
369
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
390
370
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -393,7 +373,7 @@ class BuilderTest < ActionView::TestCase
393
373
 
394
374
  test "collection check box accepts html options" do
395
375
  collection = [[1, 'Tag 1'], [2, 'Tag 2']]
396
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, :class => 'check'
376
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
397
377
 
398
378
  assert_select 'form input.check[type=checkbox][value=1]'
399
379
  assert_select 'form input.check[type=checkbox][value=2]'
@@ -415,43 +395,43 @@ class BuilderTest < ActionView::TestCase
415
395
  end
416
396
 
417
397
  test "collection check boxes wraps the collection in the given collection wrapper tag" do
418
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
398
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
419
399
 
420
- assert_select 'form ul input[type=checkbox]', :count => 2
400
+ assert_select 'form ul input[type=checkbox]', count: 2
421
401
  end
422
402
 
423
403
  test "collection check boxes does not render any wrapper tag by default" do
424
404
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
425
405
 
426
- assert_select 'form input[type=checkbox]', :count => 2
406
+ assert_select 'form input[type=checkbox]', count: 2
427
407
  assert_no_select 'form ul'
428
408
  end
429
409
 
430
410
  test "collection check boxes does not wrap the collection when given falsy values" do
431
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => false
411
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: false
432
412
 
433
- assert_select 'form input[type=checkbox]', :count => 2
413
+ assert_select 'form input[type=checkbox]', count: 2
434
414
  assert_no_select 'form ul'
435
415
  end
436
416
 
437
417
  test "collection check boxes uses the given class for collection wrapper tag" do
438
418
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
439
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
419
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
440
420
 
441
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
421
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
442
422
  end
443
423
 
444
424
  test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
445
425
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
446
- :collection_wrapper_class => "items-list"
426
+ collection_wrapper_class: "items-list"
447
427
 
448
- assert_select 'form input[type=checkbox]', :count => 2
428
+ assert_select 'form input[type=checkbox]', count: 2
449
429
  assert_no_select 'form ul'
450
430
  assert_no_select '.items-list'
451
431
  end
452
432
 
453
433
  test "collection check boxes uses no class for collection wrapper tag by default" do
454
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :collection_wrapper_tag => :ul
434
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, collection_wrapper_tag: :ul
455
435
 
456
436
  assert_select 'form ul'
457
437
  assert_no_select 'form ul[class]'
@@ -460,17 +440,17 @@ class BuilderTest < ActionView::TestCase
460
440
  test "collection check boxes wrap items in a span tag by default" do
461
441
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
462
442
 
463
- assert_select 'form span input[type=checkbox]', :count => 2
443
+ assert_select 'form span input[type=checkbox]', count: 2
464
444
  end
465
445
 
466
446
  test "collection check boxes wraps each item in the given item wrapper tag" do
467
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => :li
447
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: :li
468
448
 
469
- assert_select 'form li input[type=checkbox]', :count => 2
449
+ assert_select 'form li input[type=checkbox]', count: 2
470
450
  end
471
451
 
472
452
  test "collection check boxes does not wrap each item when given explicitly falsy value" do
473
- with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, :item_wrapper_tag => false
453
+ with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s, item_wrapper_tag: false
474
454
 
475
455
  assert_select 'form input[type=checkbox]'
476
456
  assert_no_select 'form span input[type=checkbox]'
@@ -478,25 +458,25 @@ class BuilderTest < ActionView::TestCase
478
458
 
479
459
  test "collection check boxes uses the given class for item wrapper tag" do
480
460
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
481
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
461
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
482
462
 
483
- assert_select "form li.inline input[type=checkbox]", :count => 2
463
+ assert_select "form li.inline input[type=checkbox]", count: 2
484
464
  end
485
465
 
486
466
  test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
487
467
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
488
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
468
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
489
469
 
490
- assert_select 'form input[type=checkbox]', :count => 2
470
+ assert_select 'form input[type=checkbox]', count: 2
491
471
  assert_no_select 'form li'
492
472
  assert_no_select '.inline'
493
473
  end
494
474
 
495
475
  test "collection check boxes uses no class for item wrapper tag by default" do
496
476
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
497
- :item_wrapper_tag => :li
477
+ item_wrapper_tag: :li
498
478
 
499
- assert_select "form li", :count => 2
479
+ assert_select "form li", count: 2
500
480
  assert_no_select "form li[class]"
501
481
  end
502
482
 
@@ -527,7 +507,7 @@ class BuilderTest < ActionView::TestCase
527
507
 
528
508
  test "collection check boxes with block helpers accept extra html options" do
529
509
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
530
- b.label(:class => "check_box") + b.check_box(:class => "check_box")
510
+ b.label(class: "check_box") + b.check_box(class: "check_box")
531
511
  end
532
512
 
533
513
  assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
@@ -549,7 +529,7 @@ class BuilderTest < ActionView::TestCase
549
529
 
550
530
  test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
551
531
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
552
- b.label(:class => b.object) { b.check_box + b.text }
532
+ b.label(class: b.object) { b.check_box + b.text }
553
533
  end
554
534
 
555
535
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -563,17 +543,17 @@ class BuilderTest < ActionView::TestCase
563
543
  test "collection check boxes with block helpers does not leak the template" do
564
544
  with_concat_form_for(@user) do |f|
565
545
  collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
566
- b.label(:class => b.object) { b.check_box + b.text }
546
+ b.label(class: b.object) { b.check_box + b.text }
567
547
  end
568
548
  concat collection_input
569
549
 
570
550
  concat f.hidden_field :name
571
551
  end
572
552
 
573
- assert_select 'label.true[for=user_active_true]', :text => 'true', :count => 1 do
553
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
574
554
  assert_select 'input#user_active_true[type=checkbox]'
575
555
  end
576
- assert_select 'label.false[for=user_active_false]', :text => 'false', :count => 1 do
556
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
577
557
  assert_select 'input#user_active_false[type=checkbox]'
578
558
  end
579
559
  end
@@ -608,7 +588,7 @@ class BuilderTest < ActionView::TestCase
608
588
 
609
589
  test "fields for yields an instance of FormBuilder if it was set in options" do
610
590
  with_custom_form_for(:user) do |f|
611
- f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
591
+ f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
612
592
  assert company.instance_of?(SimpleForm::FormBuilder)
613
593
  end
614
594
  end
@@ -616,7 +596,7 @@ class BuilderTest < ActionView::TestCase
616
596
 
617
597
  test "fields inherites wrapper option from the parent form" do
618
598
  swap_wrapper :another do
619
- simple_form_for(:user, :wrapper => :another) do |f|
599
+ simple_form_for(:user, wrapper: :another) do |f|
620
600
  f.simple_fields_for(:company) do |company|
621
601
  assert_equal :another, company.options[:wrapper]
622
602
  end
@@ -626,8 +606,8 @@ class BuilderTest < ActionView::TestCase
626
606
 
627
607
  test "fields overrides wrapper option from the parent form" do
628
608
  swap_wrapper :another do
629
- simple_form_for(:user, :wrapper => :another) do |f|
630
- f.simple_fields_for(:company, :wrapper => false) do |company|
609
+ simple_form_for(:user, wrapper: :another) do |f|
610
+ f.simple_fields_for(:company, wrapper: false) do |company|
631
611
  assert_equal false, company.options[:wrapper]
632
612
  end
633
613
  end