simple_form 3.0.4 → 5.0.3

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 (107) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +199 -33
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +453 -128
  5. data/lib/generators/simple_form/install_generator.rb +4 -3
  6. data/lib/generators/simple_form/templates/README +3 -5
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +47 -16
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +418 -23
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
  13. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  14. data/lib/simple_form/action_view_extensions/builder.rb +2 -0
  15. data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
  16. data/lib/simple_form/components/errors.rb +39 -6
  17. data/lib/simple_form/components/hints.rb +3 -2
  18. data/lib/simple_form/components/html5.rb +16 -5
  19. data/lib/simple_form/components/label_input.rb +21 -2
  20. data/lib/simple_form/components/labels.rb +22 -11
  21. data/lib/simple_form/components/maxlength.rb +9 -5
  22. data/lib/simple_form/components/min_max.rb +2 -1
  23. data/lib/simple_form/components/minlength.rb +38 -0
  24. data/lib/simple_form/components/pattern.rb +2 -1
  25. data/lib/simple_form/components/placeholders.rb +4 -3
  26. data/lib/simple_form/components/readonly.rb +2 -1
  27. data/lib/simple_form/components.rb +2 -0
  28. data/lib/simple_form/error_notification.rb +1 -0
  29. data/lib/simple_form/form_builder.rb +220 -89
  30. data/lib/simple_form/helpers/autofocus.rb +1 -0
  31. data/lib/simple_form/helpers/disabled.rb +1 -0
  32. data/lib/simple_form/helpers/readonly.rb +1 -0
  33. data/lib/simple_form/helpers/required.rb +1 -0
  34. data/lib/simple_form/helpers/validators.rb +2 -1
  35. data/lib/simple_form/helpers.rb +6 -5
  36. data/lib/simple_form/i18n_cache.rb +1 -0
  37. data/lib/simple_form/inputs/base.rb +62 -16
  38. data/lib/simple_form/inputs/block_input.rb +2 -1
  39. data/lib/simple_form/inputs/boolean_input.rb +40 -16
  40. data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
  41. data/lib/simple_form/inputs/collection_input.rb +37 -14
  42. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
  43. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  44. data/lib/simple_form/inputs/color_input.rb +14 -0
  45. data/lib/simple_form/inputs/date_time_input.rb +24 -9
  46. data/lib/simple_form/inputs/file_input.rb +5 -2
  47. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  48. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  49. data/lib/simple_form/inputs/numeric_input.rb +6 -4
  50. data/lib/simple_form/inputs/password_input.rb +6 -3
  51. data/lib/simple_form/inputs/priority_input.rb +5 -6
  52. data/lib/simple_form/inputs/range_input.rb +2 -1
  53. data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
  54. data/lib/simple_form/inputs/string_input.rb +7 -4
  55. data/lib/simple_form/inputs/text_input.rb +6 -3
  56. data/lib/simple_form/inputs.rb +3 -0
  57. data/lib/simple_form/map_type.rb +1 -0
  58. data/lib/simple_form/railtie.rb +8 -0
  59. data/lib/simple_form/tags.rb +13 -2
  60. data/lib/simple_form/version.rb +2 -1
  61. data/lib/simple_form/wrappers/builder.rb +7 -6
  62. data/lib/simple_form/wrappers/leaf.rb +29 -0
  63. data/lib/simple_form/wrappers/many.rb +7 -6
  64. data/lib/simple_form/wrappers/root.rb +10 -3
  65. data/lib/simple_form/wrappers/single.rb +7 -4
  66. data/lib/simple_form/wrappers.rb +2 -0
  67. data/lib/simple_form.rb +137 -21
  68. data/test/action_view_extensions/builder_test.rb +64 -45
  69. data/test/action_view_extensions/form_helper_test.rb +36 -16
  70. data/test/components/custom_components_test.rb +62 -0
  71. data/test/components/label_test.rb +70 -41
  72. data/test/form_builder/association_test.rb +85 -37
  73. data/test/form_builder/button_test.rb +11 -10
  74. data/test/form_builder/error_notification_test.rb +2 -1
  75. data/test/form_builder/error_test.rb +146 -33
  76. data/test/form_builder/general_test.rb +183 -81
  77. data/test/form_builder/hint_test.rb +24 -18
  78. data/test/form_builder/input_field_test.rb +105 -75
  79. data/test/form_builder/label_test.rb +68 -13
  80. data/test/form_builder/wrapper_test.rb +197 -22
  81. data/test/generators/simple_form_generator_test.rb +8 -7
  82. data/test/inputs/boolean_input_test.rb +97 -6
  83. data/test/inputs/collection_check_boxes_input_test.rb +117 -25
  84. data/test/inputs/collection_radio_buttons_input_test.rb +176 -54
  85. data/test/inputs/collection_select_input_test.rb +189 -77
  86. data/test/inputs/color_input_test.rb +10 -0
  87. data/test/inputs/datetime_input_test.rb +121 -50
  88. data/test/inputs/disabled_test.rb +29 -15
  89. data/test/inputs/discovery_test.rb +79 -6
  90. data/test/inputs/file_input_test.rb +3 -2
  91. data/test/inputs/general_test.rb +23 -22
  92. data/test/inputs/grouped_collection_select_input_test.rb +54 -17
  93. data/test/inputs/hidden_input_test.rb +5 -4
  94. data/test/inputs/numeric_input_test.rb +48 -44
  95. data/test/inputs/priority_input_test.rb +17 -16
  96. data/test/inputs/readonly_test.rb +20 -19
  97. data/test/inputs/required_test.rb +58 -13
  98. data/test/inputs/rich_text_area_input_test.rb +15 -0
  99. data/test/inputs/string_input_test.rb +58 -36
  100. data/test/inputs/text_input_test.rb +20 -7
  101. data/test/simple_form_test.rb +9 -0
  102. data/test/support/discovery_inputs.rb +40 -2
  103. data/test/support/misc_helpers.rb +113 -5
  104. data/test/support/mock_controller.rb +7 -1
  105. data/test/support/models.rb +162 -39
  106. data/test/test_helper.rb +19 -4
  107. metadata +51 -43
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class GroupedCollectionSelectInputTest < ActionView::TestCase
5
6
  test 'grouped collection accepts array collection form' do
