simple_form 5.0.3 → 5.2.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.
@@ -5,8 +5,7 @@ module SimpleForm
5
5
  def input(wrapper_options = nil)
6
6
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
7
 
8
- @builder.send(:"#{input_type}_select", attribute_name, input_priority,
9
- input_options, merged_input_options)
8
+ send(:"#{input_type}_input", merged_input_options)
10
9
  end
11
10
 
12
11
  def input_priority
@@ -15,6 +14,21 @@ module SimpleForm
15
14
 
16
15
  protected
17
16
 
17
+ def country_input(merged_input_options)
18
+ @builder.send(:country_select,
19
+ attribute_name,
20
+ input_options.merge(priority_countries: input_priority),
21
+ merged_input_options)
22
+ end
23
+
24
+ def time_zone_input(merged_input_options)
25
+ @builder.send(:time_zone_select,
26
+ attribute_name,
27
+ input_priority,
28
+ input_options,
29
+ merged_input_options)
30
+ end
31
+
18
32
  def skip_include_blank?
19
33
  super || input_priority.present?
20
34
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SimpleForm
3
- VERSION = "5.0.3".freeze
3
+ VERSION = "5.2.0".freeze
4
4
  end
data/lib/simple_form.rb CHANGED
@@ -114,7 +114,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
114
114
  mattr_reader :form_class
115
115
  @@form_class = :simple_form
116
116
 
117
- # You can define the default class to be used on all forms. Can be overriden
117
+ # You can define the default class to be used on all forms. Can be overridden
118
118
  # with `html: { :class }`. Defaults to none.
119
119
  mattr_accessor :default_form_class
120
120
  @@default_form_class = nil
@@ -4,10 +4,6 @@ require 'test_helper'
4
4
 
5
5
  # Isolated tests for label without triggering f.label.
6
6
  class IsolatedLabelTest < ActionView::TestCase
7
- setup do
8
- SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
9
- end
10
-
11
7
  def with_label_for(object, attribute_name, type, options = {})
12
8
  with_concat_form_for(object) do |f|
13
9
  options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
@@ -195,12 +195,12 @@ class WrapperTest < ActionView::TestCase
195
195
  with_form_for @user, :name
196
196
  assert_no_select "section.custom_wrapper div.another_wrapper label"
197
197
  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
198
- output_buffer.replace ""
198
+ output_buffer.to_s.replace ""
199
199
 
200
200
  with_form_for @user, :name, wrapper: :another
201
201
  assert_select "section.custom_wrapper div.another_wrapper label"
202
202
  assert_select "section.custom_wrapper div.another_wrapper input.string"
203
- output_buffer.replace ""
203
+ output_buffer.to_s.replace ""
204
204
  end
205
205
 
206
206
  with_form_for @user, :name, wrapper: custom_wrapper
@@ -33,6 +33,11 @@ class BooleanInputTest < ActionView::TestCase
33
33
  assert_select 'input[type=hidden][value=off]'
34
34
  end
35
35
 
36
+ test 'input allows skipping hidden input when setting :include_hidden to false' do
37
+ with_input_for @user, :active, :boolean, include_hidden: false
38
+ assert_no_select "input[type=hidden][name='user[active]']"
39
+ end
40
+
36
41
  test 'input uses inline boolean style by default' do
37
42
  with_input_for @user, :active, :boolean
38
43
  assert_select 'input.boolean + label.boolean.optional'
@@ -154,6 +159,14 @@ class BooleanInputTest < ActionView::TestCase
154
159
  end
155
160
  end
156
161
 
162
+ test 'input with nested style and with single wrapper allows disabling hidden field' do
163
+ swap SimpleForm, boolean_style: :nested do
164
+ with_input_for @user, :active, :boolean, include_hidden: false, wrapper: custom_wrapper_with_wrapped_label_input
165
+ assert_select "label.boolean > input.boolean"
166
+ assert_no_select "input[type=hidden] + label.boolean"
167
+ end
168
+ end
169
+
157
170
  test 'input with nested style does not include hidden field when unchecked_value is false' do
158
171
  swap SimpleForm, boolean_style: :nested do
159
172
  with_input_for @user, :active, :boolean, unchecked_value: false
