simple_form 3.1.0 → 3.5.0

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +70 -31
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +5 -2
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +19 -1
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +5 -2
  8. data/lib/simple_form/action_view_extensions/form_helper.rb +3 -1
  9. data/lib/simple_form/components/html5.rb +14 -4
  10. data/lib/simple_form/components/labels.rb +1 -1
  11. data/lib/simple_form/components/maxlength.rb +17 -4
  12. data/lib/simple_form/components/minlength.rb +47 -0
  13. data/lib/simple_form/components.rb +1 -0
  14. data/lib/simple_form/form_builder.rb +17 -9
  15. data/lib/simple_form/inputs/base.rb +12 -10
  16. data/lib/simple_form/inputs/boolean_input.rb +11 -2
  17. data/lib/simple_form/inputs/collection_input.rb +4 -3
  18. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
  19. data/lib/simple_form/inputs/date_time_input.rb +12 -8
  20. data/lib/simple_form/inputs/password_input.rb +1 -1
  21. data/lib/simple_form/inputs/string_input.rb +1 -1
  22. data/lib/simple_form/inputs/text_input.rb +1 -1
  23. data/lib/simple_form/version.rb +1 -1
  24. data/lib/simple_form.rb +1 -4
  25. data/test/form_builder/error_test.rb +32 -9
  26. data/test/form_builder/general_test.rb +40 -8
  27. data/test/form_builder/input_field_test.rb +53 -67
  28. data/test/form_builder/label_test.rb +19 -2
  29. data/test/form_builder/wrapper_test.rb +43 -11
  30. data/test/inputs/boolean_input_test.rb +18 -0
  31. data/test/inputs/datetime_input_test.rb +15 -2
  32. data/test/inputs/discovery_test.rb +1 -0
  33. data/test/inputs/numeric_input_test.rb +3 -0
  34. data/test/inputs/priority_input_test.rb +10 -2
  35. data/test/inputs/required_test.rb +44 -0
  36. data/test/inputs/string_input_test.rb +20 -12
  37. data/test/inputs/text_input_test.rb +12 -0
  38. data/test/support/misc_helpers.rb +22 -1
  39. data/test/support/mock_controller.rb +3 -1
  40. data/test/support/models.rb +41 -7
  41. data/test/test_helper.rb +6 -0
  42. metadata +24 -11
@@ -12,7 +12,7 @@ module SimpleForm
12
12
  'update' => 'edit'
13
13
  }
14
14
 
15
- ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :placeholder, :pattern, :readonly]
15
+ ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :minlength, :placeholder, :pattern, :readonly]
16
16
 
17
17
  extend MapType
18
18
  include SimpleForm::Inputs
@@ -30,6 +30,7 @@ module SimpleForm
30
30
  map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput
31
31
  map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput
32
32
  map_type :boolean, to: SimpleForm::Inputs::BooleanInput
33
+ map_type :hidden, to: SimpleForm::Inputs::HiddenInput
33
34
 
34
35
  def self.discovery_cache
35
36
  @discovery_cache ||= {}
@@ -47,6 +48,11 @@ module SimpleForm
47
48
  # label + input + hint (when defined) + errors (when exists), and all can
48
49
  # be configured inside a wrapper html.
49
50
  #
51
+ # If a block is given, the contents of the block will replace the input
52
+ # field that would otherwise be generated automatically. The content will
53
+ # be given a label and wrapper div to make it consistent with the other
54
+ # elements in the form.
55
+ #
50
56
  # == Examples
51
57
  #
52
58
  # # Imagine @user has error "can't be blank" on name
@@ -134,7 +140,7 @@ module SimpleForm
134
140
  components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)
135
141
 
136
142
  options = options.dup
137
- options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *components)
143
+ options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, :prompt, *components)
138
144
  options = @defaults.deep_dup.deep_merge(options) if @defaults
139
145
 
140
146
  input = find_input(attribute_name, options)
@@ -206,8 +212,8 @@ module SimpleForm
206
212
  options = args.extract_options!.dup
207
213
  options[:class] = [SimpleForm.button_class, options[:class]].compact
208
214
  args << options
209
- if respond_to?("#{type}_button")
210
- send("#{type}_button", *args, &block)
215
+ if respond_to?(:"#{type}_button")
216
+ send(:"#{type}_button", *args, &block)
211
217
  else