6
7
  with_input_for @user, :tag_ids, :grouped_select,
7
- collection: [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
8
+ collection: [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]],
8
9
  group_method: :last
9
10
 
10
11
  assert_select 'select.grouped_select#user_tag_ids' do
@@ -31,7 +32,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
31
32
 
32
33
  test 'grouped collection accepts proc as collection' do
33
34
  with_input_for @user, :tag_ids, :grouped_select,
34
- collection: Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },
35
+ collection: proc { [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]] },
35
36
  group_method: :last
36
37
 
37
38
  assert_select 'select.grouped_select#user_tag_ids' do
@@ -49,7 +50,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
49
50
 
50
51
  test 'grouped collection accepts hash collection form' do
51
52
  with_input_for @user, :tag_ids, :grouped_select,
52
- collection: { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
53
+ collection: { Authors: %w[Jose Carlos], General: %w[Bob John] },
53
54
  group_method: :last
54
55
 
55
56
  assert_select 'select.grouped_select#user_tag_ids' do
@@ -67,7 +68,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
67
68
 
68
69
  test 'grouped collection accepts group_label_method option' do
69
70
  with_input_for @user, :tag_ids, :grouped_select,
70
- collection: { ['Jose', 'Carlos'] => 'Authors' },
71
+ collection: { %w[Jose Carlos] => 'Authors' },
71
72
  group_method: :first,
72
73
  group_label_method: :last
73
74
 
@@ -79,9 +80,45 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
79
80
  end
80
81
  end
81
82
 
83
+ test 'grouped collection finds default label methods on the group objects' do
84
+ option_list = %w[Jose Carlos]
85
+
86
+ GroupedClass = Struct.new(:to_label, :options)
87
+ group = GroupedClass.new("Authors", option_list)
88
+
89
+ with_input_for @user, :tag_ids, :grouped_select,
90
+ collection: [group],
91
+ group_method: :options
92
+
93
+ assert_select 'select.grouped_select#user_tag_ids' do
94
+ assert_select 'optgroup[label=Authors]' do
95
+ assert_select 'option', 'Jose'
96
+ assert_select 'option', 'Carlos'
97
+ end
98
+ end
99
+ end
100
+
101
+ test 'grouped collections finds the default label method from the first non-empty object' do
102
+ Agent = Struct.new(:id, :name)
103
+ agents = [["First", []], ["Second", [Agent.new(7, 'Bond'), Agent.new(47, 'Hitman')]]]
104
+
105
+ with_input_for @user, :tag_ids, :grouped_select,
106
+ collection: agents,
107
+ group_label_method: :first,
108
+ group_method: :last,
109
+ include_blank: false
110
+
111
+ assert_select 'select.grouped_select#user_tag_ids' do
112
+ assert_select 'optgroup[label=Second]' do
113
+ assert_select 'option[value="7"]', 'Bond'
114
+ assert_select 'option[value="47"]', 'Hitman'
115
+ end
116
+ end
117
+ end
118
+
82
119
  test 'grouped collection accepts label and value methods options' do
83
120
  with_input_for @user, :tag_ids, :grouped_select,
84
- collection: { 'Authors' => ['Jose', 'Carlos'] },
121
+ collection: { Authors: %w[Jose Carlos] },
85
122
  group_method: :last,
86
123
  label_method: :upcase,
87
124
  value_method: :downcase
@@ -94,12 +131,12 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
94
131
  end
95
132
  end
96
133
 
97
- test 'grouped collection should allow overriding label and value methods using a lambda' do
134
+ test 'grouped collection allows overriding label and value methods using a lambda' do
98
135
  with_input_for @user, :tag_ids, :grouped_select,
99
- collection: { 'Authors' => ['Jose', 'Carlos'] },
136
+ collection: { Authors: %w[Jose Carlos] },
100
137
  group_method: :last,
101
- label_method: lambda { |i| i.upcase },
102
- value_method: lambda { |i| i.downcase }
138
+ label_method: ->(i) { i.upcase },
139
+ value_method: ->(i) { i.downcase }
103
140
 
104
141
  assert_select 'select.grouped_select#user_tag_ids' do
105
142
  assert_select 'optgroup[label=Authors]' do
@@ -112,26 +149,26 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
112
149
  test 'grouped collection with associations' do
113
150
  tag_groups = [
114
151
  TagGroup.new(1, "Group of Tags", [Tag.new(1, "Tag 1"), Tag.new(2, "Tag 2")]),
115
- TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4,"Tag 4")])
152
+ TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4, "Tag 4")])
116
153
  ]