@@ -3,10 +3,6 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class CollectionCheckBoxesInputTest < ActionView::TestCase
6
- setup do
7
- SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
8
- end
9
-
10
6
  test 'input check boxes does not include for attribute by default' do
11
7
  with_input_for @user, :gender, :check_boxes, collection: %i[male female]
12
8
  assert_select 'label'
@@ -3,10 +3,6 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class CollectionRadioButtonsInputTest < ActionView::TestCase
6
- setup do
7
- SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
8
- end
9
-
10
6
  test 'input generates boolean radio buttons by default for radio types' do
11
7
  with_input_for @user, :active, :radio_buttons
12
8
  assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
@@ -3,10 +3,6 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class CollectionSelectInputTest < ActionView::TestCase
6
- setup do
7
- SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
8
- end
9
-
10
6
  test 'input generates a boolean select with options by default for select types' do
11
7
  with_input_for @user, :active, :select
12
8
  assert_select 'select.select#user_active'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ # encoding: UTF-8
3
+ require 'test_helper'
4
+
5
+ class CountryInputTest < ActionView::TestCase
6
+ test 'input generates a country select field' do
7
+ with_input_for @user, :country, :country
8
+ assert_select 'select#user_country'
9
+ assert_select 'select option[value=BR]', 'Brazil'
10
+ assert_no_select 'select option[value=""][disabled=disabled]'
11
+ end
12
+
13
+ test 'input generates a country select with SimpleForm default' do
14
+ swap SimpleForm, country_priority: [ 'Brazil' ] do
15
+ with_input_for @user, :country, :country
16
+ assert_select 'select option[value="BR"] + option[value="---------------"][disabled=disabled]'
17
+ end
18
+ end
19
+
20
+ test 'input generates a country select using options priority' do
21
+ with_input_for @user, :country, :country, priority: [ 'Ukraine' ]
22
+ assert_select 'select option[value="UA"] + option[value="---------------"][disabled=disabled]'
23
+ end
24
+
25
+ test 'input does generate select element with required html attribute' do
26
+ with_input_for @user, :country, :country
27
+ assert_select 'select.required'
28
+ assert_select 'select[required]'
29
+ end
30
+
31
+ test 'input does generate select element with aria-required html attribute' do
32
+ with_input_for @user, :country, :country
33
+ assert_select 'select.required'
34
+ assert_select 'select[aria-required]'
35
+ end
36
+ end
@@ -66,6 +66,19 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
66
66
  end
67
67
  end
68
68
 
69
+ test 'grouped collection allows overriding group_method using a lambda' do
70
+ with_input_for @user, :tag_ids, :grouped_select,
71
+ collection: { Authors: %w[Jose Carlos] },
72
+ group_method: ->(i) { i.last }
73
+
74
+ assert_select 'select.grouped_select#user_tag_ids' do
75
+ assert_select 'optgroup[label=Authors]' do
76
+ assert_select 'option[value=Jose]', 'Jose'
77
+ assert_select 'option[value=Carlos]', 'Carlos'
78
+ end
79
+ end
80
+ end
81
+
69
82
  test 'grouped collection accepts group_label_method option' do
70
83
  with_input_for @user, :tag_ids, :grouped_select,
71
84
  collection: { %w[Jose Carlos] => 'Authors' },
@@ -2,21 +2,7 @@
2
2
  # encoding: UTF-8
3
3
  require 'test_helper'
4
4
 
5
- class PriorityInputTest < ActionView::TestCase
6
- test 'input generates a country select field' do
7
- with_input_for @user, :country, :country
8
- assert_select 'select#user_country'
9
- assert_select 'select option[value=BR]', 'Brazil'
10
- assert_no_select 'select option[value=""][disabled=disabled]'
11
- end
12
-
13
- test 'input generates a country select with SimpleForm default' do
14
- swap SimpleForm, country_priority: [ 'Brazil' ] do
15
- with_input_for @user, :country, :country
16
- assert_select 'select option[value="---------------"][disabled=disabled]'
17
- end
18
- end
19
-
5
+ class TimeZoneInputTest < ActionView::TestCase
20
6
  test 'input generates a time zone select field' do
21
7
  with_input_for @user, :time_zone, :time_zone
22
8
  assert_select 'select#user_time_zone'
