simple_form 2.1.0 → 3.0.0.rc

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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +15 -32
  3. data/README.md +103 -71
  4. data/lib/generators/simple_form/install_generator.rb +3 -3
  5. data/lib/generators/simple_form/templates/README +1 -1
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -319
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
  11. data/lib/simple_form/components/html5.rb +5 -2
  12. data/lib/simple_form/components/labels.rb +3 -3
  13. data/lib/simple_form/components/maxlength.rb +1 -8
  14. data/lib/simple_form/components/pattern.rb +2 -2
  15. data/lib/simple_form/components.rb +1 -1
  16. data/lib/simple_form/error_notification.rb +2 -2
  17. data/lib/simple_form/form_builder.rb +147 -49
  18. data/lib/simple_form/helpers.rb +1 -1
  19. data/lib/simple_form/inputs/base.rb +2 -6
  20. data/lib/simple_form/inputs/block_input.rb +1 -1
  21. data/lib/simple_form/inputs/boolean_input.rb +5 -4
  22. data/lib/simple_form/inputs/collection_input.rb +6 -6
  23. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  24. data/lib/simple_form/inputs/password_input.rb +0 -1
  25. data/lib/simple_form/inputs/string_input.rb +0 -1
  26. data/lib/simple_form/railtie.rb +7 -0
  27. data/lib/simple_form/tags.rb +61 -0
  28. data/lib/simple_form/version.rb +1 -1
  29. data/lib/simple_form/wrappers/builder.rb +5 -29
  30. data/lib/simple_form/wrappers/many.rb +1 -1
  31. data/lib/simple_form/wrappers/root.rb +1 -1
  32. data/lib/simple_form/wrappers.rb +1 -1
  33. data/lib/simple_form.rb +39 -47
  34. data/test/action_view_extensions/builder_test.rb +75 -88
  35. data/test/action_view_extensions/form_helper_test.rb +25 -16
  36. data/test/components/label_test.rb +46 -46
  37. data/test/form_builder/association_test.rb +39 -29
  38. data/test/form_builder/button_test.rb +4 -4
  39. data/test/form_builder/error_notification_test.rb +8 -8
  40. data/test/form_builder/error_test.rb +12 -12
  41. data/test/form_builder/general_test.rb +58 -52
  42. data/test/form_builder/hint_test.rb +22 -22
  43. data/test/form_builder/input_field_test.rb +12 -12
  44. data/test/form_builder/label_test.rb +6 -6
  45. data/test/form_builder/wrapper_test.rb +21 -21
  46. data/test/inputs/boolean_input_test.rb +23 -23
  47. data/test/inputs/collection_check_boxes_input_test.rb +61 -55
  48. data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
  49. data/test/inputs/collection_select_input_test.rb +70 -45
  50. data/test/inputs/datetime_input_test.rb +17 -11
  51. data/test/inputs/disabled_test.rb +10 -10
  52. data/test/inputs/discovery_test.rb +4 -4
  53. data/test/inputs/file_input_test.rb +1 -1
  54. data/test/inputs/general_test.rb +12 -12
  55. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  56. data/test/inputs/hidden_input_test.rb +3 -2
  57. data/test/inputs/numeric_input_test.rb +3 -3
  58. data/test/inputs/priority_input_test.rb +9 -3
  59. data/test/inputs/readonly_test.rb +12 -12
  60. data/test/inputs/required_test.rb +5 -5
  61. data/test/inputs/string_input_test.rb +15 -25
  62. data/test/inputs/text_input_test.rb +1 -1
  63. data/test/support/misc_helpers.rb +46 -24
  64. data/test/support/mock_controller.rb +6 -6
  65. data/test/support/models.rb +62 -61
  66. data/test/test_helper.rb +20 -24
  67. metadata +32 -33
  68. data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
  69. data/lib/simple_form/core_ext/hash.rb +0 -16
  70. data/lib/simple_form/form_builder.rb.orig +0 -486
  71. data/lib/simple_form/version.rb.orig +0 -7
data/lib/simple_form.rb CHANGED
@@ -18,6 +18,12 @@ module SimpleForm
18
18
  autoload :Inputs
19
19
  end
20
20
 
21
+ def self.eager_load!
22
+ super
23
+ SimpleForm::Inputs.eager_load!
24
+ SimpleForm::Components.eager_load!
25
+ end
26
+
21
27
  ## CONFIGURATION OPTIONS
22
28
 
23
29
  # Method used to tidy up errors.
@@ -34,11 +40,11 @@ module SimpleForm
34
40
 
35
41
  # Series of attemps to detect a default label method for collection.
