simple_form 5.0.0 → 5.3.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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -8
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +96 -51
  5. data/lib/generators/simple_form/install_generator.rb +2 -2
  6. data/lib/generators/simple_form/templates/README +2 -3
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +2 -2
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +127 -195
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
  10. data/lib/simple_form/components/label_input.rb +1 -1
  11. data/lib/simple_form/components/labels.rb +3 -5
  12. data/lib/simple_form/components/maxlength.rb +0 -4
  13. data/lib/simple_form/components/minlength.rb +0 -4
  14. data/lib/simple_form/form_builder.rb +7 -10
  15. data/lib/simple_form/inputs/base.rb +0 -3
  16. data/lib/simple_form/inputs/boolean_input.rb +6 -2
  17. data/lib/simple_form/inputs/collection_check_boxes_input.rb +1 -1
  18. data/lib/simple_form/inputs/collection_input.rb +3 -5
  19. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -1
  20. data/lib/simple_form/inputs/priority_input.rb +16 -2
  21. data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
  22. data/lib/simple_form/inputs.rb +1 -0
  23. data/lib/simple_form/railtie.rb +4 -0
  24. data/lib/simple_form/version.rb +1 -1
  25. data/lib/simple_form/wrappers/leaf.rb +1 -1
  26. data/lib/simple_form/wrappers/root.rb +8 -3
  27. data/lib/simple_form.rb +10 -6
  28. metadata +22 -93
  29. data/lib/simple_form/i18n_cache.rb +0 -23
  30. data/test/action_view_extensions/builder_test.rb +0 -634
  31. data/test/action_view_extensions/form_helper_test.rb +0 -172
  32. data/test/components/custom_components_test.rb +0 -62
  33. data/test/components/label_test.rb +0 -356
  34. data/test/form_builder/association_test.rb +0 -252
  35. data/test/form_builder/button_test.rb +0 -48
  36. data/test/form_builder/error_notification_test.rb +0 -80
  37. data/test/form_builder/error_test.rb +0 -281
  38. data/test/form_builder/general_test.rb +0 -534
  39. data/test/form_builder/hint_test.rb +0 -150
  40. data/test/form_builder/input_field_test.rb +0 -195
  41. data/test/form_builder/label_test.rb +0 -136
  42. data/test/form_builder/wrapper_test.rb +0 -371
  43. data/test/generators/simple_form_generator_test.rb +0 -43
  44. data/test/inputs/boolean_input_test.rb +0 -243
  45. data/test/inputs/collection_check_boxes_input_test.rb +0 -327
  46. data/test/inputs/collection_radio_buttons_input_test.rb +0 -450
  47. data/test/inputs/collection_select_input_test.rb +0 -378
  48. data/test/inputs/color_input_test.rb +0 -10
  49. data/test/inputs/datetime_input_test.rb +0 -176
  50. data/test/inputs/disabled_test.rb +0 -92
  51. data/test/inputs/discovery_test.rb +0 -142
  52. data/test/inputs/file_input_test.rb +0 -17
  53. data/test/inputs/general_test.rb +0 -133
  54. data/test/inputs/grouped_collection_select_input_test.rb +0 -183
  55. data/test/inputs/hidden_input_test.rb +0 -32
  56. data/test/inputs/numeric_input_test.rb +0 -177
  57. data/test/inputs/priority_input_test.rb +0 -50
  58. data/test/inputs/readonly_test.rb +0 -102
  59. data/test/inputs/required_test.rb +0 -158
  60. data/test/inputs/string_input_test.rb +0 -158
  61. data/test/inputs/text_input_test.rb +0 -37
  62. data/test/simple_form_test.rb +0 -18
  63. data/test/support/discovery_inputs.rb +0 -65
  64. data/test/support/misc_helpers.rb +0 -274
  65. data/test/support/mock_controller.rb +0 -30
  66. data/test/support/models.rb +0 -353
  67. data/test/test_helper.rb +0 -95