212
218
  send(type, *args, &block)
213
219
  end
@@ -284,7 +290,7 @@ module SimpleForm
284
290
  #
285
291
  # f.label :name # Do I18n lookup
286
292
  # f.label :name, "Name" # Same behavior as Rails, do not add required tag
287
- # f.label :name, label: "Name" # Same as above, but adds required tag
293
+ # f.label :name, label: "Name" # Same as above, but adds required tag
288
294
  #
289
295
  # f.label :name, required: false
290
296
  # f.label :name, id: "cool_label"
@@ -293,7 +299,7 @@ module SimpleForm
293
299
  return super if args.first.is_a?(String) || block_given?
294
300
 
295
301
  options = args.extract_options!.dup
296
- options[:label_html] = options.except(:label, :required, :as)
302
+ options[:label_html] = options.except(:label, :label_text, :required, :as)
297
303
 
298
304
  column = find_attribute_column(attribute_name)
299
305
  input_type = default_input_type(attribute_name, column, options)
@@ -504,12 +510,12 @@ module SimpleForm
504
510
  end
505
511
 
506
512
  # Attempt to guess the better input type given the defined options. By
507
- # default alwayls fallback to the user :as option, or to a :select when a
513
+ # default always fallback to the user :as option, or to a :select when a
508
514
  # collection is given.
509
515
  def default_input_type(attribute_name, column, options)
510
516
  return options[:as].to_sym if options[:as]
511
- return :select if options[:collection]
512
517
  custom_type = find_custom_type(attribute_name.to_s) and return custom_type
518
+ return :select if options[:collection]
513
519
 
514
520
  input_type = column.try(:type)
515
521
  case input_type
@@ -543,7 +549,9 @@ module SimpleForm
543
549
  end
544
550
 
545
551
  def find_attribute_column(attribute_name)
546
- if @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name)
552
+ if @object.respond_to?(:type_for_attribute) && @object.has_attribute?(attribute_name)
553
+ @object.type_for_attribute(attribute_name.to_s)
554
+ elsif @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name)
547
555
  @object.column_for_attribute(attribute_name)
548
556
  end
549
557
  end
@@ -21,6 +21,7 @@ module SimpleForm
21
21
  include SimpleForm::Components::HTML5
22
22
  include SimpleForm::Components::LabelInput
23
23
  include SimpleForm::Components::Maxlength
24
+ include SimpleForm::Components::Minlength
24
25
  include SimpleForm::Components::MinMax
25
26
  include SimpleForm::Components::Pattern
26
27
  include SimpleForm::Components::Placeholders
@@ -50,7 +51,7 @@ module SimpleForm
50
51
  enable :hint
51
52
 
52
53
  # Usually disabled, needs to be enabled explicitly passing true as option.
53
- disable :maxlength, :placeholder, :pattern, :min_max
54
+ disable :maxlength, :minlength, :placeholder, :pattern, :min_max
54
55
 
55
56
  def initialize(builder, attribute_name, column, input_type, options = {})
56
57
  super
@@ -115,7 +116,7 @@ module SimpleForm
115
116
  end
116
117
 
117
118
  def decimal_or_float?
118
- column.number? && column.type != :integer
119
+ column.type == :float || column.type == :decimal
119
120
  end
120
121
 
121
122
  def nested_boolean_style?
@@ -178,24 +179,25 @@ module SimpleForm
178
179
  model_names.shift
179
180
 
180
181
  lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
181
- lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}_html"
182
182
  lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
183
- lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}_html"
184
183
  end
185
184
  lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}"
186
- lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}_html"
187
185
  lookups << :"defaults.#{reflection_or_attribute_name}"
188
- lookups << :"defaults.#{reflection_or_attribute_name}_html"
189
186
  lookups << default
190
187
 
191
- t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
188
+ I18n.t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
192
189
  end
193
190
 
194
191
  def merge_wrapper_options(options, wrapper_options)
195
192
  if wrapper_options