36
42
  mattr_accessor :collection_label_methods
37
- @@collection_label_methods = [ :to_label, :name, :title, :to_s ]
43
+ @@collection_label_methods = [:to_label, :name, :title, :to_s]
38
44
 
39
45
  # Series of attemps to detect a default value method for collection.
40
46
  mattr_accessor :collection_value_methods
41
- @@collection_value_methods = [ :id, :to_s ]
47
+ @@collection_value_methods = [:id, :to_s]
42
48
 
43
49
  # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
44
50
  mattr_accessor :collection_wrapper_tag
@@ -49,7 +55,7 @@ module SimpleForm
49
55
  @@collection_wrapper_class = nil
50
56
 
51
57
  # You can wrap each item in a collection of radio/check boxes with a tag,
52
- # defaulting to none. Please note that when using :boolean_style = :nested,
58
+ # defaulting to span. Please note that when using :boolean_style = :nested,
53
59
  # SimpleForm will force this option to be a :label.
54
60
  mattr_accessor :item_wrapper_tag
55
61
  @@item_wrapper_tag = :span
@@ -62,25 +68,25 @@ module SimpleForm
62
68
  mattr_accessor :label_text
63
69
  @@label_text = lambda { |label, required| "#{required} #{label}" }
64
70
 
65
- # You can define the class to use on all labels. Default is nil.
71
+ # You can define the class to be used on all labels. Defaults to none.
66
72
  mattr_accessor :label_class
67
73
  @@label_class = nil
68
74
 
69
75
  # Define the way to render check boxes / radio buttons with labels.
70
- # :inline => input + label (default)
71
- # :nested => label > input
76
+ # inline: input + label (default)
77
+ # nested: label > input
72
78
  mattr_accessor :boolean_style
73
79
  @@boolean_style = :inline
74
80
 
75
- # You can define the class to use on all forms. Default is simple_form.
81
+ # You can define the class to be used on all forms. Default is simple_form.
76
82
  mattr_accessor :form_class
77
83
  @@form_class = :simple_form
78
84
 
79
- # You can define which elements should obtain additional classes
85
+ # You can define which elements should obtain additional classes.
80
86
  mattr_accessor :generate_additional_classes_for
81
87
  @@generate_additional_classes_for = [:wrapper, :label, :input]
82
88
 
83
- # Whether attributes are required by default (or not).
89
+ # Whether attributes are required by default or not.
84
90
  mattr_accessor :required_by_default
85
91
  @@required_by_default = true
86
92
 
@@ -90,7 +96,7 @@ module SimpleForm
90
96
 
91
97
  # Collection of methods to detect if a file type was given.
92
98
  mattr_accessor :file_methods
93
- @@file_methods = [ :mounted_as, :file?, :public_filename ]
99
+ @@file_methods = [:mounted_as, :file?, :public_filename]
94
100
 
95
101
  # Custom mappings for input types. This should be a hash containing a regexp
96
102
  # to match as key, and the input type that will be used when the field name
@@ -100,7 +106,7 @@ module SimpleForm
100
106
 
101
107
  # Custom wrappers for input types. This should be a hash containing an input
102
108
  # type as key and the wrapper that will be used for all inputs with specified type.
103
- # e.g { :string => :string_wrapper, :boolean => :boolean_wrapper }
109
+ # e.g { string: :string_wrapper, boolean: :boolean_wrapper }
104
110
  mattr_accessor :wrapper_mappings
105
111
  @@wrapper_mappings = nil
106
112
 
@@ -112,9 +118,9 @@ module SimpleForm
112
118
  mattr_accessor :country_priority
113
119
  @@country_priority = nil
114
120
 
115
- # Maximum size allowed for inputs.
121
+ # DEPRECATED: Maximum size allowed for inputs.
116
122
  mattr_accessor :default_input_size
117
- @@default_input_size = 50
123
+ @@default_input_size = nil
118
124
 
119
125
  # When off, do not use translations in labels. Disabling translation in
120
126
  # hints and placeholders can be done manually in the wrapper API.
@@ -125,14 +131,22 @@ module SimpleForm
125
131
  mattr_accessor :inputs_discovery
126
132
  @@inputs_discovery = true
127
133
 
128
- # Cache SimpleForm inputs discovery
134
+ # Cache SimpleForm inputs discovery.
129
135
  mattr_accessor :cache_discovery
130
136
  @@cache_discovery = defined?(Rails) && !Rails.env.development?
131
137
 
132
- # Adds a class to each generated button, mostly for compatiblity
138
+ # Adds a class to each generated button, mostly for compatiblity.
133
139
  mattr_accessor :button_class