117
154
 
118
155
  with_input_for @user, :tag_ids, :grouped_select,
119
156
  collection: tag_groups, group_method: :tags
120
157
 
121
158
  assert_select 'select.grouped_select#user_tag_ids' do
122
- assert_select 'optgroup[label=Group of Tags]' do
123
- assert_select 'option[value=1]', 'Tag 1'
124
- assert_select 'option[value=2]', 'Tag 2'
159
+ assert_select 'optgroup[label="Group of Tags"]' do
160
+ assert_select 'option[value="1"]', 'Tag 1'
161
+ assert_select 'option[value="2"]', 'Tag 2'
125
162
  end
126
163
 
127
- assert_select 'optgroup[label=Other group]' do
128
- assert_select 'option[value=3]', 'Tag 3'
129
- assert_select 'option[value=4]', 'Tag 4'
164
+ assert_select 'optgroup[label="Other group"]' do
165
+ assert_select 'option[value="3"]', 'Tag 3'
166
+ assert_select 'option[value="4"]', 'Tag 4'
130
167
  end
131
168
  end
132
169
  end
133
170
 
134
- test 'grouped collection should accept html options as the last element of collection' do
171
+ test 'grouped collection accepts html options as the last element of collection' do
135
172
  with_input_for @user, :tag_ids, :grouped_select,