@@ -36,14 +22,14 @@ class PriorityInputTest < ActionView::TestCase
36
22
  assert_no_select 'select option[value=""]', /^$/
37
23
  end
38
24
 
39
- test 'priority input does generate select element with required html attribute' do
40
- with_input_for @user, :country, :country
25
+ test 'input does generate select element with required html attribute' do
26
+ with_input_for @user, :time_zone, :time_zone
41
27
  assert_select 'select.required'
42
28
  assert_select 'select[required]'
43
29
  end
44
30
 
45
- test 'priority input does generate select element with aria-required html attribute' do
46
- with_input_for @user, :country, :country
31
+ test 'input does generate select element with aria-required html attribute' do
32
+ with_input_for @user, :time_zone, :time_zone
47
33
  assert_select 'select.required'
48
34
  assert_select 'select[aria-required]'
49
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-30 00:00:00.000000000 Z
13
+ date: 2023-01-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -18,28 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.0'
21
+ version: '5.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '5.0'
28
+ version: '5.2'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: actionpack
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '5.0'
35
+ version: '5.2'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '5.0'
42
+ version: '5.2'
43
43
  description: Forms made easy!
44
44
  email: heartcombo@googlegroups.com
45
45
  executables: []
@@ -82,7 +82,6 @@ files:
82
82
  - lib/simple_form/helpers/readonly.rb
83
83
  - lib/simple_form/helpers/required.rb
84
84
  - lib/simple_form/helpers/validators.rb
85
- - lib/simple_form/i18n_cache.rb
86
85
  - lib/simple_form/inputs.rb
87
86
  - lib/simple_form/inputs/base.rb
88
87
  - lib/simple_form/inputs/block_input.rb
@@ -132,6 +131,7 @@ files:
132
131
  - test/inputs/collection_radio_buttons_input_test.rb
133
132
  - test/inputs/collection_select_input_test.rb
134
133
  - test/inputs/color_input_test.rb
134
+ - test/inputs/country_input_test.rb
135
135
  - test/inputs/datetime_input_test.rb
136
136
  - test/inputs/disabled_test.rb
137
137
  - test/inputs/discovery_test.rb
@@ -140,12 +140,12 @@ files:
140
140
  - test/inputs/grouped_collection_select_input_test.rb
141
141
  - test/inputs/hidden_input_test.rb
142
142
  - test/inputs/numeric_input_test.rb
143
- - test/inputs/priority_input_test.rb
144
143
  - test/inputs/readonly_test.rb
145
144
  - test/inputs/required_test.rb
146
145
  - test/inputs/rich_text_area_input_test.rb
147
146
  - test/inputs/string_input_test.rb
148
147
  - test/inputs/text_input_test.rb
148
+ - test/inputs/time_zone_input_test.rb
149
149
  - test/simple_form_test.rb
150
150
  - test/support/discovery_inputs.rb
151
151
  - test/support/misc_helpers.rb
@@ -155,7 +155,13 @@ files:
155
155
  homepage: https://github.com/heartcombo/simple_form
156
156
  licenses:
157
157
  - MIT
158
- metadata: {}
158
+ metadata:
159
+ homepage_uri: https://github.com/heartcombo/simple_form
160
+ documentation_uri: https://rubydoc.info/github/heartcombo/simple_form
161
+ changelog_uri: https://github.com/heartcombo/simple_form/blob/master/CHANGELOG.md
162
+ source_code_uri: https://github.com/heartcombo/simple_form
163
+ bug_tracker_uri: https://github.com/heartcombo/simple_form/issues
164
+ wiki_uri: https://github.com/heartcombo/simple_form/wiki
159
165
  post_install_message:
160
166
  rdoc_options: []
161
167
  require_paths:
@@ -164,54 +170,55 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
170
  requirements:
165
171
  - - ">="
166
172
  - !ruby/object:Gem::Version
167
- version: 2.3.0
173
+ version: 2.5.0
168
174
  required_rubygems_version: !ruby/object:Gem::Requirement
169
175
  requirements:
170
176
  - - ">="
171
177
  - !ruby/object:Gem::Version
172
178
  version: '0'
173
179
  requirements: []
174
- rubygems_version: 3.1.2
180
+ rubygems_version: 3.4.5
175
181
  signing_key:
176
182
  specification_version: 4
177
183
  summary: Forms made easy!
178
184
  test_files:
179
- - test/components/label_test.rb
185
+ - test/action_view_extensions/builder_test.rb
186
+ - test/action_view_extensions/form_helper_test.rb
180
187
  - test/components/custom_components_test.rb
181
- - test/support/discovery_inputs.rb
182
- - test/support/misc_helpers.rb
183
- - test/support/mock_controller.rb
184
- - test/support/models.rb
185
- - test/test_helper.rb
186
- - test/form_builder/error_test.rb
187
- - test/form_builder/hint_test.rb
188
+ - test/components/label_test.rb
189
+ - test/form_builder/association_test.rb
190
+ - test/form_builder/button_test.rb
188
191
  - test/form_builder/error_notification_test.rb
192
+ - test/form_builder/error_test.rb
189
193
  - test/form_builder/general_test.rb
190
- - test/form_builder/button_test.rb
194
+ - test/form_builder/hint_test.rb
191
195
  - test/form_builder/input_field_test.rb
192
196
  - test/form_builder/label_test.rb
193
197
  - test/form_builder/wrapper_test.rb
194
- - test/form_builder/association_test.rb
195
198
  - test/generators/simple_form_generator_test.rb
196
- - test/action_view_extensions/builder_test.rb
197
- - test/action_view_extensions/form_helper_test.rb
198
- - test/simple_form_test.rb
199
- - test/inputs/string_input_test.rb
200
- - test/inputs/numeric_input_test.rb
201
- - test/inputs/rich_text_area_input_test.rb
202
- - test/inputs/readonly_test.rb
203
- - test/inputs/grouped_collection_select_input_test.rb
204
- - test/inputs/text_input_test.rb
205
- - test/inputs/collection_check_boxes_input_test.rb
206
199
  - test/inputs/boolean_input_test.rb
200
+ - test/inputs/collection_check_boxes_input_test.rb
201
+ - test/inputs/collection_radio_buttons_input_test.rb
202
+ - test/inputs/collection_select_input_test.rb
203
+ - test/inputs/color_input_test.rb
204
+ - test/inputs/country_input_test.rb
205
+ - test/inputs/datetime_input_test.rb
207
206
  - test/inputs/disabled_test.rb
208
207
  - test/inputs/discovery_test.rb
209
- - test/inputs/collection_select_input_test.rb
208
+ - test/inputs/file_input_test.rb
210
209
  - test/inputs/general_test.rb
211
- - test/inputs/color_input_test.rb
212
- - test/inputs/required_test.rb
213
- - test/inputs/collection_radio_buttons_input_test.rb
214
- - test/inputs/priority_input_test.rb
210
+ - test/inputs/grouped_collection_select_input_test.rb
215
211
  - test/inputs/hidden_input_test.rb
216
- - test/inputs/file_input_test.rb
217
- - test/inputs/datetime_input_test.rb
212
+ - test/inputs/numeric_input_test.rb
213
+ - test/inputs/readonly_test.rb
214
+ - test/inputs/required_test.rb
215
+ - test/inputs/rich_text_area_input_test.rb
216
+ - test/inputs/string_input_test.rb
217
+ - test/inputs/text_input_test.rb
218
+ - test/inputs/time_zone_input_test.rb
219
+ - test/simple_form_test.rb
220
+ - test/support/discovery_inputs.rb
221
+ - test/support/misc_helpers.rb
222
+ - test/support/mock_controller.rb
223
+ - test/support/models.rb
224
+ - test/test_helper.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
- module SimpleForm
3
- # A lot of configuration values are retrived from I18n,
4
- # like boolean collection, required string. This module provides
5
- # caching facility to speed up form construction.
6
- module I18nCache
7
- def i18n_cache(key)
8
- get_i18n_cache(key)[I18n.locale] ||= yield.freeze
9
- end
10
-
11
- def get_i18n_cache(key)
12
- if class_variable_defined?(:"@@#{key}")
13
- class_variable_get(:"@@#{key}")
14
- else
15
- reset_i18n_cache(key)
16
- end
17
- end
18
-
19
- def reset_i18n_cache(key)
20
- class_variable_set(:"@@#{key}", {})
21
- end
22
- end
23
- end