196
- options.merge(wrapper_options) do |_, oldval, newval|
197
- if Array === oldval
198
- oldval + Array(newval)
193
+ wrapper_options.merge(options) do |key, oldval, newval|
194
+ case key.to_s
195
+ when "class"
196
+ Array(oldval) + Array(newval)
197
+ when "data", "aria"
198
+ oldval.merge(newval)
199
+ else
200
+ newval
199
201
  end
200
202
  end
201
203
  else
@@ -6,7 +6,7 @@ module SimpleForm
6
6
 
7
7
  if nested_boolean_style?
8
8
  build_hidden_field_for_checkbox +
9
- template.label_tag(nil, class: SimpleForm.boolean_label_class) {
9
+ template.label_tag(nil, class: boolean_label_class) {
10
10
  build_check_box_without_hidden_field(merged_input_options) +
11
11
  inline_label
12
12
  }
@@ -21,7 +21,7 @@ module SimpleForm
21
21
  elsif nested_boolean_style?
22
22
  html_options = label_html_options.dup
23
23
  html_options[:class] ||= []
24
- html_options[:class].push(SimpleForm.boolean_label_class) if SimpleForm.boolean_label_class
24
+ html_options[:class].push(boolean_label_class) if boolean_label_class
25
25
 
26
26
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
27
27
 
@@ -36,6 +36,10 @@ module SimpleForm
36
36
 
37
37
  private
38
38
 
39
+ def boolean_label_class
40
+ options[:boolean_label_class] || SimpleForm.boolean_label_class
41
+ end
42
+
39
43
  # Build a checkbox tag using default unchecked value. This allows us to
40
44
  # reuse the method for nested boolean style, but with no unchecked value,
41
45
  # which won't generate the hidden checkbox. This is the default functionality
@@ -55,6 +59,7 @@ module SimpleForm
55
59
  # we need the hidden field to be *outside* the label (otherwise it
56
60
  # generates invalid html - html5 only).
57
61
  def build_hidden_field_for_checkbox
62
+ return "" unless include_hidden?
58
63
  options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
59
64
  options[:name] = input_html_options[:name] if input_html_options.has_key?(:name)
60
65
 
@@ -81,6 +86,10 @@ module SimpleForm
81
86
  false
82
87
  end
83
88
 
89
+ def include_hidden?
90
+ options.fetch(:include_hidden, true)
91
+ end
92
+
84
93
  def checked_value
85
94
  options.fetch(:checked_value, '1')
86
95
  end
@@ -1,6 +1,9 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class CollectionInput < Base
4
+ BASIC_OBJECT_CLASSES = [String, Integer, Float, NilClass, Symbol, TrueClass, FalseClass]
5
+ BASIC_OBJECT_CLASSES.push(Fixnum, Bignum) unless 1.class == Integer
6
+
4
7
  # Default boolean collection for use with selects/radios when no
5
8
  # collection is given. Always fallback to this boolean collection.
6
9
  # Texts can be translated using i18n in "simple_form.yes" and
@@ -90,9 +93,7 @@ module SimpleForm
90
93
  end
91
94
 
92
95
  def collection_includes_basic_objects?(collection_classes)
93
- (collection_classes & [
94
- String, Integer, Fixnum, Bignum, Float, NilClass, Symbol, TrueClass, FalseClass
95
- ]).any?
96
+ (collection_classes & BASIC_OBJECT_CLASSES).any?
96
97
  end
97
98
 
98
99
  def translate_collection
@@ -6,7 +6,7 @@ module SimpleForm
6
6
 
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
8
8
 
9
- @builder.send("collection_#{input_type}",
9
+ @builder.send(:"collection_#{input_type}",
10
10
  attribute_name, collection, value_method, label_method,
11
11
  input_options, merged_input_options,
12
12
  &collection_block_for_nested_boolean_style
@@ -14,16 +14,20 @@ module SimpleForm
14
14
  private
15
15
 
16
16
  def label_target
17
- position = case input_type
18
- when :date, :datetime
19
- date_order = input_options[:order] || I18n.t('date.order')
20
- date_order.first.to_sym
17
+ if use_html5_inputs?
18
+ attribute_name
21
19
  else
22
- :hour
23
- end
20
+ position = case input_type
21
+ when :date, :datetime
22
+ date_order = input_options[:order] || I18n.t('date.order')
23
+ date_order.first.to_sym
24
+ else
25
+ :hour
26
+ end
24
27
 
25
- position = ActionView::Helpers::DateTimeSelector::POSITION[position]
26
- "#{attribute_name}_#{position}i"
28
+ position = ActionView::Helpers::DateTimeSelector::POSITION[position]
29
+ "#{attribute_name}_#{position}i"
30
+ end
27
31
  end
28
32
 
29
33
  def use_html5_inputs?
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class PasswordInput < Base
4
- enable :placeholder, :maxlength
4
+ enable :placeholder, :maxlength, :minlength
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class StringInput < Base
4
- enable :placeholder, :maxlength, :pattern
4
+ enable :placeholder, :maxlength, :minlength, :pattern
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  unless string?
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class TextInput < Base
4
- enable :placeholder, :maxlength
4
+ enable :placeholder, :maxlength, :minlength
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "3.1.0".freeze
2
+ VERSION = "3.5.0".freeze
3
3
  end
data/lib/simple_form.rb CHANGED
@@ -152,10 +152,6 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
152
152
  mattr_accessor :country_priority
153
153
  @@country_priority = nil
154
154
 
155
- # DEPRECATED: Maximum size allowed for inputs.
156
- mattr_accessor :default_input_size
157
- @@default_input_size = nil
158
-
159
155
  # When off, do not use translations in labels. Disabling translation in
160
156
  # hints and placeholders can be done manually in the wrapper API.
161
157
  mattr_accessor :translate_labels
@@ -236,6 +232,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
236
232
 
237
233
  b.use :min_max
238
234
  b.use :maxlength
235
+ b.use :minlength
239
236
  b.use :placeholder
240
237
  b.optional :pattern
241
238
  b.optional :readonly
@@ -94,13 +94,36 @@ class ErrorTest < ActionView::TestCase
94
94
  assert_no_select 'span.error b', 'markup'
95
95
  end
96
96
 
97
-
98
97
  test 'error generates an error message with raw HTML tags' do
99
98
  with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
100
99
  assert_select 'span.error', "Name cannot be blank"
101
100
  assert_select 'span.error b', "Name"
102
101
  end
103
102
 
103
+ test 'error adds aria-invalid attribute to inputs' do
104
+ with_form_for @user, :name, error: true
105
+ assert_select "input#user_name[name='user[name]'][aria-invalid='true']"
106
+
107
+ with_form_for @user, :name, as: :text, error: true
108
+ assert_select "textarea#user_name[name='user[name]'][aria-invalid='true']"
109
+
110
+ @user.errors.add(:active, 'must select one')
111
+ with_form_for @user, :active, as: :radio_buttons
112
+ assert_select "input#user_active_true[type=radio][name='user[active]'][aria-invalid='true']"
113
+ assert_select "input#user_active_false[type=radio][name='user[active]'][aria-invalid='true']"
114
+
115
+ with_form_for @user, :active, as: :check_boxes
116
+ assert_select "input#user_active_true[type=checkbox][aria-invalid='true']"
117
+ assert_select "input#user_active_false[type=checkbox][aria-invalid='true']"
118
+
119
+ with_form_for @user, :company_id, as: :select, error: true
120
+ assert_select "select#user_company_id[aria-invalid='true']"
121
+
122
+ @user.errors.add(:password, 'must not be blank')
123
+ with_form_for @user, :password
124
+ assert_select "input#user_password[type=password][aria-invalid='true']"
125
+ end
126
+
104
127
  # FULL ERRORS
105
128
 
106
129
  test 'full error generates a full error tag for the attribute' do
@@ -146,14 +169,14 @@ class ErrorTest < ActionView::TestCase
146
169
  # FULL_ERROR_WRAPPER
147
170
 
148
171
  test 'full error finds errors on association' do
149
- swap_wrapper :default, self.custom_wrapper_with_full_error do
172
+ swap_wrapper :default, custom_wrapper_with_full_error do
150
173
  with_form_for @user, :company_id, as: :select
151
174
  assert_select 'span.error', 'Company must be valid'
152
175
  end
153
176
  end
154
177
 
155
178
  test 'full error finds errors on association with reflection' do
156
- swap_wrapper :default, self.custom_wrapper_with_full_error do
179
+ swap_wrapper :default, custom_wrapper_with_full_error do
157
180
  with_form_for @user, :company_id, as: :select,
158
181
  reflection: Association.new(Company, :company, {})
159
182
  assert_select 'span.error', 'Company must be valid'
@@ -161,14 +184,14 @@ class ErrorTest < ActionView::TestCase
161
184
  end
162
185
 
163
186
  test 'full error can be disabled' do
164
- swap_wrapper :default, self.custom_wrapper_with_full_error do
187
+ swap_wrapper :default, custom_wrapper_with_full_error do
165
188
  with_form_for @user, :company_id, as: :select, full_error: false
166
189
  assert_no_select 'span.error'
167
190
  end
168
191
  end
169
192
 
170
193
  test 'full error can be disabled setting error to false' do
171
- swap_wrapper :default, self.custom_wrapper_with_full_error do
194
+ swap_wrapper :default, custom_wrapper_with_full_error do
172
195
  with_form_for @user, :company_id, as: :select, error: false
173
196
  assert_no_select 'span.error'
174
197
  end
@@ -196,7 +219,7 @@ class ErrorTest < ActionView::TestCase
196
219
  end
197
220
 
198
221
  test 'input with custom error works when using full_error component' do
199
- swap_wrapper :default, self.custom_wrapper_with_full_error do
222
+ swap_wrapper :default, custom_wrapper_with_full_error do
200
223
  error_text = "Super User Name! cannot be blank"
201
224
  with_form_for @user, :name, error: error_text
202
225
 
@@ -219,7 +242,7 @@ class ErrorTest < ActionView::TestCase
219
242
  end
220
243
 
221
244
  test 'input with custom error escapes the error text using full_error component' do
222
- swap_wrapper :default, self.custom_wrapper_with_full_error do
245
+ swap_wrapper :default, custom_wrapper_with_full_error do
223
246
  with_form_for @user, :name, error: 'error must not contain <b>markup</b>'
224
247
 
225
248
  assert_select 'span.error'
@@ -228,7 +251,7 @@ class ErrorTest < ActionView::TestCase
228
251
  end
229
252
 
230
253
  test 'input with custom error does not escape the error text if it is safe using full_error component' do
231
- swap_wrapper :default, self.custom_wrapper_with_full_error do
254
+ swap_wrapper :default, custom_wrapper_with_full_error do
232
255
  with_form_for @user, :name, error: 'error must contain <b>markup</b>'.html_safe
233
256
 
234
257
  assert_select 'span.error'
@@ -237,7 +260,7 @@ class ErrorTest < ActionView::TestCase
237
260
  end
238
261
 
239
262
  test 'input with custom error when using full_error component does not generate the error if there is no error on the attribute' do
240
- swap_wrapper :default, self.custom_wrapper_with_full_error do
263
+ swap_wrapper :default, custom_wrapper_with_full_error do
241
264
  with_form_for @user, :active, error: "Super User Active! can't be blank"
242
265
 
243
266
  assert_no_select 'span.error'
@@ -46,6 +46,17 @@ class FormBuilderTest < ActionView::TestCase
46
46
  end
47
47
  end
48
48
 
49
+ test 'builder does not override custom input mappings for custom collection' do
50
+ swap SimpleForm, input_mappings: { /gender$/ => :check_boxes } do
51
+ with_concat_form_for @user do |f|
52
+ f.input :gender, collection: [:male, :female]
53
+ end
54
+
55
+ assert_no_select 'select option', 'Male'
56
+ assert_select 'input[type=checkbox][value=male]'
57
+ end
58
+ end
59
+
49
60
  test 'builder allows to skip input_type class' do
50
61
  swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
51
62
  with_form_for @user, :post_count
@@ -108,9 +119,22 @@ class FormBuilderTest < ActionView::TestCase
108
119
 
109
120
  test 'builder generates text areas for text columns' do
110
121
  with_form_for @user, :description
122
+ assert_no_select 'form input#user_description.string'
111
123
  assert_select 'form textarea#user_description.text'
112
124
  end
113
125
 
126
+ test 'builder generates text areas for text columns when hinted' do
127
+ with_form_for @user, :description, as: :text
128
+ assert_no_select 'form input#user_description.string'
129
+ assert_select 'form textarea#user_description.text'
130
+ end
131
+
132
+ test 'builder generates text field for text columns when hinted' do
133
+ with_form_for @user, :description, as: :string
134
+ assert_no_select 'form textarea#user_description.text'
135
+ assert_select 'form input#user_description.string'
136
+ end
137
+
114
138
  test 'builder generates a checkbox for boolean columns' do
115
139
  with_form_for @user, :active
116
140
  assert_select 'form input[type=checkbox]#user_active.boolean'
@@ -128,7 +152,11 @@ class FormBuilderTest < ActionView::TestCase
128
152
 
129
153
  test 'builder generates uuid fields for uuid columns' do
130
154
  with_form_for @user, :uuid
131
- assert_select 'form input#user_uuid.string.uuid'
155
+ if defined? ActiveModel::Type
156
+ assert_select 'form input#user_uuid.string.string'
157
+ else
158
+ assert_select 'form input#user_uuid.string.uuid'
159
+ end
132
160
  end
133
161
 
134
162
  test 'builder generates password fields for columns that matches password' do
@@ -206,11 +234,15 @@ class FormBuilderTest < ActionView::TestCase
206
234
  with_form_for @user, :name, as: :text
207
235
  assert_no_select 'form input#user_name'
208
236
  assert_select 'form textarea#user_name.text'
237
+ end
209
238
 
239
+ test 'builder allows overriding default input type for radio_buttons' do
210
240
  with_form_for @user, :active, as: :radio_buttons
211
241
  assert_no_select 'form input[type=checkbox]'
212
242
  assert_select 'form input.radio_buttons[type=radio]', count: 2
243
+ end
213
244
 
245
+ test 'builder allows overriding default input type for string' do
214
246
  with_form_for @user, :born_at, as: :string
215
247
  assert_no_select 'form select'
216
248
  assert_select 'form input#user_born_at.string'
@@ -256,7 +288,7 @@ class FormBuilderTest < ActionView::TestCase
256
288
  end
257
289
 
258
290
  test 'builder does not propagate input options to wrapper with custom wrapper' do
259
- swap_wrapper :default, self.custom_wrapper_with_wrapped_input do
291
+ swap_wrapper :default, custom_wrapper_with_wrapped_input do
260
292
  with_form_for @user, :name, input_html: { class: 'my_input' }
261
293
  assert_no_select 'form div.input.my_input'
262
294
  assert_select 'form input.my_input.string'
@@ -264,7 +296,7 @@ class FormBuilderTest < ActionView::TestCase
264
296
  end
265
297
 
266
298
  test 'builder does not propagate label options to wrapper with custom wrapper' do
267
- swap_wrapper :default, self.custom_wrapper_with_wrapped_label do
299
+ swap_wrapper :default, custom_wrapper_with_wrapped_label do
268
300
  with_form_for @user, :name, label_html: { class: 'my_label' }
269
301
  assert_no_select 'form div.label.my_label'
270
302
  assert_select 'form label.my_label.string'
@@ -353,15 +385,15 @@ class FormBuilderTest < ActionView::TestCase
353
385
  [:input, :input_field].each do |method|
354
386
  test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
355
387
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
356
- f.send(method, :name)
388
+ f.public_send(method, :name)
357
389
  end
358
390
  assert_select 'input.default_class'
359
391
  end
360
392
 
361
393
  test "builder receives a default argument and pass it to the inputs without changing the defaults when calling '#{method}'" do
362
394
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class', id: 'default_id' } } do |f|
363
- concat(f.send(method, :name))
364
- concat(f.send(method, :credit_limit))
395
+ concat(f.public_send(method, :name))
396
+ concat(f.public_send(method, :credit_limit))
365
397
  end
366
398
 
367
399
  assert_select "input.string.default_class[name='user[name]']"
@@ -372,9 +404,9 @@ class FormBuilderTest < ActionView::TestCase
372
404
  @user.company = Company.new(1, 'Empresa')
373
405
 
374
406
  with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
375
- concat(f.send(method, :name))
407
+ concat(f.public_send(method, :name))
376
408
  concat(f.simple_fields_for(:company) do |company_form|
377
- concat(company_form.send(method, :name))
409
+ concat(company_form.public_send(method, :name))
378
410
  end)
379
411
  end
380
412