136
173
  collection: [['Authors', [['Jose', 'jose', class: 'foo'], ['Carlos', 'carlos', class: 'bar']]]],
137
174
  group_method: :last
@@ -1,26 +1,27 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class HiddenInputTest < ActionView::TestCase
5
- test 'input should generate a hidden field' do
6
+ test 'input generates a hidden field' do
6
7
  with_input_for @user, :name, :hidden
7
8
  assert_no_select 'input[type=text]'
8
9
  assert_select 'input#user_name[type=hidden]'
9
10
  end
10
11
 
11
- test 'hint should not be generated for hidden fields' do
12
+ test 'hint does not be generated for hidden fields' do
12
13
  store_translations(:en, simple_form: { hints: { user: { name: "text" } } }) do
13
14
  with_input_for @user, :name, :hidden
14
15
  assert_no_select 'span.hint'
15
16
  end
16
17
  end
17
18
 
18
- test 'label should not be generated for hidden inputs' do
19
+ test 'label does not be generated for hidden inputs' do
19
20
  with_input_for @user, :name, :hidden
20
21
  assert_no_select 'label'
21
22
  end
22
23
 
23
- test 'required/aria-required/optional options should not be generated for hidden inputs' do
24
+ test 'required/aria-required/optional options does not be generated for hidden inputs' do
24
25
  with_input_for @user, :name, :hidden
25
26
  assert_no_select 'input.required'
26
27
  assert_no_select 'input[required]'
@@ -1,141 +1,145 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class NumericInputTest < ActionView::TestCase
5
- test 'input should generate an integer text field for integer attributes ' do
6
+ test 'input generates an integer text field for integer attributes ' do
6
7
  with_input_for @user, :age, :integer
7
8
  assert_select 'input[type=number].integer#user_age'
8
9
  end
9
10
 
10
- test 'input should generate a float text field for float attributes ' do
11
+ test 'input generates a float text field for float attributes ' do
11
12
  with_input_for @user, :age, :float
12
13
  assert_select 'input[type=number].float#user_age'
13
14
  end
14
15
 
15
- test 'input should generate a decimal text field for decimal attributes ' do
16
+ test 'input generates a decimal text field for decimal attributes ' do
16
17
  with_input_for @user, :age, :decimal
17
18
  assert_select 'input[type=number].decimal#user_age'
18
19
  end
19
20
 
20
- test 'input should not generate min attribute by default' do
21
+ test 'input does not generate min attribute by default' do
21
22
  with_input_for @user, :age, :integer
22
23
  assert_no_select 'input[min]'
23
24
  end
24
25
 
25
- test 'input should not generate max attribute by default' do
26
+ test 'input does not generate max attribute by default' do
26
27
  with_input_for @user, :age, :integer
27
28
  assert_no_select 'input[max]'
28
29
  end
29
30
 
30
- test 'input should infer min value from integer attributes with greater than validation' do
31
+ test 'input infers min value from integer attributes with greater than validation' do
31
32
  with_input_for @other_validating_user, :age, :float
32
33
  assert_no_select 'input[min]'
33
34
 
34
35
  with_input_for @other_validating_user, :age, :integer
35
- assert_select 'input[min=18]'
36
+ assert_select 'input[min="18"]'
36
37
  end
37
38
 
38
- test 'input should infer min value from integer attributes with greater than validation using symbol' do
39
+ test 'input infers min value from integer attributes with greater than validation using symbol' do
39
40
  with_input_for @validating_user, :amount, :float
40
41
  assert_no_select 'input[min]'
41
42
 
42
43
  with_input_for @validating_user, :amount, :integer
43
- assert_select 'input[min=11]'
44
+ assert_select 'input[min="11"]'
44
45
  end
45
46
 
46
- test 'input should infer min value from integer attributes with greater than or equal to validation using symbol' do
47
+ test 'input infers min value from integer attributes with greater than or equal to validation using symbol' do
47
48
  with_input_for @validating_user, :attempts, :float
