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,177 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class NumericInputTest < ActionView::TestCase
6
- test 'input generates an integer text field for integer attributes ' do
7
- with_input_for @user, :age, :integer
8
- assert_select 'input[type=number].integer#user_age'
9
- end
10
-
11
- test 'input generates a float text field for float attributes ' do
12
- with_input_for @user, :age, :float
13
- assert_select 'input[type=number].float#user_age'
14
- end
15
-
16
- test 'input generates a decimal text field for decimal attributes ' do
17
- with_input_for @user, :age, :decimal
18
- assert_select 'input[type=number].decimal#user_age'
19
- end
20
-
21
- test 'input does not generate min attribute by default' do
22
- with_input_for @user, :age, :integer
23
- assert_no_select 'input[min]'
24
- end
25
-
26
- test 'input does not generate max attribute by default' do
27
- with_input_for @user, :age, :integer
28
- assert_no_select 'input[max]'
29
- end
30
-
31
- test 'input infers min value from integer attributes with greater than validation' do
32
- with_input_for @other_validating_user, :age, :float
33
- assert_no_select 'input[min]'
34
-
35
- with_input_for @other_validating_user, :age, :integer
36
- assert_select 'input[min="18"]'
37
- end
38
-
39
- test 'input infers min value from integer attributes with greater than validation using symbol' do
40
- with_input_for @validating_user, :amount, :float
41
- assert_no_select 'input[min]'
42
-
43
- with_input_for @validating_user, :amount, :integer
44
- assert_select 'input[min="11"]'
45
- end
46
-
47
- test 'input infers min value from integer attributes with greater than or equal to validation using symbol' do
48
- with_input_for @validating_user, :attempts, :float
49
- assert_select 'input[min="1"]'
50
-
51
- with_input_for @validating_user, :attempts, :integer
52
- assert_select 'input[min="1"]'
53
- end
54
-
55
- test 'input infers min value from integer attributes with greater than validation using proc' do
56
- with_input_for @other_validating_user, :amount, :float
57
- assert_no_select 'input[min]'
58
-
59
- with_input_for @other_validating_user, :amount, :integer
60
- assert_select 'input[min="20"]'
61
- end
62
-
63
- test 'input infers min value from integer attributes with greater than or equal to validation using proc' do
64
- with_input_for @other_validating_user, :attempts, :float
65
- assert_select 'input[min="19"]'
66
-
67
- with_input_for @other_validating_user, :attempts, :integer
68
- assert_select 'input[min="19"]'
69
- end
70
-
71
- test 'input infers max value from attributes with less than validation' do
72
- with_input_for @other_validating_user, :age, :float
73
- assert_no_select 'input[max]'
74
-
75
- with_input_for @other_validating_user, :age, :integer
76
- assert_select 'input[max="99"]'
77
- end
78
-
79
- test 'input infers max value from attributes with less than validation using symbol' do
80
- with_input_for @validating_user, :amount, :float
81
- assert_no_select 'input[max]'
82
-
83
- with_input_for @validating_user, :amount, :integer
84
- assert_select 'input[max="99"]'
85
- end
86
-
87
- test 'input infers max value from attributes with less than or equal to validation using symbol' do
88
- with_input_for @validating_user, :attempts, :float
89
- assert_select 'input[max="100"]'
90
-
91
- with_input_for @validating_user, :attempts, :integer
92
- assert_select 'input[max="100"]'
93
- end
94
-
95
- test 'input infers max value from attributes with less than validation using proc' do
96
- with_input_for @other_validating_user, :amount, :float
97
- assert_no_select 'input[max]'
98
-
99
- with_input_for @other_validating_user, :amount, :integer
100
- assert_select 'input[max="118"]'
101
- end
102
-
103
- test 'input infers max value from attributes with less than or equal to validation using proc' do
104
- with_input_for @other_validating_user, :attempts, :float
105
- assert_select 'input[max="119"]'
106
-
107
- with_input_for @other_validating_user, :attempts, :integer
108
- assert_select 'input[max="119"]'
109
- end
110
-
111
- test 'input has step value of any except for integer attribute' do
112
- with_input_for @validating_user, :age, :float
113
- assert_select 'input[step="any"]'
114
-
115
- with_input_for @validating_user, :age, :integer
116
- assert_select 'input[step="1"]'
117
-
118
- with_input_for @validating_user, :age, :integer, as: :decimal, input_html: { step: 0.5 }
119
- assert_select 'input[step="0.5"]'
120
- end
121
-
122
- test 'numeric input does not generate placeholder by default' do
123
- with_input_for @user, :age, :integer
124
- assert_no_select 'input[placeholder]'
125
- end
126
-
127
- test 'numeric input accepts the placeholder option' do
128
- with_input_for @user, :age, :integer, placeholder: 'Put in your age'
129
- assert_select 'input.integer[placeholder="Put in your age"]'
130
- end
131
-
132
- test 'numeric input uses i18n to translate placeholder text' do
133
- store_translations(:en, simple_form: { placeholders: { user: {
134
- age: 'Age goes here'
135
- } } }) do
136
- with_input_for @user, :age, :integer
137
- assert_select 'input.integer[placeholder="Age goes here"]'
138
- end
139
- end
140
-
141
- # Numeric input but HTML5 disabled
142
- test 'when not using HTML5 input does not generate field with type number and use text instead' do
143
- swap_wrapper do
144
- with_input_for @user, :age, :integer
145
- assert_no_select "input[type=number]"
146
- assert_no_select "input#user_age[text]"
147
- end
148
- end
149
-
150
- test 'when not using HTML5 input does not use min or max or step attributes' do
151
- swap_wrapper do
152
- with_input_for @validating_user, :age, :integer
153
- assert_no_select "input[type=number]"
154
- assert_no_select "input[min]"
155
- assert_no_select "input[max]"
156
- assert_no_select "input[step]"
157
- end
158
- end
159
-
160
- %i[integer float decimal].each do |type|
161
- test "#{type} input infers min value from attributes with greater than or equal validation" do
162
- with_input_for @validating_user, :age, type
163
- assert_select 'input[min="18"]'
164
- end
165
-
166
- test "#{type} input infers the max value from attributes with less than or equal to validation" do
167
- with_input_for @validating_user, :age, type
168
- assert_select 'input[max="99"]'
169
- end
170
- end
171
-
172
- test 'min_max does not emit max value as bare string' do
173
- with_input_for @other_validating_user, :age, :integer
174
- assert_select 'input[max]'
175
- assert_no_select 'div', %r{^99}
176
- end
177
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- class ReadonlyTest < ActionView::TestCase
5
- test 'string input generates readonly elements when readonly option is true' do
6
- with_input_for @user, :name, :string, readonly: true
7
- assert_select 'input.string.readonly[readonly]'
8
- end
9
-
10
- test 'text input generates readonly elements when readonly option is true' do
11
- with_input_for @user, :description, :text, readonly: true
12
- assert_select 'textarea.text.readonly[readonly]'
13
- end
14
-
15
- test 'numeric input generates readonly elements when readonly option is true' do
16
- with_input_for @user, :age, :integer, readonly: true
17
- assert_select 'input.integer.readonly[readonly]'
18
- end
19
-
20
- test 'date input generates readonly elements when readonly option is true' do
21
- with_input_for @user, :born_at, :date, readonly: true
22
- assert_select 'select.date.readonly[readonly]'
23
- end
24
-
25
- test 'datetime input generates readonly elements when readonly option is true' do
26
- with_input_for @user, :created_at, :datetime, readonly: true
27
- assert_select 'select.datetime.readonly[readonly]'
28
- end
29
-
30
- test 'string input generates readonly elements when readonly option is false' do
31
- with_input_for @user, :name, :string, readonly: false
32
- assert_no_select 'input.string.readonly[readonly]'
33
- end
34
-
35
- test 'text input generates readonly elements when readonly option is false' do
36
- with_input_for @user, :description, :text, readonly: false
37
- assert_no_select 'textarea.text.readonly[readonly]'
38
- end
39
-
40
- test 'numeric input generates readonly elements when readonly option is false' do
41
- with_input_for @user, :age, :integer, readonly: false
42
- assert_no_select 'input.integer.readonly[readonly]'
43
- end
44
-
45
- test 'date input generates readonly elements when readonly option is false' do
46
- with_input_for @user, :born_at, :date, readonly: false
47
- assert_no_select 'select.date.readonly[readonly]'
48
- end
49
-
50
- test 'datetime input generates readonly elements when readonly option is false' do
51
- with_input_for @user, :created_at, :datetime, readonly: false
52
- assert_no_select 'select.datetime.readonly[readonly]'
53
- end
54
-
55
- test 'string input generates readonly elements when readonly option is not present' do
56
- with_input_for @user, :name, :string
57
- assert_no_select 'input.string.readonly[readonly]'
58
- end
59
-
60
- test 'text input generates readonly elements when readonly option is not present' do
61
- with_input_for @user, :description, :text
62
- assert_no_select 'textarea.text.readonly[readonly]'
63
- end
64
-
65
- test 'numeric input generates readonly elements when readonly option is not present' do
66
- with_input_for @user, :age, :integer
67
- assert_no_select 'input.integer.readonly[readonly]'
68
- end
69
-
70
- test 'date input generates readonly elements when readonly option is not present' do
71
- with_input_for @user, :born_at, :date
72
- assert_no_select 'select.date.readonly[readonly]'
73
- end
74
-
75
- test 'datetime input generates readonly elements when readonly option is not present' do
76
- with_input_for @user, :created_at, :datetime
77
- assert_no_select 'select.datetime.readonly[readonly]'
78
- end
79
-
80
- test 'input generates readonly attribute when the field is readonly and the object is persisted' do
81
- with_input_for @user, :credit_card, :string, readonly: :lookup
82
- assert_select 'input.string.readonly[readonly]'
83
- end
84
-
85
- test 'input does not generate readonly attribute when the field is readonly and the object is not persisted' do
86
- @user.new_record!
87
- with_input_for @user, :credit_card, :string, readonly: :lookup
88
- assert_no_select 'input.string.readonly[readonly]'
89
- end
90
-
91
- test 'input does not generate readonly attribute when the field is not readonly and the object is persisted' do
92
- with_input_for @user, :name, :string
93
- assert_no_select 'input.string.readonly[readonly]'
94
- end
95
-
96
- test 'input does not generate readonly attribute when the component is not used' do
97
- swap_wrapper do
98
- with_input_for @user, :credit_card, :string
99
- assert_no_select 'input.string.readonly[readonly]'
100
- end
101
- end
102
- end
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- class RequiredTest < ActionView::TestCase
5
- # REQUIRED AND PRESENCE VALIDATION
6
- test 'builder input obtains required from ActiveModel::Validations when it is included' do
7
- with_form_for @validating_user, :name
8
- assert_select 'input.required[required]#validating_user_name'
9
- with_form_for @validating_user, :status
10
- assert_select 'input.optional#validating_user_status'
11
- end
12
-
13
- test 'builder input allows overriding required when ActiveModel::Validations is included' do
14
- with_form_for @validating_user, :name, required: false
15
- assert_select 'input.optional#validating_user_name'
16
- with_form_for @validating_user, :status, required: true
17
- assert_select 'input.required[required]#validating_user_status'
18
- end
19
-
20
- test 'builder input is required by default when ActiveModel::Validations is not included' do
21
- with_form_for @user, :name
22
- assert_select 'input.required[required]#user_name'
23
- end
24
-
25
- test 'builder input does not be required by default when ActiveModel::Validations is not included if option is set to false' do
26
- swap SimpleForm, required_by_default: false do
27
- with_form_for @user, :name
28
- assert_select 'input.optional#user_name'
29
- assert_no_select 'input[required]'
30
- end
31
- end
32
-
33
- test 'when not using browser validations, input does not generate required html attribute' do
34
- swap SimpleForm, browser_validations: false do
35
- with_input_for @user, :name, :string
36
- assert_select 'input[type=text].required'
37
- assert_no_select 'input[type=text][required]'
38
- assert_no_select 'input[type=text][aria-required]'
39
- end
40
- end
41
-
42
- test 'when not using browser validations, when required option is set to false, input does not generate required html attribute' do
43
- swap SimpleForm, browser_validations: false do
44
- with_input_for @user, :name, :string, required: false
45
- assert_no_select 'input[type=text].required'
46
- assert_no_select 'input[type=text][required]'
47
- assert_no_select 'input[type=text][aria-required]'
48
- end
49
- end
50
-
51
- test 'when not using browser validations, when required option is set to true, input generates required html attribute' do
52
- swap SimpleForm, browser_validations: false do
53
- with_input_for @user, :name, :string, required: true
54
- assert_select 'input[type=text].required'
55
- assert_select 'input[type=text][required]'
56
- assert_select 'input[type=text][aria-required]'
57
- end
58
- end
59
-
60
- test 'when not using browser validations, when required option is true in the wrapper, input does not generate required html attribute' do
61
- swap SimpleForm, browser_validations: false do
62
- swap_wrapper :default, self.custom_wrapper_with_required_input do
63
- with_concat_form_for(@user) do |f|
64
- concat f.input :name
65
- end
66
- assert_select 'input[type=text].required'
67
- assert_no_select 'input[type=text][required]'
68
- assert_no_select 'input[type=text][aria-required]'
69
- end
70
- end
71
- end
72
-
73
- test 'builder input allows disabling required when ActiveModel::Validations is not included' do
74
- with_form_for @user, :name, required: false
75
- assert_no_select 'input.required'
76
- assert_no_select 'input[required]'
77
- assert_select 'input.optional#user_name'
78
- end
79
-
80
- test 'when not the required component the input does not have the required attribute but has the required class' do
81
- swap_wrapper do
82
- with_input_for @user, :name, :string
83
- assert_select 'input[type=text].required'
84
- assert_no_select 'input[type=text][required]'
85
- end
86
- end
87
-
88
- # VALIDATORS :if :unless
89
- test 'builder input does not be required when ActiveModel::Validations is included and if option is present' do
90
- with_form_for @validating_user, :age
91
- assert_no_select 'input.required'
92
- assert_no_select 'input[required]'
93
- assert_select 'input.optional#validating_user_age'
94
- end
95
-
96
- test 'builder input does not be required when ActiveModel::Validations is included and unless option is present' do
97
- with_form_for @validating_user, :amount
98
- assert_no_select 'input.required'
99
- assert_no_select 'input[required]'
100
- assert_select 'input.optional#validating_user_amount'
101
- end
102
-
103
- # VALIDATORS :on
104
- test 'builder input is required when validation is on create and is not persisted' do
105
- @validating_user.new_record!
106
- with_form_for @validating_user, :action
107
- assert_select 'input.required'
108
- assert_select 'input[required]'
109
- assert_select 'input.required[required]#validating_user_action'
110
- end
111
-
112
- test 'builder input does not be required when validation is on create and is persisted' do
113
- with_form_for @validating_user, :action
114
- assert_no_select 'input.required'
115
- assert_no_select 'input[required]'
116
- assert_select 'input.optional#validating_user_action'
117
- end
118
-
119
- test 'builder input is required when validation is on save' do
120
- with_form_for @validating_user, :credit_limit
121
- assert_select 'input.required'
122
- assert_select 'input[required]'
123
- assert_select 'input.required[required]#validating_user_credit_limit'
124
-
125
- @validating_user.new_record!
126
- with_form_for @validating_user, :credit_limit
127
- assert_select 'input.required'
128
- assert_select 'input[required]'
129
- assert_select 'input.required[required]#validating_user_credit_limit'
130
- end
131
-
132
- test 'builder input is required when validation is on update and is persisted' do
133
- with_form_for @validating_user, :phone_number
134
- assert_select 'input.required'
135
- assert_select 'input[required]'
136
- assert_select 'input.required[required]#validating_user_phone_number'
137
- end
138
-
139
- test 'builder input does not be required when validation is on update and is not persisted' do
140
- @validating_user.new_record!
141
- with_form_for @validating_user, :phone_number
142
- assert_no_select 'input.required'
143
- assert_no_select 'input[required]'
144
- assert_select 'input.optional#validating_user_phone_number'
145
- end
146
-
147
- test 'builder input does not generate required html attribute when option is set to false when it is set to true in wrapper' do
148
- swap SimpleForm, browser_validations: true do
149
- swap_wrapper :default, self.custom_wrapper_with_required_input do
150
- with_concat_form_for(@user) do |f|
151
- concat f.input :name, required: false
152
- end
153
- assert_no_select 'input[type=text][required]'
154
- assert_no_select 'input[type=text][aria-required]'
155
- end
156
- end
157
- end
158
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class RichTextAreaInputTest < ActionView::TestCase
6
- test 'input generates a text area for text attributes' do
7
- with_input_for @user, :description, :text
8
- assert_select 'textarea.text#user_description'
9
- end
10
-
11
- test 'input generates a text area for text attributes that accept placeholder' do
12
- with_input_for @user, :description, :text, placeholder: 'Put in some text'
13
- assert_select 'textarea.text[placeholder="Put in some text"]'
14
- end
15
- end
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class StringInputTest < ActionView::TestCase
6
- test 'input maps text field to string attribute' do
7
- with_input_for @user, :name, :string
8
- assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
9
- end
10
-
11
- test 'input maps text field to citext attribute' do
12
- with_input_for @user, :name, :citext
13
- assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
14
- end
15
-
16
- test 'input generates a password field for password attributes' do
17
- with_input_for @user, :password, :password
18
- assert_select "input#user_password.password[type=password][name='user[password]']"
19
- end
20
-
21
- test 'input gets maxlength from column definition for string attributes' do
22
- with_input_for @user, :name, :string
23
- assert_select 'input.string[maxlength="100"]'
24
- end
25
-
26
- test 'input does not get maxlength from column without size definition for string attributes' do
27
- with_input_for @user, :action, :string
28
- assert_no_select 'input.string[maxlength]'
29
- end
30
-
31
- test 'input gets maxlength from column definition for password attributes' do
32
- with_input_for @user, :password, :password
33
- assert_select 'input.password[type=password][maxlength="100"]'
34
- end
35
-
36
- test 'input infers maxlength column definition from validation when present' do
37
- with_input_for @validating_user, :name, :string
38
- assert_select 'input.string[maxlength="25"]'
39
- end
40
-
41
- test 'input infers minlength column definition from validation when present' do
42
- with_input_for @validating_user, :name, :string
43
- assert_select 'input.string[minlength="5"]'
44
- end
45
-
46
- test 'input gets maxlength from validation when :is option present' do
47
- with_input_for @validating_user, :home_picture, :string
48
- assert_select 'input.string[maxlength="12"]'
49
- end
50
-
51
- test 'input gets minlength from validation when :is option present' do
52
- with_input_for @validating_user, :home_picture, :string
53
- assert_select 'input.string[minlength="12"]'
54
- end
55
-
56
- test 'input maxlength is the column limit plus one to make room for decimal point' do
57
- with_input_for @user, :credit_limit, :string
58
-
59
- assert_select 'input.string[maxlength="16"]'
60
- end
61
-
62
- test 'input does not generate placeholder by default' do
63
- with_input_for @user, :name, :string
64
- assert_no_select 'input[placeholder]'
65
- end
66
-
67
- test 'input accepts the placeholder option' do
68
- with_input_for @user, :name, :string, placeholder: 'Put in some text'
69
- assert_select 'input.string[placeholder="Put in some text"]'
70
- end
71
-
72
- test 'input generates a password field for password attributes that accept placeholder' do
73
- with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
74
- assert_select 'input[type=password].password[placeholder="Password Confirmation"]#user_password'
75
- end
76
-
77
- test 'input does not infer pattern from attributes by default' do
78
- with_input_for @other_validating_user, :country, :string
79
- assert_no_select 'input[pattern="\w+"]'
80
- end
81
-
82
- test 'input infers pattern from attributes' do
83
- with_input_for @other_validating_user, :country, :string, pattern: true
84
- assert_select "input:match('pattern', ?)", /\w+/
85
- end
86
-
87
- test 'input infers pattern from attributes using proc' do
88
- with_input_for @other_validating_user, :name, :string, pattern: true
89
- assert_select "input:match('pattern', ?)", /\w+/
90
- end
91
-
92
- test 'input does not infer pattern from attributes if root default is false' do
93
- swap_wrapper do
94
- with_input_for @other_validating_user, :country, :string
95
- assert_no_select 'input[pattern="\w+"]'
96
- end
97
- end
98
-
99
- test 'input uses given pattern from attributes' do
100
- with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
101
- assert_select "input:match('pattern', ?)", /\\d+/
102
- end
103
-
104
- test 'input does not use pattern if model has :without validation option' do
105
- with_input_for @other_validating_user, :description, :string, pattern: true
106
- assert_no_select 'input[pattern="\d+"]'
107
- end
108
-
109
- test 'input uses i18n to translate placeholder text' do
110
- store_translations(:en, simple_form: { placeholders: { user: {
111
- name: 'Name goes here'
112
- } } }) do
113
- with_input_for @user, :name, :string
114
- assert_select 'input.string[placeholder="Name goes here"]'
115
- end
116
- end
117
-
118
- test 'input uses custom i18n scope to translate placeholder text' do
119
- store_translations(:en, my_scope: { placeholders: { user: {
120
- name: 'Name goes here'
121
- } } }) do
122
- swap SimpleForm, i18n_scope: :my_scope do
123
- with_input_for @user, :name, :string
124
- assert_select 'input.string[placeholder="Name goes here"]'
125
- end
126
- end
127
- end
128
-
129
- %i[email url search tel].each do |type|
130
- test "input allows type #{type}" do
131
- with_input_for @user, :name, type
132
- assert_select "input.string.#{type}"
133
- assert_select "input[type=#{type}]"
134
- end
135
-
136
- test "input does not allow type #{type} if HTML5 compatibility is disabled" do
137
- swap_wrapper do
138
- with_input_for @user, :name, type
139
- assert_select "input[type=text]"
140
- assert_no_select "input[type=#{type}]"
141
- end
142
- end
143
- end
144
-
145
- test 'input strips extra spaces from class html attribute with default classes' do
146
- with_input_for @user, :name, :string
147
- assert_select "input[class='string required']"
148
- assert_no_select "input[class='string required ']"
149
- assert_no_select "input[class=' string required']"
150
- end
151
-
152
- test 'input strips extra spaces from class html attribute when giving a custom class' do
153
- with_input_for @user, :name, :string, input_html: { class: "my_input" }
154
- assert_select "input[class='string required my_input']"
155
- assert_no_select "input[class='string required my_input ']"
156
- assert_no_select "input[class=' string required my_input']"
157
- end
158
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class TextInputTest < ActionView::TestCase
6
- test 'input generates a text area for text attributes' do
7
- with_input_for @user, :description, :text
8
- assert_select 'textarea.text#user_description'
9
- end
10
-
11
- test 'input generates a text area for text attributes that accept placeholder' do
12
- with_input_for @user, :description, :text, placeholder: 'Put in some text'
13
- assert_select 'textarea.text[placeholder="Put in some text"]'
14
- end
15
-
16
- test 'input generates a placeholder from the translations' do
17
- store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
18
- with_input_for @user, :name, :text
19
- assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
20
- end
21
- end
22
-
23
- test 'input gets maxlength from column definition for text attributes' do
24
- with_input_for @user, :description, :text
25
- assert_select 'textarea.text[maxlength="200"]'
26
- end
27
-
28
- test 'input infers maxlength column definition from validation when present for text attributes' do
29
- with_input_for @validating_user, :description, :text
30
- assert_select 'textarea.text[maxlength="50"]'
31
- end
32
-
33
- test 'input infers minlength column definition from validation when present for text attributes' do
34
- with_input_for @validating_user, :description, :text
35
- assert_select 'textarea.text[minlength="15"]'
36
- end
37
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- require 'test_helper'
4
-
5
- class TimeZoneInputTest < ActionView::TestCase
6
- test 'input generates a time zone select field' do
7
- with_input_for @user, :time_zone, :time_zone
8
- assert_select 'select#user_time_zone'
9
- assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
10
- assert_no_select 'select option[value=""][disabled=disabled]'
11
- end
12
-
13
- test 'input generates a time zone select field with default' do
14
- with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
15
- assert_select 'select option[value=Brasilia][selected=selected]'
16
- assert_no_select 'select option[value=""]'
17
- end
18
-
19
- test 'input generates a time zone select using options priority' do
20
- with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
21
- assert_select 'select option[value=""][disabled=disabled]'
22
- assert_no_select 'select option[value=""]', /^$/
23
- end
24
-
25
- test 'input does generate select element with required html attribute' do
26
- with_input_for @user, :time_zone, :time_zone
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, :time_zone, :time_zone
33
- assert_select 'select.required'
34
- assert_select 'select[aria-required]'
35
- end
36
- end