134
140
  @@button_class = 'button'
135
141
 
142
+ # Override the default ActiveModelHelper behaviour of wrapping the input.
143
+ # This gets taken care of semantically by adding an error class to the wrapper tag
144
+ # containing the input.
145
+ mattr_accessor :field_error_proc
146
+ @@field_error_proc = proc do |html_tag, instance_tag|
147
+ html_tag
148
+ end
149
+
136
150
  ## WRAPPER CONFIGURATION
137
151
  # The default wrapper to be used by the FormBuilder.
138
152
  mattr_accessor :default_wrapper
@@ -168,7 +182,7 @@ module SimpleForm
168
182
  SimpleForm::Wrappers::Root.new(builder.to_a, options)
169
183
  end
170
184
 
171
- wrappers :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
185
+ wrappers class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
172
186
  b.use :html5
173
187
 
174
188
  b.use :min_max
@@ -178,47 +192,25 @@ module SimpleForm
178
192
  b.optional :readonly
179
193
 
180
194
  b.use :label_input
181
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
182
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
183
- end
184
-
185
- ## SETUP
186
-
187
- DEPRECATED = %w(hint_tag hint_class error_tag error_class error_notification_id wrapper_tag wrapper_class wrapper_error_class components html5)
188
- @@deprecated = []
189
-
190
- DEPRECATED.each do |method|
191
- class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
192
- class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
193
- end
194
-
195
- def self.translate=(value)
196
- deprecation_warn "SimpleForm.translate= is disabled in favor of translate_labels="
197
- self.translate_labels = value
195
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
196
+ b.use :error, wrap_with: { tag: :span, class: :error }
198
197
  end
199
198
 
200
- def self.translate
201
- deprecation_warn "SimpleForm.translate is disabled in favor of translate_labels"
202
- self.translate_labels
199
+ def self.additional_classes_for(component)
200
+ generate_additional_classes_for.include?(component) ? yield : []
203
201
  end
204
202
 
205
- def self.deprecation_warn(message)
206
- ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
207
- end
203
+ ## SETUP
208
204
 
209
- def self.additional_classes_for(component)
210
- generate_additional_classes_for.include?(component) ? yield : []
205
+ def self.default_input_size=(*)
206
+ ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
211
207
  end
212
208
 
213
209
  # Default way to setup SimpleForm. Run rails generate simple_form:install
214
210
  # to create a fresh initializer with all configuration values.
215
211
  def self.setup
216
212
  yield self
217
-
218
- unless @@deprecated.empty?
219
- raise "[SIMPLE FORM] Your SimpleForm initializer file is using the following methods: #{@@deprecated.to_sentence}. " <<
220
- "Those methods are part of the outdated configuration API. Updating to the new API is easy and fast. " <<
221
- "Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
222
- end
223
213
  end
224
214
  end
215
+
216
+ require 'simple_form/railtie' if defined?(Rails)
@@ -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,7 +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
275
+ assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
289
276
  end
290
277
 
291
278
  test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
@@ -312,7 +299,7 @@ class BuilderTest < ActionView::TestCase
312
299
  test "collection check box checks the correct value to local variables" do
313
300
  user = User.new
314
301
  user.tag_ids = [1, 3]
315
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
302
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
316
303
  with_collection_check_boxes user, :tag_ids, collection, :first, :last
317
304
 
318
305
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -321,8 +308,8 @@ class BuilderTest < ActionView::TestCase
321
308
  end
322
309
 
323
310
  test "collection check box accepts selected values as :checked option" do
324
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
325
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
311
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
312
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
326
313
 
327
314
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
328
315
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -330,8 +317,8 @@ class BuilderTest < ActionView::TestCase
330
317
  end
331
318
 
332
319
  test "collection check boxes accepts selected string values as :checked option" do
333
- collection = (1..3).map{|i| [i, "Category #{i}"] }
334
- with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
320
+ collection = (1..3).map { |i| [i, "Category #{i}"] }
321
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
335
322
 
336
323
  assert_select 'input[type=checkbox][value=1][checked=checked]'
337
324
  assert_select 'input[type=checkbox][value=3][checked=checked]'
@@ -339,8 +326,8 @@ class BuilderTest < ActionView::TestCase
339
326
  end
340
327
 
341
328
  test "collection check box accepts a single checked value" do
342
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
343
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => 3
329
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
330
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
344
331
 
345
332
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
346
333
  assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
@@ -348,9 +335,9 @@ class BuilderTest < ActionView::TestCase
348
335
  end
349
336
 