48
- assert_select 'input[min=1]'
49
+ assert_select 'input[min="1"]'
49
50
 
50
51
  with_input_for @validating_user, :attempts, :integer
51
- assert_select 'input[min=1]'
52
+ assert_select 'input[min="1"]'
52
53
  end
53
54
 
54
- test 'input should infer min value from integer attributes with greater than validation using proc' do
55
+ test 'input infers min value from integer attributes with greater than validation using proc' do
55
56
  with_input_for @other_validating_user, :amount, :float
56
57
  assert_no_select 'input[min]'
57
58
 
58
59
  with_input_for @other_validating_user, :amount, :integer
59
- assert_select 'input[min=20]'
60
+ assert_select 'input[min="20"]'
60
61
  end
61
62
 
62
- test 'input should infer min value from integer attributes with greater than or equal to validation using proc' do
63
+ test 'input infers min value from integer attributes with greater than or equal to validation using proc' do
63
64
  with_input_for @other_validating_user, :attempts, :float
64
- assert_select 'input[min=19]'
65
+ assert_select 'input[min="19"]'
65
66
 
66
67
  with_input_for @other_validating_user, :attempts, :integer
67
- assert_select 'input[min=19]'
68
+ assert_select 'input[min="19"]'
68
69
  end
69
70
 
70
- test 'input should infer max value from attributes with less than validation' do
71
+ test 'input infers max value from attributes with less than validation' do
71
72
  with_input_for @other_validating_user, :age, :float
72
73
  assert_no_select 'input[max]'
73
74
 
74
75
  with_input_for @other_validating_user, :age, :integer
75
- assert_select 'input[max=99]'
76
+ assert_select 'input[max="99"]'
76
77
  end
77
78
 
78
- test 'input should infer max value from attributes with less than validation using symbol' do
79
+ test 'input infers max value from attributes with less than validation using symbol' do
79
80
  with_input_for @validating_user, :amount, :float
80
81
  assert_no_select 'input[max]'
81
82
 
82
83
  with_input_for @validating_user, :amount, :integer
83
- assert_select 'input[max=99]'
84
+ assert_select 'input[max="99"]'
84
85
  end
85
86
 
86
- test 'input should infer max value from attributes with less than or equal to validation using symbol' do
87
+ test 'input infers max value from attributes with less than or equal to validation using symbol' do
87
88
  with_input_for @validating_user, :attempts, :float
88
- assert_select 'input[max=100]'
89
+ assert_select 'input[max="100"]'
89
90
 
90
91
  with_input_for @validating_user, :attempts, :integer
91
- assert_select 'input[max=100]'
92
+ assert_select 'input[max="100"]'
92
93
  end
93
94
 
94
- test 'input should infer max value from attributes with less than validation using proc' do
95
+ test 'input infers max value from attributes with less than validation using proc' do
95
96
  with_input_for @other_validating_user, :amount, :float
96
97
  assert_no_select 'input[max]'
97
98
 
98
99
  with_input_for @other_validating_user, :amount, :integer
99
- assert_select 'input[max=118]'
100
+ assert_select 'input[max="118"]'
100
101
  end
101
102
 
102
- test 'input should infer max value from attributes with less than or equal to validation using proc' do
103
+ test 'input infers max value from attributes with less than or equal to validation using proc' do
103
104
  with_input_for @other_validating_user, :attempts, :float
104
- assert_select 'input[max=119]'
105
+ assert_select 'input[max="119"]'
105
106
 
106
107
  with_input_for @other_validating_user, :attempts, :integer
107
- assert_select 'input[max=119]'
108
+ assert_select 'input[max="119"]'
108
109
  end
109
110
 
110
- test 'input should have step value of any except for integer attribute' do
111
+ test 'input has step value of any except for integer attribute' do
111
112
  with_input_for @validating_user, :age, :float
112
113
  assert_select 'input[step="any"]'
113
114
 
114
115
  with_input_for @validating_user, :age, :integer