@@ -1,195 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- # Tests for f.input_field
5
- class InputFieldTest < ActionView::TestCase
6
- test "builder input_field only renders the input tag, nothing else" do
7
- with_input_field_for @user, :name
8
-
9
- assert_select 'form > input.required.string'
10
- assert_no_select 'div.string'
11
- assert_no_select 'label'
12
- assert_no_select '.hint'
13
- end
14
-
15
- test 'builder input_field allows overriding default input type' do
16
- with_input_field_for @user, :name, as: :text
17
-
18
- assert_no_select 'input#user_name'
19
- assert_select 'textarea#user_name.text'
20
- end
21
-
22
- test 'builder input_field generates input type based on column type' do
23
- with_input_field_for @user, :age
24
-
25
- assert_select 'input[type=number].integer#user_age'
26
- end
27
-
28
- test 'builder input_field is able to disable any component' do
29
- with_input_field_for @user, :age, html5: false
30
-
31
- assert_no_select 'input[html5=false]#user_age'
32
- assert_select 'input[type=text].integer#user_age'
33
- end
34
-
35
- test 'builder input_field allows passing options to input tag' do
36
- with_input_field_for @user, :name, id: 'name_input', class: 'name'
37
-
38
- assert_select 'input.string.name#name_input'
39
- end
40
-
41
- test 'builder input_field does not modify the options hash' do
42
- options = { id: 'name_input', class: 'name' }
43
- with_input_field_for @user, :name, options
44
-
45
- assert_select 'input.string.name#name_input'
46
- assert_equal({ id: 'name_input', class: 'name' }, options)
47
- end
48
-
49
-
50
- test 'builder input_field generates an input tag with a clean HTML' do
51
- with_input_field_for @user, :name, as: :integer, class: 'name'
52
-
53
- assert_no_select 'input.integer[input_html]'
54
- assert_no_select 'input.integer[as]'
55
- end
56
-
57
- test 'builder input_field uses i18n to translate placeholder text' do
58
- store_translations(:en, simple_form: { placeholders: { user: {
59
- name: 'Name goes here'
60
- } } }) do
61
- with_input_field_for @user, :name
62
-
63
- assert_select 'input.string[placeholder="Name goes here"]'
64
- end
65
- end
66
-
67
- test 'builder input_field uses min_max component' do
68
- with_input_field_for @other_validating_user, :age, as: :integer
69
-
70
- assert_select 'input[min="18"]'
71
- end
72
-
73
- test 'builder input_field does not use pattern component by default' do
74
- with_input_field_for @other_validating_user, :country, as: :string
75
-
76
- assert_no_select 'input[pattern="\w+"]'
77
- end
78
-
79
- test 'builder input_field infers pattern from attributes' do
80
- with_input_field_for @other_validating_user, :country, as: :string, pattern: true
81
-
82
- assert_select "input:match('pattern', ?)", /\w+/
83
- end
84
-
85
- test 'builder input_field accepts custom pattern' do
86
- with_input_field_for @other_validating_user, :country, as: :string, pattern: '\d+'
87
-
88
- assert_select "input:match('pattern', ?)", /\\d+/
89
- end
90
-
91
- test 'builder input_field uses readonly component' do
92
- with_input_field_for @other_validating_user, :age, as: :integer, readonly: true
93
-
94
- assert_select 'input.integer.readonly[readonly]'
95
- end
96
-
97
- test 'builder input_field uses maxlength component' do
98
- with_input_field_for @validating_user, :name, as: :string
99
-
100
- assert_select 'input.string[maxlength="25"]'
101
- end
102
-
103
- test 'builder input_field uses minlength component' do
104
- with_input_field_for @validating_user, :name, as: :string
105
-
106
- assert_select 'input.string[minlength="5"]'
107
- end
108
-
109
- test 'builder collection input_field generates input tag with a clean HTML' do
110
- with_input_field_for @user, :status, collection: %w[Open Closed],
111
- class: 'status', label_method: :to_s, value_method: :to_s
112
-
113
- assert_no_select 'select.status[input_html]'
114
- assert_no_select 'select.status[collection]'
115
- assert_no_select 'select.status[label_method]'
116
- assert_no_select 'select.status[value_method]'
117
- end
118
-
119
- test 'build input_field does not treat "boolean_style" as a HTML attribute' do
120
- with_input_field_for @user, :active, boolean_style: :nested
121
-
122
- assert_no_select 'input.boolean[boolean_style]'
123
- end
124
-
125
- test 'build input_field does not treat "prompt" as a HTML attribute' do
126
- with_input_field_for @user, :attempts, collection: [1,2,3,4,5], prompt: :translate
127
-
128
- assert_no_select 'select[prompt]'
129
- end
130
-
131
- test 'build input_field without pattern component use the pattern string' do
132
- swap_wrapper :default, custom_wrapper_with_html5_components do
133
- with_input_field_for @user, :name, pattern: '\w+'
134
-
135
- assert_select "input:match('pattern', ?)", /\w+/
136
- end
137
- end
138
-
139
- test 'build input_field without placeholder component use the placeholder string' do
140
- swap_wrapper :default, custom_wrapper_with_html5_components do
141
- with_input_field_for @user, :name, placeholder: 'Placeholder'
142
-
143
- assert_select 'input[placeholder="Placeholder"]'
144
- end
145
- end
146
-
147
- test 'build input_field without maxlength component use the maxlength string' do
148
- swap_wrapper :default, custom_wrapper_with_html5_components do
149
- with_input_field_for @user, :name, maxlength: 5
150
-
151
- assert_select 'input[maxlength="5"]'
152
- end
153
- end
154
-
155
- test 'build input_field without minlength component use the minlength string' do
156
- swap_wrapper :default, custom_wrapper_with_html5_components do
157
- with_input_field_for @user, :name, minlength: 5
158
-
159
- assert_select 'input[minlength="5"]'
160
- end
161
- end
162
-
163
- test 'build input_field without readonly component use the readonly string' do
164
- swap_wrapper :default, custom_wrapper_with_html5_components do
165
- with_input_field_for @user, :name, readonly: true
166
-
167
- assert_select 'input[readonly="readonly"]'
168
- end
169
- end
170
-
171
- test 'adds valid class to input_field when it is configured' do
172
- swap SimpleForm, input_field_valid_class: 'is-valid' do
173
- @user.instance_eval { undef errors }
174
- with_input_field_for @user, :name
175
-
176
- assert_select 'input.string.required.is-valid'
177
- end
178
- end
179
-
180
- test 'adds error class to input_field when it is configured' do
181
- swap SimpleForm, input_field_error_class: 'is-invalid' do
182
- with_input_field_for @user, :name
183
-
184
- assert_select 'input.string.required.is-invalid'
185
- end
186
- end
187
-
188
- test 'does not add validation classes to input_field when it is not configured' do
189
- swap SimpleForm, input_field_error_class: nil, input_field_valid_class: nil do
190
- with_input_field_for @user, :name
191
-
192
- assert_select 'input.string.required'
193
- end
194
- end
195
- end
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class LabelTest < ActionView::TestCase
6
- def with_label_for(object, *args, &block)
7
- with_concat_form_for(object) do |f|
8
- f.label(*args, &block)
9
- end
10
- end
11
-
12
- test 'builder generates a label for the attribute' do
13
- with_label_for @user, :name
14
- assert_select 'label.string[for=user_name]', /Name/
15
- end
16
-
17
- test 'builder generates a label for the attribute with decorated object responsive to #to_model' do
18
- with_label_for @decorated_user, :name
19
- assert_select 'label.string[for=user_name]', /Name/
20
- end
21
-
22
- test 'builder generates a label for the boolean attrbiute' do
23
- with_label_for @user, :name, as: :boolean
24
- assert_select 'label.boolean[for=user_name]', /Name/
25
- assert_no_select 'label[as=boolean]'
26
- end
27
-
28
- test 'builder generates a label component tag with a clean HTML' do
29
- with_label_for @user, :name
30
- assert_no_select 'label.string[label_html]'
31
- end
32
-
33
- test 'builder adds a required class to label if the attribute is required' do
34
- with_label_for @validating_user, :name
35
- assert_select 'label.string.required[for=validating_user_name]', /Name/
36
- end
37
-
38
- test 'builder adds a disabled class to label if the attribute is disabled' do
39
- with_label_for @validating_user, :name, disabled: true
40
- assert_select 'label.string.disabled[for=validating_user_name]', /Name/
41
- end
42
-
43
- test 'builder does not add a disabled class to label if the attribute is not disabled' do
44
- with_label_for @validating_user, :name, disabled: false
45
- assert_no_select 'label.string.disabled[for=validating_user_name]', /Name/
46
- end
47
-
48
- test 'builder escapes label text' do
49
- with_label_for @user, :name, label: '<script>alert(1337)</script>', required: false
50
- assert_no_select 'label.string script'
51
- end
52
-
53
- test 'builder does not escape label text if it is safe' do
54
- with_label_for @user, :name, label: '<script>alert(1337)</script>'.html_safe, required: false
55
- assert_select 'label.string script', "alert(1337)"
56
- end
57
-
58
- test 'builder allows passing options to label tag' do
59
- with_label_for @user, :name, label: 'My label', id: 'name_label'
60
- assert_select 'label.string#name_label', /My label/
61
- end
62
-
63
- test 'builder label generates label tag with clean HTML' do
64
- with_label_for @user, :name, label: 'My label', required: true, id: 'name_label'
65
- assert_select 'label.string#name_label', /My label/
66
- assert_no_select 'label[label]'
67
- assert_no_select 'label[required]'
68
- end
69
-
70
- test 'builder does not modify the options hash' do
71
- options = { label: 'My label', id: 'name_label' }
72
- with_label_for @user, :name, options
73
- assert_select 'label.string#name_label', /My label/
74
- assert_equal({ label: 'My label', id: 'name_label' }, options)
75
- end
76
-
77
- test 'builder fallbacks to default label when string is given' do
78
- with_label_for @user, :name, 'Nome do usuário'
79
- assert_select 'label', 'Nome do usuário'
80
- assert_no_select 'label.string'
81
- end
82
-
83
- test 'builder fallbacks to default label when block is given' do
84
- with_label_for @user, :name do
85
- 'Nome do usuário'
86
- end
87
- assert_select 'label', 'Nome do usuário'
88
- assert_no_select 'label.string'
89
- end
90
-
91
- test 'builder allows label order to be changed' do
92
- swap SimpleForm, label_text: proc { |l, r| "#{l}:" } do
93
- with_label_for @user, :age
94
- assert_select 'label.integer[for=user_age]', "Age:"
95
- end
96
- end
97
-
98
- test 'configuration allow set label text for wrappers' do
99
- swap_wrapper :default, custom_wrapper_with_label_text do
100
- with_concat_form_for(@user) do |f|
101
- concat f.input :age
102
- end
103
- assert_select "label.integer[for=user_age]", "**Age**"
104
- end
105
- end
106
-
107
- test 'configuration allow set rewrited label tag for wrappers' do
108
- swap_wrapper :default, custom_wrapper_with_custom_label_component do
109
- with_concat_form_for(@user) do |f|
110
- concat f.input :age
111
- end
112
- assert_select "span.integer.user_age", /Age/
113
- end
114
- end
115
-
116
- test 'builder allows custom formatting when label is explicitly specified' do
117
- swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
118
- with_label_for @user, :time_zone, 'What is your home time zone?'
119
- assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
120
- end
121
- end
122
-
123
- test 'builder allows custom formatting when label is generated' do
124
- swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
125
- with_label_for @user, :time_zone
126
- assert_select 'label[for=user_time_zone]', 'Time Zone:'
127
- end
128
- end
129
-
130
- test 'builder allows label specific `label_text` option' do
131
- with_label_for @user, :time_zone, label_text: ->(l, _, _) { "#{l.titleize}:" }
132
-
133
- assert_no_select 'label[label_text]'
134
- assert_select 'label[for=user_time_zone]', 'Time Zone:'
135
- end
136
- end
@@ -1,371 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- class WrapperTest < ActionView::TestCase
5
- test 'wrapper does not have error class for attribute without errors' do
6
- with_form_for @user, :active
7
- assert_no_select 'div.field_with_errors'
8
- end
9
-
10
- test 'wrapper does not have error class when object is not present' do
11
- with_form_for :project, :name
12
- assert_no_select 'div.field_with_errors'
13
- end
14
-
15
- test 'wrapper adds the attribute name class' do
16
- with_form_for @user, :name
17
- assert_select 'div.user_name'
18
- end
19
-
20
- test 'wrapper adds the attribute name class for nested forms' do
21
- @user.company = Company.new(1, 'Empresa')
22
- with_concat_form_for @user do |f|
23
- concat(f.simple_fields_for(:company) do |company_form|
24
- concat(company_form.input :name)
25
- end)
26
- end
27
-
28
- assert_select 'div.user_company_name'
29
- end
30
-
31
- test 'wrapper adds the association name class' do
32
- with_form_for @user, :company
33
- assert_select 'div.user_company'
34
- end
35
-
36
- test 'wrapper adds error class for attribute with errors' do
37
- with_form_for @user, :name
38
- assert_select 'div.field_with_errors'
39
- end
40
-
41
- test 'wrapper adds error class to input for attribute with errors' do
42
- with_form_for @user, :name, wrapper: custom_wrapper_with_input_error_class
43
- assert_select 'div.field_with_errors'
44
- assert_select 'input.is-invalid'
45
- end
46
-
47
- test 'wrapper does not add error class to input when the attribute is valid' do
48
- with_form_for @user, :phone_number, wrapper: custom_wrapper_with_input_error_class
49
- assert_no_select 'div.field_with_errors'
50
- assert_no_select 'input.is-invalid'
51
- end
52
-
53
- test 'wrapper adds valid class for present attribute without errors' do
54
- @user.instance_eval { undef errors }
55
- with_form_for @user, :name, wrapper: custom_wrapper_with_input_valid_class
56
- assert_select 'div.field_without_errors'
57
- assert_select 'input.is-valid'
58
- assert_no_select 'div.field_with_errors'
59
- assert_no_select 'input.is-invalid'
60
- end
61
-
62
- test 'wrapper adds hint class for attribute with a hint' do
63
- with_form_for @user, :name, hint: 'hint'
64
- assert_select 'div.field_with_hint'
65
- end
66
-
67
- test 'wrapper does not have disabled class by default' do
68
- with_form_for @user, :active
69
- assert_no_select 'div.disabled'
70
- end
71
-
72
- test 'wrapper has disabled class when input is disabled' do
73
- with_form_for @user, :active, disabled: true
74
- assert_select 'div.disabled'
75
- end
76
-
77
- test 'wrapper supports no wrapping when wrapper is false' do
78
- with_form_for @user, :name, wrapper: false
79
- assert_select 'form > label[for=user_name]'
80
- assert_select 'form > input#user_name.string'
81
- end
82
-
83
- test 'wrapper supports no wrapping when wrapper tag is false' do
84
- with_form_for @user, :name, wrapper: custom_wrapper_without_top_level
85
- assert_select 'form > label[for=user_name]'
86
- assert_select 'form > input#user_name.string'
87
- end
88
-
89
- test 'wrapper wraps tag adds required/optional css classes' do
90
- with_form_for @user, :name
91
- assert_select 'form div.input.required.string'
92
-
93
- with_form_for @user, :age, required: false
94
- assert_select 'form div.input.optional.integer'
95
- end
96
-
97
- test 'wrapper allows custom options to be given' do
98
- with_form_for @user, :name, wrapper_html: { id: "super_cool", class: 'yay' }
99
- assert_select 'form #super_cool.required.string.yay'
100
- end
101
-
102
- test 'wrapper allows tag to be given on demand' do
103
- with_form_for @user, :name, wrapper_tag: :b
104
- assert_select 'form b.required.string'
105
- end
106
-
107
- test 'wrapper allows wrapper class to be given on demand' do
108
- with_form_for @user, :name, wrapper_class: :wrapper
109
- assert_select 'form div.wrapper.required.string'
110
- end
111
-
112
- test 'wrapper skips additional classes when configured' do
113
- swap SimpleForm, generate_additional_classes_for: %i[input label] do
114
- with_form_for @user, :name, wrapper_class: :wrapper
115
- assert_select 'form div.wrapper'
116
- assert_no_select 'div.required'
117
- assert_no_select 'div.string'
118
- assert_no_select 'div.user_name'
119
- end
120
- end
121
-
122
- test 'wrapper does not generate empty css class' do
123
- swap SimpleForm, generate_additional_classes_for: %i[input label] do
124
- swap_wrapper :default, custom_wrapper_without_class do
125
- with_form_for @user, :name
126
- assert_no_select 'div#custom_wrapper_without_class[class]'
127
- end
128
- end
129
- end
130
-
131
- # Custom wrapper test
132
-
133
- test 'custom wrappers works' do
134
- swap_wrapper do
135
- with_form_for @user, :name, hint: "cool"
136
- assert_select "section.custom_wrapper div.another_wrapper label"
137
- assert_select "section.custom_wrapper div.another_wrapper input.string"
138
- assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
139
- assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
140
- assert_select "section.custom_wrapper > div.omg_hint", "cool"
141
- end
142
- end
143
-
144
- test 'custom wrappers can be turned off' do
145
- swap_wrapper do
146
- with_form_for @user, :name, another: false
147
- assert_no_select "section.custom_wrapper div.another_wrapper label"
148
- assert_no_select "section.custom_wrapper div.another_wrapper input.string"
149
- assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
150
- end
151
- end
152
-
153
- test 'custom wrappers can have additional attributes' do
154
- swap_wrapper :default, custom_wrapper_with_additional_attributes do
155
- with_form_for @user, :name
156
-
157
- assert_select "div.custom_wrapper[title='some title'][data-wrapper='test']"
158
- end
159
- end
160
-
161
- test 'custom wrappers can have full error message on attributes' do
162
- swap_wrapper :default, custom_wrapper_with_full_error do
163
- with_form_for @user, :name
164
- assert_select 'span.error', "Super User Name! cannot be blank"
165
- end
166
- end
167
-
168
- test 'custom wrappers on a form basis' do
169
- swap_wrapper :another do
170
- with_concat_form_for(@user) do |f|
171
- f.input :name
172
- end
173
-
174
- assert_no_select "section.custom_wrapper div.another_wrapper label"
175
- assert_no_select "section.custom_wrapper div.another_wrapper input.string"
176
-
177
- with_concat_form_for(@user, wrapper: :another) do |f|
178
- f.input :name
179
- end
180
-
181
- assert_select "section.custom_wrapper div.another_wrapper label"
182
- assert_select "section.custom_wrapper div.another_wrapper input.string"
183
- end
184
- end
185
-
186
- test 'custom wrappers on input basis' do
187
- swap_wrapper :another do
188
- with_form_for @user, :name
189
- assert_no_select "section.custom_wrapper div.another_wrapper label"
190
- assert_no_select "section.custom_wrapper div.another_wrapper input.string"
191
- output_buffer.replace ""
192
-
193
- with_form_for @user, :name, wrapper: :another
194
- assert_select "section.custom_wrapper div.another_wrapper label"
195
- assert_select "section.custom_wrapper div.another_wrapper input.string"
196
- output_buffer.replace ""
197
- end
198
-
199
- with_form_for @user, :name, wrapper: custom_wrapper
200
- assert_select "section.custom_wrapper div.another_wrapper label"
201
- assert_select "section.custom_wrapper div.another_wrapper input.string"
202
- end
203
-
204
- test 'access wrappers with indifferent access' do
205
- swap_wrapper :another do
206
- with_form_for @user, :name, wrapper: "another"
207
- assert_select "section.custom_wrapper div.another_wrapper label"
208
- assert_select "section.custom_wrapper div.another_wrapper input.string"
209
- end
210
- end
211
-
212
- test 'does not duplicate label classes for different inputs' do
213
- swap_wrapper :default, custom_wrapper_with_label_html_option do
214
- with_concat_form_for(@user) do |f|
215
- concat f.input :name, required: false
216
- concat f.input :email, as: :email, required: true
217
- end
218
-
219
- assert_select "label.string.optional.extra-label-class[for='user_name']"
220
- assert_select "label.email.required.extra-label-class[for='user_email']"
221
- assert_no_select "label.string.optional.extra-label-class[for='user_email']"
222
- end
223
- end
224
-
225
- test 'raise error when wrapper not found' do
226
- assert_raise SimpleForm::WrapperNotFound do
227
- with_form_for @user, :name, wrapper: :not_found
228
- end
229
- end
230
-
231
- test 'uses wrapper for specified in config mapping' do
232
- swap_wrapper :another do
233
- swap SimpleForm, wrapper_mappings: { string: :another } do
234
- with_form_for @user, :name
235
- assert_select "section.custom_wrapper div.another_wrapper label"
236
- assert_select "section.custom_wrapper div.another_wrapper input.string"
237
- end
238
- end
239
- end
240
-
241
- test 'uses custom wrapper mapping per form basis' do
242
- swap_wrapper :another do
243
- with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
244
- concat f.input :name
245
- end
246
- end
247
-
248
- assert_select "section.custom_wrapper div.another_wrapper label"
249
- assert_select "section.custom_wrapper div.another_wrapper input.string"
250
- end
251
-
252
- test 'simple_fields_form reuses custom wrapper mapping per form basis' do
253
- @user.company = Company.new(1, 'Empresa')
254
-
255
- swap_wrapper :another do
256
- with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
257
- concat(f.simple_fields_for(:company) do |company_form|
258
- concat(company_form.input(:name))
259
- end)
260
- end
261
- end
262
-
263
- assert_select "section.custom_wrapper div.another_wrapper label"
264
- assert_select "section.custom_wrapper div.another_wrapper input.string"
265
- end
266
-
267
- test "input attributes class will merge with wrapper_options' classes" do
268
- swap_wrapper :default, custom_wrapper_with_input_class do
269
- with_concat_form_for @user do |f|
270
- concat f.input :name, input_html: { class: 'another-class' }
271
- end
272
- end
273
-
274
- assert_select "div.custom_wrapper input.string.inline-class.another-class"
275
- end
276
-
277
- test "input with data attributes will merge with wrapper_options' data" do
278
- swap_wrapper :default, custom_wrapper_with_input_data_modal do
279
- with_concat_form_for @user do |f|
280
- concat f.input :name, input_html: { data: { modal: 'another-data', target: 'merge-data' } }
281
- end
282
- end
283
-
284
- assert_select "input[data-wrapper='data-wrapper'][data-modal='another-data'][data-target='merge-data']"
285
- end
286
-
287
- test "input with aria attributes will merge with wrapper_options' aria" do
288
- swap_wrapper :default, custom_wrapper_with_input_aria_modal do
289
- with_concat_form_for @user do |f|
290
- concat f.input :name, input_html: { aria: { modal: 'another-aria', target: 'merge-aria' } }
291
- end
292
- end
293
-
294
- assert_select "input[aria-wrapper='aria-wrapper'][aria-modal='another-aria'][aria-target='merge-aria']"
295
- end
296
-
297
- test 'input accepts attributes in the DSL' do
298
- swap_wrapper :default, custom_wrapper_with_input_class do
299
- with_concat_form_for @user do |f|
300
- concat f.input :name
301
- end
302
- end
303
-
304
- assert_select "div.custom_wrapper input.string.inline-class"
305
- end
306
-
307
- test 'label accepts attributes in the DSL' do
308
- swap_wrapper :default, custom_wrapper_with_label_class do
309
- with_concat_form_for @user do |f|
310
- concat f.input :name
311
- end
312
- end
313
-
314
- assert_select "div.custom_wrapper label.string.inline-class"
315
- end
316
-
317
- test 'label_input accepts attributes in the DSL' do
318
- swap_wrapper :default, custom_wrapper_with_label_input_class do
319
- with_concat_form_for @user do |f|
320
- concat f.input :name
321
- end
322
- end
323
-
324
- assert_select "div.custom_wrapper label.string.inline-class"
325
- assert_select "div.custom_wrapper input.string.inline-class"
326
- end
327
-
328
- test 'input accepts data attributes in the DSL' do
329
- swap_wrapper :default, custom_wrapper_with_input_attributes do
330
- with_concat_form_for @user do |f|
331
- concat f.input :name
332
- end
333
- end
334
-
335
- assert_select "div.custom_wrapper input.string[data-modal=true]"
336
- end
337
-
338
- test 'inline wrapper displays when there is content' do
339
- swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
340
- with_form_for @user, :name, hint: "cannot be blank"
341
- assert_select 'section.custom_wrapper div.no_output_wrapper p.omg_hint', "cannot be blank"
342
- assert_select 'p.omg_hint'
343
- end
344
- end
345
-
346
- test 'inline wrapper does not display when there is no content' do
347
- swap_wrapper :default, custom_wrapper_with_wrapped_optional_component do
348
- with_form_for @user, :name
349
- assert_select 'section.custom_wrapper div.no_output_wrapper'
350
- assert_no_select 'p.omg_hint'
351
- end
352
- end
353
-
354
- test 'optional wrapper does not display when there is content' do
355
- swap_wrapper :default, custom_wrapper_with_unless_blank do
356
- with_form_for @user, :name, hint: "can't be blank"
357
- assert_select 'section.custom_wrapper div.no_output_wrapper'
358
- assert_select 'div.no_output_wrapper'
359
- assert_select 'p.omg_hint'
360
- end
361
- end
362
-
363
- test 'optional wrapper does not display when there is no content' do
364
- swap_wrapper :default, custom_wrapper_with_unless_blank do
365
- with_form_for @user, :name
366
- assert_no_select 'section.custom_wrapper div.no_output_wrapper'
367
- assert_no_select 'div.no_output_wrapper'
368
- assert_no_select 'p.omg_hint'
369
- end
370
- end
371
- end