simple_form 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +3 -4
  5. data/lib/simple_form/components/label_input.rb +1 -1
  6. data/lib/simple_form/form_builder.rb +1 -5
  7. data/lib/simple_form/railtie.rb +4 -0
  8. data/lib/simple_form/version.rb +1 -1
  9. data/lib/simple_form/wrappers/leaf.rb +1 -1
  10. data/lib/simple_form.rb +8 -4
  11. metadata +5 -85
  12. data/test/action_view_extensions/builder_test.rb +0 -634
  13. data/test/action_view_extensions/form_helper_test.rb +0 -172
  14. data/test/components/custom_components_test.rb +0 -62
  15. data/test/components/label_test.rb +0 -352
  16. data/test/form_builder/association_test.rb +0 -252
  17. data/test/form_builder/button_test.rb +0 -48
  18. data/test/form_builder/error_notification_test.rb +0 -80
  19. data/test/form_builder/error_test.rb +0 -281
  20. data/test/form_builder/general_test.rb +0 -539
  21. data/test/form_builder/hint_test.rb +0 -150
  22. data/test/form_builder/input_field_test.rb +0 -195
  23. data/test/form_builder/label_test.rb +0 -136
  24. data/test/form_builder/wrapper_test.rb +0 -378
  25. data/test/generators/simple_form_generator_test.rb +0 -43
  26. data/test/inputs/boolean_input_test.rb +0 -256
  27. data/test/inputs/collection_check_boxes_input_test.rb +0 -323
  28. data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
  29. data/test/inputs/collection_select_input_test.rb +0 -380
  30. data/test/inputs/color_input_test.rb +0 -10
  31. data/test/inputs/country_input_test.rb +0 -36
  32. data/test/inputs/datetime_input_test.rb +0 -176
  33. data/test/inputs/disabled_test.rb +0 -92
  34. data/test/inputs/discovery_test.rb +0 -142
  35. data/test/inputs/file_input_test.rb +0 -17
  36. data/test/inputs/general_test.rb +0 -133
  37. data/test/inputs/grouped_collection_select_input_test.rb +0 -196
  38. data/test/inputs/hidden_input_test.rb +0 -32
  39. data/test/inputs/numeric_input_test.rb +0 -177
  40. data/test/inputs/readonly_test.rb +0 -102
  41. data/test/inputs/required_test.rb +0 -158
  42. data/test/inputs/rich_text_area_input_test.rb +0 -15
  43. data/test/inputs/string_input_test.rb +0 -158
  44. data/test/inputs/text_input_test.rb +0 -37
  45. data/test/inputs/time_zone_input_test.rb +0 -36
  46. data/test/simple_form_test.rb +0 -18
  47. data/test/support/discovery_inputs.rb +0 -65
  48. data/test/support/misc_helpers.rb +0 -274
  49. data/test/support/mock_controller.rb +0 -30
  50. data/test/support/models.rb +0 -357
  51. data/test/test_helper.rb +0 -95
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- class SimpleFormTest < ActiveSupport::TestCase
5
- test 'setup block yields self' do
6
- SimpleForm.setup do |config|
7
- assert_equal SimpleForm, config
8
- end
9
- end
10
-
11
- test 'setup block configure Simple Form' do
12
- SimpleForm.setup do |config|
13
- assert_equal SimpleForm, config
14
- end
15
-
16
- assert_equal true, SimpleForm.configured?
17
- end
18
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
- class StringInput < SimpleForm::Inputs::StringInput
3
- def input(wrapper_options = nil)
4
- "<section>#{super}</section>".html_safe
5
- end
6
- end
7
-
8
- class NumericInput < SimpleForm::Inputs::NumericInput
9
- def input(wrapper_options = nil)
10
- "<section>#{super}</section>".html_safe
11
- end
12
- end
13
-
14
- class CustomizedInput < SimpleForm::Inputs::StringInput
15
- def input(wrapper_options = nil)
16
- "<section>#{super}</section>".html_safe
17
- end
18
-
19
- def input_method
20
- :text_field
21
- end
22
- end
23
-
24
- class DeprecatedInput < SimpleForm::Inputs::StringInput
25
- def input
26
- "<section>#{super}</section>".html_safe
27
- end
28
-
29
- def input_method
30
- :text_field
31
- end
32
- end
33
-
34
- class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
35
- def input_html_classes
36
- super.push('chosen')
37
- end
38
- end
39
-
40
- class FileInput < SimpleForm::Inputs::FileInput
41
- def input_html_classes
42
- super.delete_if { |html_class| html_class == :file }
43
- super.push('file-upload')
44
- end
45
- end
46
-
47
- module CustomInputs
48
- class CustomizedInput < SimpleForm::Inputs::StringInput
49
- def input_html_classes
50
- super.push('customized-namespace-custom-input')
51
- end
52
- end
53
-
54
- class PasswordInput < SimpleForm::Inputs::PasswordInput
55
- def input_html_classes
56
- super.push('password-custom-input')
57
- end
58
- end
59
-
60
- class NumericInput < SimpleForm::Inputs::PasswordInput
61
- def input_html_classes
62
- super.push('numeric-custom-input')
63
- end
64
- end
65
- end
@@ -1,274 +0,0 @@
1
- # frozen_string_literal: true
2
- module MiscHelpers
3
- def store_translations(locale, translations, &block)
4
- I18n.backend.store_translations locale, translations
5
- yield
6
- ensure
7
- I18n.reload!
8
- I18n.backend.send :init_translations
9
- end
10
-
11
- def assert_no_select(selector, value = nil)
12
- assert_select(selector, text: value, count: 0)
13
- end
14
-
15
- def swap(object, new_values)
16
- old_values = {}
17
- new_values.each do |key, value|
18
- old_values[key] = object.send key
19
- object.send :"#{key}=", value
20
- end
21
- yield
22
- ensure
23
- old_values.each do |key, value|
24
- object.send :"#{key}=", value
25
- end
26
- end
27
-
28
- def stub_any_instance(klass, method, value)
29
- klass.class_eval do
30
- alias_method :"new_#{method}", method
31
-
32
- define_method(method) do
33
- if value.respond_to?(:call)
34
- value.call
35
- else
36
- value
37
- end
38
- end
39
- end
40
-
41
- yield
42
- ensure
43
- klass.class_eval do
44
- undef_method method
45
- alias_method method, :"new_#{method}"
46
- undef_method :"new_#{method}"
47
- end
48
- end
49
-
50
- def swap_wrapper(name = :default, wrapper = custom_wrapper)
51
- old = SimpleForm.wrappers[name.to_s]
52
- SimpleForm.wrappers[name.to_s] = wrapper
53
- yield
54
- ensure
55
- SimpleForm.wrappers[name.to_s] = old
56
- end
57
-
58
- def custom_wrapper
59
- SimpleForm.build tag: :section, class: "custom_wrapper", pattern: false do |b|
60
- b.use :pattern
61
- b.wrapper :another, class: "another_wrapper" do |ba|
62
- ba.use :label
63
- ba.use :input
64
- end
65
- b.wrapper :error_wrapper, tag: :div, class: "error_wrapper" do |be|
66
- be.use :error, wrap_with: { tag: :span, class: "omg_error" }
67
- end
68
- b.use :hint, wrap_with: { class: "omg_hint" }
69
- end
70
- end
71
-
72
- def custom_wrapper_with_wrapped_optional_component
73
- SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
74
- b.wrapper tag: :div, class: 'no_output_wrapper' do |ba|
75
- ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
76
- end
77
- end
78
- end
79
-
80
- def custom_wrapper_with_unless_blank
81
- SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
82
- b.wrapper tag: :div, class: 'no_output_wrapper', unless_blank: true do |ba|
83
- ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
84
- end
85
- end
86
- end
87
-
88
- def custom_wrapper_with_input_class
89
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
90
- b.use :label
91
- b.use :input, class: 'inline-class'
92
- end
93
- end
94
-
95
- def custom_wrapper_with_input_data_modal
96
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
97
- b.use :label
98
- b.use :input, data: { modal: 'data-modal', wrapper: 'data-wrapper' }
99
- end
100
- end
101
-
102
- def custom_wrapper_with_input_aria_modal
103
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
104
- b.use :label
105
- b.use :input, aria: { modal: 'aria-modal', wrapper: 'aria-wrapper' }
106
- end
107
- end
108
-
109
- def custom_wrapper_with_label_class
110
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
111
- b.use :label, class: 'inline-class'
112
- b.use :input
113
- end
114
- end
115
-
116
- def custom_wrapper_with_input_attributes
117
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
118
- b.use :input, data: { modal: true }
119
- end
120
- end
121
-
122
- def custom_wrapper_with_label_input_class
123
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
124
- b.use :label_input, class: 'inline-class'
125
- end
126
- end
127
-
128
- def custom_wrapper_with_wrapped_input
129
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
130
- b.wrapper tag: :div, class: 'elem' do |component|
131
- component.use :label
132
- component.use :input, wrap_with: { tag: :div, class: 'input' }
133
- end
134
- end
135
- end
136
-
137
- def custom_wrapper_with_wrapped_label
138
- SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
139
- b.wrapper tag: :div, class: 'elem' do |component|
140
- component.use :label, wrap_with: { tag: :div, class: 'label' }
141
- component.use :input
142
- end
143
- end
144
- end
145
-
146
- def custom_wrapper_without_top_level
147
- SimpleForm.build tag: false, class: 'custom_wrapper_without_top_level' do |b|
148
- b.use :label_input
149
- b.use :hint, wrap_with: { tag: :span, class: :hint }
150
- b.use :error, wrap_with: { tag: :span, class: :error }
151
- end
152
- end
153
-
154
- def custom_wrapper_without_class
155
- SimpleForm.build tag: :div, wrapper_html: { id: 'custom_wrapper_without_class' } do |b|
156
- b.use :label_input
157
- end
158
- end
159
-
160
- def custom_wrapper_with_label_html_option
161
- SimpleForm.build tag: :div, class: "custom_wrapper", label_html: { class: 'extra-label-class' } do |b|
162
- b.use :label_input
163
- end
164
- end
165
-
166
- def custom_wrapper_with_wrapped_label_input
167
- SimpleForm.build tag: :section, class: "custom_wrapper", pattern: false do |b|
168
- b.use :label_input, wrap_with: { tag: :div, class: :field }
169
- end
170
- end
171
-
172
- def custom_wrapper_with_additional_attributes
173
- SimpleForm.build tag: :div, class: 'custom_wrapper', html: { data: { wrapper: :test }, title: 'some title' } do |b|
174
- b.use :label_input
175
- end
176
- end
177
-
178
- def custom_wrapper_with_full_error
179
- SimpleForm.build tag: :div, class: 'custom_wrapper' do |b|
180
- b.use :full_error, wrap_with: { tag: :span, class: :error }
181
- end
182
- end
183
-
184
- def custom_wrapper_with_label_text
185
- SimpleForm.build label_text: proc { |label, required| "**#{label}**" } do |b|
186
- b.use :label_input
187
- end
188
- end
189
-
190
- def custom_wrapper_with_custom_label_component
191
- SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
192
- b.use :label_text
193
- end
194
- end
195
-
196
- def custom_wrapper_with_html5_components
197
- SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
198
- b.use :label_text
199
- end
200
- end
201
-
202
- def custom_wrapper_with_required_input
203
- SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
204
- b.use :html5
205
- b.use :input, required: true
206
- end
207
- end
208
-
209
- def custom_wrapper_with_input_error_class
210
- SimpleForm.build tag: :div, class: "custom_wrapper", error_class: :field_with_errors do |b|
211
- b.use :label
212
- b.use :input, class: 'inline-class', error_class: 'is-invalid'
213
- end
214
- end
215
-
216
- def custom_wrapper_with_input_valid_class(valid_class: :field_without_errors)
217
- SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: valid_class do |b|
218
- b.use :label
219
- b.use :input, class: 'inline-class', valid_class: 'is-valid'
220
- end
221
- end
222
-
223
- def custom_form_for(object, *args, &block)
224
- simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
225
- end
226
-
227
- def custom_mapping_form_for(object, *args, &block)
228
- simple_form_for(object, *args, { builder: CustomMapTypeFormBuilder }, &block)
229
- end
230
-
231
- def with_concat_form_for(*args, &block)
232
- concat simple_form_for(*args, &(block || proc {}))
233
- end
234
-
235
- def with_concat_fields_for(*args, &block)
236
- concat simple_fields_for(*args, &block)
237
- end
238
-
239
- def with_concat_custom_form_for(*args, &block)
240
- concat custom_form_for(*args, &block)
241
- end
242
-
243
- def with_concat_custom_mapping_form_for(*args, &block)
244
- concat custom_mapping_form_for(*args, &block)
245
- end
246
-
247
- def with_form_for(object, *args, &block)
248
- with_concat_form_for(object) do |f|
249
- f.input(*args, &block)
250
- end
251
- end
252
-
253
- def with_input_for(object, attribute_name, type, options = {})
254
- with_concat_form_for(object) do |f|
255
- f.input(attribute_name, options.merge(as: type))
256
- end
257
- end
258
-
259
- def with_input_field_for(object, *args)
260
- with_concat_form_for(object) do |f|
261
- f.input_field(*args)
262
- end
263
- end
264
- end
265
-
266
- class CustomFormBuilder < SimpleForm::FormBuilder
267
- def input(attribute_name, *args, &block)
268
- super(attribute_name, *args, { input_html: { class: 'custom' } }, &block)
269
- end
270
- end
271
-
272
- class CustomMapTypeFormBuilder < SimpleForm::FormBuilder
273
- map_type :custom_type, to: SimpleForm::Inputs::StringInput
274
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
- class MockController
3
- attr_writer :action_name
4
-
5
- def _routes
6
- self
7
- end
8
-
9
- def action_name
10
- defined?(@action_name) ? @action_name : "edit"
11
- end
12
-
13
- def url_for(*)
14
- "http://example.com"
15
- end
16
-
17
- def url_options
18
- {}
19
- end
20
-
21
- def polymorphic_mappings(*); {}; end
22
-
23
- def hash_for_user_path(*); end
24
-
25
- def hash_for_validating_user_path(*); end
26
-
27
- def hash_for_other_validating_user_path(*); end
28
-
29
- def hash_for_users_path(*); end
30
- end