115
- assert_select 'input[step=1]'
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"]'
116
120
  end
117
121
 
118
- test 'numeric input should not generate placeholder by default' do
122
+ test 'numeric input does not generate placeholder by default' do
119
123
  with_input_for @user, :age, :integer
120
124
  assert_no_select 'input[placeholder]'
121
125
  end
122
126
 
123
- test 'numeric input should accept the placeholder option' do
127
+ test 'numeric input accepts the placeholder option' do
124
128
  with_input_for @user, :age, :integer, placeholder: 'Put in your age'
125
- assert_select 'input.integer[placeholder=Put in your age]'
129
+ assert_select 'input.integer[placeholder="Put in your age"]'
126
130
  end
127
131
 
128
- test 'numeric input should use i18n to translate placeholder text' do
132
+ test 'numeric input uses i18n to translate placeholder text' do
129
133
  store_translations(:en, simple_form: { placeholders: { user: {
130
134
  age: 'Age goes here'
131
135
  } } }) do
132
136
  with_input_for @user, :age, :integer
133
- assert_select 'input.integer[placeholder=Age goes here]'
137
+ assert_select 'input.integer[placeholder="Age goes here"]'
134
138
  end
135
139
  end
136
140
 
137
141
  # Numeric input but HTML5 disabled
138
- test ' when not using HTML5 input should not generate field with type number and use text instead' do
142
+ test 'when not using HTML5 input does not generate field with type number and use text instead' do
139
143
  swap_wrapper do
140
144
  with_input_for @user, :age, :integer
141
145
  assert_no_select "input[type=number]"
@@ -143,7 +147,7 @@ class NumericInputTest < ActionView::TestCase
143
147
  end
144
148
  end
145
149
 
146
- test 'when not using HTML5 input should not use min or max or step attributes' do
150
+ test 'when not using HTML5 input does not use min or max or step attributes' do
147
151
  swap_wrapper do
148
152
  with_input_for @validating_user, :age, :integer
149
153
  assert_no_select "input[type=number]"
@@ -153,19 +157,19 @@ class NumericInputTest < ActionView::TestCase
153
157
  end
154
158
  end
155
159
 
156
- [:integer, :float, :decimal].each do |type|
157
- test "#{type} input should infer min value from attributes with greater than or equal validation" do
160
+ %i[integer float decimal].each do |type|
161
+ test "#{type} input infers min value from attributes with greater than or equal validation" do
158
162
  with_input_for @validating_user, :age, type
159
- assert_select 'input[min=18]'
163
+ assert_select 'input[min="18"]'
160
164
  end
161
165
 
162
- test "#{type} input should infer the max value from attributes with less than or equal to validation" do
166
+ test "#{type} input infers the max value from attributes with less than or equal to validation" do
163
167
  with_input_for @validating_user, :age, type
164
- assert_select 'input[max=99]'
168
+ assert_select 'input[max="99"]'
165
169
  end
166
170
  end
167
171
 
168
- test 'min_max should not emit max value as bare string' do
172
+ test 'min_max does not emit max value as bare string' do
169
173
  with_input_for @other_validating_user, :age, :integer
170
174
  assert_select 'input[max]'
171
175
  assert_no_select 'div', %r{^99}
@@ -1,49 +1,50 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
4
5
  class PriorityInputTest < ActionView::TestCase
5
- test 'input should generate a country select field' do
6
+ test 'input generates a country select field' do
6
7
  with_input_for @user, :country, :country
7
8
  assert_select 'select#user_country'
8
- assert_select 'select option[value=Brazil]', 'Brazil'
9
- assert_no_select 'select option[value=][disabled=disabled]'
9
+ assert_select 'select option[value=BR]', 'Brazil'
10
+ assert_no_select 'select option[value=""][disabled=disabled]'
10
11
  end
11
12
 
12
- test 'input should generate a country select with SimpleForm default' do
13
+ test 'input generates a country select with SimpleForm default' do
13
14
  swap SimpleForm, country_priority: [ 'Brazil' ] do