350
337
  test "collection check box accepts selected values as :checked option and override the model values" do
351
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
338
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
352
339
  @user.tag_ids = [2]
353
- 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]
354
341
 
355
342
  assert_select 'form input[type=checkbox][value=1][checked=checked]'
356
343
  assert_select 'form input[type=checkbox][value=3][checked=checked]'
@@ -358,8 +345,8 @@ class BuilderTest < ActionView::TestCase
358
345
  end
359
346
 
360
347
  test "collection check box accepts multiple disabled items" do
361
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
362
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => [1, 3]
348
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
349
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
363
350
 
364
351
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
365
352
  assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -367,8 +354,8 @@ class BuilderTest < ActionView::TestCase
367
354
  end
368
355
 
369
356
  test "collection check box accepts single disable item" do
370
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
371
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => 1
357
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
358
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
372
359
 
373
360
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
374
361
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -376,8 +363,8 @@ class BuilderTest < ActionView::TestCase
376
363
  end
377
364
 
378
365
  test "collection check box accepts a proc to disabled items" do
379
- collection = (1..3).map{|i| [i, "Tag #{i}"] }
380
- with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
366
+ collection = (1..3).map { |i| [i, "Tag #{i}"] }
367
+ with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
381
368
 
382
369
  assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
383
370
  assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
@@ -386,7 +373,7 @@ class BuilderTest < ActionView::TestCase
386
373
 
387
374
  test "collection check box accepts html options" do
388
375
  collection = [[1, 'Tag 1'], [2, 'Tag 2']]
389
- 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'
390
377
 
391
378
  assert_select 'form input.check[type=checkbox][value=1]'
392
379
  assert_select 'form input.check[type=checkbox][value=2]'
@@ -408,43 +395,43 @@ class BuilderTest < ActionView::TestCase
408
395
  end
409
396
 
410
397
  test "collection check boxes wraps the collection in the given collection wrapper tag" do
411
- 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
412
399
 
413
- assert_select 'form ul input[type=checkbox]', :count => 2
400
+ assert_select 'form ul input[type=checkbox]', count: 2
414
401
  end
415
402
 
416
403
  test "collection check boxes does not render any wrapper tag by default" do
417
404
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
418
405
 
419
- assert_select 'form input[type=checkbox]', :count => 2
406
+ assert_select 'form input[type=checkbox]', count: 2
420
407
  assert_no_select 'form ul'
421
408
  end
422
409
 
423
410
  test "collection check boxes does not wrap the collection when given falsy values" do
424
- 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
425
412
 
426
- assert_select 'form input[type=checkbox]', :count => 2
413
+ assert_select 'form input[type=checkbox]', count: 2
427
414
  assert_no_select 'form ul'
428
415
  end
429
416
 
430
417
  test "collection check boxes uses the given class for collection wrapper tag" do
431
418
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
432
- :collection_wrapper_tag => :ul, :collection_wrapper_class => "items-list"
419
+ collection_wrapper_tag: :ul, collection_wrapper_class: "items-list"
433
420
 
434
- assert_select 'form ul.items-list input[type=checkbox]', :count => 2
421
+ assert_select 'form ul.items-list input[type=checkbox]', count: 2
435
422
  end
436
423
 
437
424
  test "collection check boxes uses no class for collection wrapper tag when no wrapper tag is given" do
438
425
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
439
- :collection_wrapper_class => "items-list"
426
+ collection_wrapper_class: "items-list"
440
427
 
441
- assert_select 'form input[type=checkbox]', :count => 2
428
+ assert_select 'form input[type=checkbox]', count: 2
442
429
  assert_no_select 'form ul'
443
430
  assert_no_select '.items-list'
444
431
  end
445
432
 
446
433
  test "collection check boxes uses no class for collection wrapper tag by default" do
447
- 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
448
435
 
449
436
  assert_select 'form ul'
450
437
  assert_no_select 'form ul[class]'
@@ -453,17 +440,17 @@ class BuilderTest < ActionView::TestCase
453
440
  test "collection check boxes wrap items in a span tag by default" do
454
441
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s
455
442
 
456
- assert_select 'form span input[type=checkbox]', :count => 2
443
+ assert_select 'form span input[type=checkbox]', count: 2
457
444
  end
458
445
 
459
446
  test "collection check boxes wraps each item in the given item wrapper tag" do
460
- 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
461
448
 
462
- assert_select 'form li input[type=checkbox]', :count => 2
449
+ assert_select 'form li input[type=checkbox]', count: 2
463
450
  end
464
451
 
465
452
  test "collection check boxes does not wrap each item when given explicitly falsy value" do