14
15
  with_input_for @user, :country, :country
15
- assert_select 'select option[value=][disabled=disabled]'
16
+ assert_select 'select option[value="---------------"][disabled=disabled]'
16
17
  end
17
18
  end
18
19
 
19
- test 'input should generate a time zone select field' do
20
+ test 'input generates a time zone select field' do
20
21
  with_input_for @user, :time_zone, :time_zone
21
22
  assert_select 'select#user_time_zone'
22
23
  assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
23
- assert_no_select 'select option[value=][disabled=disabled]'
24
+ assert_no_select 'select option[value=""][disabled=disabled]'
24
25
  end
25
26
 
26
- test 'input should generate a time zone select field with default' do
27
+ test 'input generates a time zone select field with default' do
27
28
  with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
28
29
  assert_select 'select option[value=Brasilia][selected=selected]'
29
- assert_no_select 'select option[value=]'
30
+ assert_no_select 'select option[value=""]'
30
31
  end
31
32
 
32
- test 'input should generate a time zone select using options priority' do
33
+ test 'input generates a time zone select using options priority' do
33
34
  with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
34
- assert_select 'select option[value=][disabled=disabled]'
35
- assert_no_select 'select option[value=]', /^$/
35
+ assert_select 'select option[value=""][disabled=disabled]'
36
+ assert_no_select 'select option[value=""]', /^$/
36
37
  end
37
38
 
38
- test 'priority input should not generate invalid required html attribute' do
39
+ test 'priority input does generate select element with required html attribute' do
39
40
  with_input_for @user, :country, :country
40
41
  assert_select 'select.required'
41
- assert_no_select 'select[required]'
42
+ assert_select 'select[required]'
42
43
  end
43
44
 
44
- test 'priority input should not generate invalid aria-required html attribute' do
45
+ test 'priority input does generate select element with aria-required html attribute' do
45
46
  with_input_for @user, :country, :country
46
47
  assert_select 'select.required'
47
- assert_no_select 'select[aria-required]'
48
+ assert_select 'select[aria-required]'
48
49
  end
49
50
  end
@@ -1,98 +1,99 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ReadonlyTest < ActionView::TestCase
4
- test 'string input should generate readonly elements when readonly option is true' do
5
+ test 'string input generates readonly elements when readonly option is true' do
5
6
  with_input_for @user, :name, :string, readonly: true
6
7
  assert_select 'input.string.readonly[readonly]'
7
8
  end
8
9
 
9
- test 'text input should generate readonly elements when readonly option is true' do
10
+ test 'text input generates readonly elements when readonly option is true' do
10
11
  with_input_for @user, :description, :text, readonly: true
11
12
  assert_select 'textarea.text.readonly[readonly]'
12
13
  end
13
14
 
14
- test 'numeric input should generate readonly elements when readonly option is true' do
15
+ test 'numeric input generates readonly elements when readonly option is true' do
15
16
  with_input_for @user, :age, :integer, readonly: true
16
17
  assert_select 'input.integer.readonly[readonly]'
17
18
  end
18
19
 
19
- test 'date input should generate readonly elements when readonly option is true' do
20
+ test 'date input generates readonly elements when readonly option is true' do
20
21
  with_input_for @user, :born_at, :date, readonly: true
21
22
  assert_select 'select.date.readonly[readonly]'
22
23
  end
23
24
 
24
- test 'datetime input should generate readonly elements when readonly option is true' do
25
+ test 'datetime input generates readonly elements when readonly option is true' do
25
26
  with_input_for @user, :created_at, :datetime, readonly: true
26
27
  assert_select 'select.datetime.readonly[readonly]'
27
28
  end
28
29
 
29
- test 'string input should generate readonly elements when readonly option is false' do
30
+ test 'string input generates readonly elements when readonly option is false' do
30
31
  with_input_for @user, :name, :string, readonly: false
31
32
  assert_no_select 'input.string.readonly[readonly]'
32
33
  end
33
34
 