466
- 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
467
454
 
468
455
  assert_select 'form input[type=checkbox]'
469
456
  assert_no_select 'form span input[type=checkbox]'
@@ -471,25 +458,25 @@ class BuilderTest < ActionView::TestCase
471
458
 
472
459
  test "collection check boxes uses the given class for item wrapper tag" do
473
460
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
474
- :item_wrapper_tag => :li, :item_wrapper_class => "inline"
461
+ item_wrapper_tag: :li, item_wrapper_class: "inline"
475
462
 
476
- assert_select "form li.inline input[type=checkbox]", :count => 2
463
+ assert_select "form li.inline input[type=checkbox]", count: 2
477
464
  end
478
465
 
479
466
  test "collection check boxes uses no class for item wrapper tag when no wrapper tag is given" do
480
467
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
481
- :item_wrapper_tag => nil, :item_wrapper_class => "inline"
468
+ item_wrapper_tag: nil, item_wrapper_class: "inline"
482
469
 
483
- assert_select 'form input[type=checkbox]', :count => 2
470
+ assert_select 'form input[type=checkbox]', count: 2
484
471
  assert_no_select 'form li'
485
472
  assert_no_select '.inline'
486
473
  end
487
474
 
488
475
  test "collection check boxes uses no class for item wrapper tag by default" do
489
476
  with_collection_check_boxes @user, :active, [true, false], :to_s, :to_s,
490
- :item_wrapper_tag => :li
477
+ item_wrapper_tag: :li
491
478
 
492
- assert_select "form li", :count => 2
479
+ assert_select "form li", count: 2
493
480
  assert_no_select "form li[class]"
494
481
  end
495
482
 
@@ -520,7 +507,7 @@ class BuilderTest < ActionView::TestCase
520
507
 
521
508
  test "collection check boxes with block helpers accept extra html options" do
522
509
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
523
- b.label(:class => "check_box") + b.check_box(:class => "check_box")
510
+ b.label(class: "check_box") + b.check_box(class: "check_box")
524
511
  end
525
512
 
526
513
  assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]'
@@ -542,7 +529,7 @@ class BuilderTest < ActionView::TestCase
542
529
 
543
530
  test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
544
531
  with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
545
- b.label(:class => b.object) { b.check_box + b.text }
532
+ b.label(class: b.object) { b.check_box + b.text }
546
533
  end
547
534
 
548
535
  assert_select 'label.true[for=user_active_true]', 'true' do
@@ -556,17 +543,17 @@ class BuilderTest < ActionView::TestCase
556
543
  test "collection check boxes with block helpers does not leak the template" do
557
544
  with_concat_form_for(@user) do |f|
558
545
  collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
559
- b.label(:class => b.object) { b.check_box + b.text }
546
+ b.label(class: b.object) { b.check_box + b.text }
560
547
  end
561
548
  concat collection_input
562
549
 
563
550
  concat f.hidden_field :name
564
551
  end
565
552
 
566
- 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
567
554
  assert_select 'input#user_active_true[type=checkbox]'
568
555
  end
569
- 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
570
557
  assert_select 'input#user_active_false[type=checkbox]'
571
558
  end
572
559
  end
@@ -601,7 +588,7 @@ class BuilderTest < ActionView::TestCase
601
588
 
602
589
  test "fields for yields an instance of FormBuilder if it was set in options" do
603
590
  with_custom_form_for(:user) do |f|
604
- f.simple_fields_for(:company, :builder => SimpleForm::FormBuilder) do |company|
591
+ f.simple_fields_for(:company, builder: SimpleForm::FormBuilder) do |company|
605
592
  assert company.instance_of?(SimpleForm::FormBuilder)
606
593
  end
607
594
  end
@@ -609,7 +596,7 @@ class BuilderTest < ActionView::TestCase
609
596
 
610
597
  test "fields inherites wrapper option from the parent form" do
611
598
  swap_wrapper :another do
612
- simple_form_for(:user, :wrapper => :another) do |f|
599
+ simple_form_for(:user, wrapper: :another) do |f|
613
600
  f.simple_fields_for(:company) do |company|
614
601
  assert_equal :another, company.options[:wrapper]
615
602
  end
@@ -619,8 +606,8 @@ class BuilderTest < ActionView::TestCase
619
606
 
620
607
  test "fields overrides wrapper option from the parent form" do
621
608
  swap_wrapper :another do
622
- simple_form_for(:user, :wrapper => :another) do |f|
623
- 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|
624
611
  assert_equal false, company.options[:wrapper]
625
612
  end
626
613
  end