34
- test 'text input should generate readonly elements when readonly option is false' do
35
+ test 'text input generates readonly elements when readonly option is false' do
35
36
  with_input_for @user, :description, :text, readonly: false
36
37
  assert_no_select 'textarea.text.readonly[readonly]'
37
38
  end
38
39
 
39
- test 'numeric input should generate readonly elements when readonly option is false' do
40
+ test 'numeric input generates readonly elements when readonly option is false' do
40
41
  with_input_for @user, :age, :integer, readonly: false
41
42
  assert_no_select 'input.integer.readonly[readonly]'
42
43
  end
43
44
 
44
- test 'date input should generate readonly elements when readonly option is false' do
45
+ test 'date input generates readonly elements when readonly option is false' do
45
46
  with_input_for @user, :born_at, :date, readonly: false
46
47
  assert_no_select 'select.date.readonly[readonly]'
47
48
  end
48
49
 
49
- test 'datetime input should generate readonly elements when readonly option is false' do
50
+ test 'datetime input generates readonly elements when readonly option is false' do
50
51
  with_input_for @user, :created_at, :datetime, readonly: false
51
52
  assert_no_select 'select.datetime.readonly[readonly]'
52
53
  end
53
54
 
54
- test 'string input should generate readonly elements when readonly option is not present' do
55
+ test 'string input generates readonly elements when readonly option is not present' do
55
56
  with_input_for @user, :name, :string
56
57
  assert_no_select 'input.string.readonly[readonly]'
57
58
  end
58
59
 
59
- test 'text input should generate readonly elements when readonly option is not present' do
60
+ test 'text input generates readonly elements when readonly option is not present' do
60
61
  with_input_for @user, :description, :text
61
62
  assert_no_select 'textarea.text.readonly[readonly]'
62
63
  end
63
64
 
64
- test 'numeric input should generate readonly elements when readonly option is not present' do
65
+ test 'numeric input generates readonly elements when readonly option is not present' do
65
66
  with_input_for @user, :age, :integer
66
67
  assert_no_select 'input.integer.readonly[readonly]'
67
68
  end
68
69
 
69
- test 'date input should generate readonly elements when readonly option is not present' do
70
+ test 'date input generates readonly elements when readonly option is not present' do
70
71
  with_input_for @user, :born_at, :date
71
72
  assert_no_select 'select.date.readonly[readonly]'
72
73
  end
73
74
 
74
- test 'datetime input should generate readonly elements when readonly option is not present' do
75
+ test 'datetime input generates readonly elements when readonly option is not present' do
75
76
  with_input_for @user, :created_at, :datetime
76
77
  assert_no_select 'select.datetime.readonly[readonly]'
77
78
  end
78
79
 
79
- test 'input should generate readonly attribute when the field is readonly and the object is persisted' do
80
+ test 'input generates readonly attribute when the field is readonly and the object is persisted' do
80
81
  with_input_for @user, :credit_card, :string, readonly: :lookup
81
82
  assert_select 'input.string.readonly[readonly]'
82
83
  end
83
84
 
84
- test 'input should not generate readonly attribute when the field is readonly and the object is not persisted' do
85
+ test 'input does not generate readonly attribute when the field is readonly and the object is not persisted' do
85
86
  @user.new_record!
86
87
  with_input_for @user, :credit_card, :string, readonly: :lookup
87
88
  assert_no_select 'input.string.readonly[readonly]'
88
89
  end
89
90
 
90
- test 'input should not generate readonly attribute when the field is not readonly and the object is persisted' do
91
+ test 'input does not generate readonly attribute when the field is not readonly and the object is persisted' do
91
92
  with_input_for @user, :name, :string
92
93
  assert_no_select 'input.string.readonly[readonly]'
93
94
  end
94
95
 
95
- test 'input should not generate readonly attribute when the component is not used' do
96
+ test 'input does not generate readonly attribute when the component is not used' do
96
97
  swap_wrapper do
97
98
  with_input_for @user, :credit_card, :string
98
99
  assert_no_select 'input.string.readonly[readonly]'