simple_form 5.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/MIT-LICENSE +1 -1
- data/README.md +64 -16
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +126 -194
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/form_builder.rb +2 -6
- data/lib/simple_form/inputs/boolean_input.rb +6 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -1
- data/lib/simple_form/inputs/priority_input.rb +16 -2
- data/lib/simple_form/railtie.rb +4 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/leaf.rb +1 -1
- data/lib/simple_form.rb +9 -5
- metadata +11 -83
- data/test/action_view_extensions/builder_test.rb +0 -634
- data/test/action_view_extensions/form_helper_test.rb +0 -172
- data/test/components/custom_components_test.rb +0 -62
- data/test/components/label_test.rb +0 -352
- data/test/form_builder/association_test.rb +0 -252
- data/test/form_builder/button_test.rb +0 -48
- data/test/form_builder/error_notification_test.rb +0 -80
- data/test/form_builder/error_test.rb +0 -281
- data/test/form_builder/general_test.rb +0 -539
- data/test/form_builder/hint_test.rb +0 -150
- data/test/form_builder/input_field_test.rb +0 -195
- data/test/form_builder/label_test.rb +0 -136
- data/test/form_builder/wrapper_test.rb +0 -378
- data/test/generators/simple_form_generator_test.rb +0 -43
- data/test/inputs/boolean_input_test.rb +0 -243
- data/test/inputs/collection_check_boxes_input_test.rb +0 -323
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
- data/test/inputs/collection_select_input_test.rb +0 -380
- data/test/inputs/color_input_test.rb +0 -10
- data/test/inputs/datetime_input_test.rb +0 -176
- data/test/inputs/disabled_test.rb +0 -92
- data/test/inputs/discovery_test.rb +0 -142
- data/test/inputs/file_input_test.rb +0 -17
- data/test/inputs/general_test.rb +0 -133
- data/test/inputs/grouped_collection_select_input_test.rb +0 -183
- data/test/inputs/hidden_input_test.rb +0 -32
- data/test/inputs/numeric_input_test.rb +0 -177
- data/test/inputs/priority_input_test.rb +0 -50
- data/test/inputs/readonly_test.rb +0 -102
- data/test/inputs/required_test.rb +0 -158
- data/test/inputs/rich_text_area_input_test.rb +0 -15
- data/test/inputs/string_input_test.rb +0 -158
- data/test/inputs/text_input_test.rb +0 -37
- data/test/simple_form_test.rb +0 -18
- data/test/support/discovery_inputs.rb +0 -65
- data/test/support/misc_helpers.rb +0 -274
- data/test/support/mock_controller.rb +0 -30
- data/test/support/models.rb +0 -357
- data/test/test_helper.rb +0 -95
@@ -1,142 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class DiscoveryTest < ActionView::TestCase
|
5
|
-
# Setup new inputs and remove them after the test.
|
6
|
-
def discovery(value = false)
|
7
|
-
swap SimpleForm, cache_discovery: value do
|
8
|
-
begin
|
9
|
-
load "support/discovery_inputs.rb"
|
10
|
-
yield
|
11
|
-
ensure
|
12
|
-
SimpleForm::FormBuilder.discovery_cache.clear
|
13
|
-
Object.send :remove_const, :StringInput
|
14
|
-
Object.send :remove_const, :NumericInput
|
15
|
-
Object.send :remove_const, :CustomizedInput
|
16
|
-
Object.send :remove_const, :DeprecatedInput
|
17
|
-
Object.send :remove_const, :CollectionSelectInput
|
18
|
-
Object.send :remove_const, :FileInput
|
19
|
-
CustomInputs.send :remove_const, :CustomizedInput
|
20
|
-
CustomInputs.send :remove_const, :PasswordInput
|
21
|
-
CustomInputs.send :remove_const, :NumericInput
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'builder does not discover new inputs if cached' do
|
27
|
-
with_form_for @user, :name
|
28
|
-
assert_select 'form input#user_name.string'
|
29
|
-
|
30
|
-
discovery(true) do
|
31
|
-
with_form_for @user, :name
|
32
|
-
assert_no_select 'form section input#user_name.string'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'builder discovers new inputs' do
|
37
|
-
discovery do
|
38
|
-
with_form_for @user, :name, as: :customized
|
39
|
-
assert_select 'form section input#user_name.string'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'builder does not discover new inputs if discovery is off' do
|
44
|
-
with_form_for @user, :name
|
45
|
-
assert_select 'form input#user_name.string'
|
46
|
-
|
47
|
-
swap SimpleForm, inputs_discovery: false do
|
48
|
-
discovery do
|
49
|
-
with_form_for @user, :name
|
50
|
-
assert_no_select 'form section input#user_name.string'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'builder discovers new inputs from mappings if not cached' do
|
56
|
-
discovery do
|
57
|
-
with_form_for @user, :name
|
58
|
-
assert_select 'form section input#user_name.string'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test 'builder discovers new inputs from internal fallbacks if not cached' do
|
63
|
-
discovery do
|
64
|
-
with_form_for @user, :age
|
65
|
-
assert_select 'form section input#user_age.numeric.integer'
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'builder discovers new maped inputs from configured namespaces if not cached' do
|
70
|
-
discovery do
|
71
|
-
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
72
|
-
with_form_for @user, :password
|
73
|
-
assert_select 'form input#user_password.password-custom-input'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'builder discovers new maped inputs from configured namespaces before the ones from top level namespace' do
|
79
|
-
discovery do
|
80
|
-
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
81
|
-
with_form_for @user, :age
|
82
|
-
assert_select 'form input#user_age.numeric-custom-input'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
test 'builder discovers new custom inputs from configured namespace before the ones from top level namespace' do
|
88
|
-
discovery do
|
89
|
-
swap SimpleForm, custom_inputs_namespaces: ['CustomInputs'] do
|
90
|
-
with_form_for @user, :name, as: 'customized'
|
91
|
-
assert_select 'form input#user_name.customized-namespace-custom-input'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'raises error when configured namespace does not exists' do
|
97
|
-
discovery do
|
98
|
-
swap SimpleForm, custom_inputs_namespaces: ['InvalidNamespace'] do
|
99
|
-
assert_raise NameError do
|
100
|
-
with_form_for @user, :age
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
test 'new inputs can override the input_html_options' do
|
107
|
-
discovery do
|
108
|
-
with_form_for @user, :active, as: :select
|
109
|
-
assert_select 'form select#user_active.select.chosen'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
test 'does not duplicate the html classes giving a extra class' do
|
114
|
-
discovery do
|
115
|
-
swap SimpleForm, input_class: 'custom-default-input-class' do
|
116
|
-
with_form_for @user, :active, as: :select
|
117
|
-
assert_select 'form select#user_active.select' do
|
118
|
-
# Make sure class list contains 'chosen' only once.
|
119
|
-
assert_select ":match('class', ?)", /^(?!.*\bchosen\b.*\bchosen\b).*\bchosen\b.*$/
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
test 'new inputs can override the default input_html_classes' do
|
126
|
-
discovery do
|
127
|
-
with_form_for @user, :avatar, as: :file
|
128
|
-
assert_no_select 'form input[type=file]#user_avatar.file.file-upload'
|
129
|
-
assert_select 'form input[type=file]#user_avatar.file-upload'
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
test 'inputs method without wrapper_options are deprecated' do
|
134
|
-
discovery do
|
135
|
-
assert_deprecated do
|
136
|
-
with_form_for @user, :name, as: :deprecated
|
137
|
-
end
|
138
|
-
|
139
|
-
assert_select 'form section input#user_name.string'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class FileInputTest < ActionView::TestCase
|
6
|
-
test 'input generates a file field' do
|
7
|
-
with_input_for @user, :name, :file
|
8
|
-
assert_select 'input#user_name[type=file]'
|
9
|
-
end
|
10
|
-
|
11
|
-
test "input generates a file field that doesn't accept placeholder" do
|
12
|
-
store_translations(:en, simple_form: { placeholders: { user: { name: "text" } } }) do
|
13
|
-
with_input_for @user, :name, :file
|
14
|
-
assert_no_select 'input[placeholder]'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/test/inputs/general_test.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class InputTest < ActionView::TestCase
|
6
|
-
test 'input generates css class based on default input type' do
|
7
|
-
with_input_for @user, :name, :string
|
8
|
-
assert_select 'input.string'
|
9
|
-
with_input_for @user, :description, :text
|
10
|
-
assert_select 'textarea.text'
|
11
|
-
with_input_for @user, :age, :integer
|
12
|
-
assert_select 'input.integer'
|
13
|
-
with_input_for @user, :born_at, :date
|
14
|
-
assert_select 'select.date'
|
15
|
-
with_input_for @user, :created_at, :datetime
|
16
|
-
assert_select 'select.datetime'
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'string input generates autofocus attribute when autofocus option is true' do
|
20
|
-
with_input_for @user, :name, :string, autofocus: true
|
21
|
-
assert_select 'input.string[autofocus]'
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'input accepts input_class configuration' do
|
25
|
-
swap SimpleForm, input_class: :xlarge do
|
26
|
-
with_input_for @user, :name, :string
|
27
|
-
assert_select 'input.xlarge'
|
28
|
-
assert_no_select 'div.xlarge'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'input does not add input_class when configured to not generate additional classes for input' do
|
33
|
-
swap SimpleForm, input_class: 'xlarge', generate_additional_classes_for: [:wrapper] do
|
34
|
-
with_input_for @user, :name, :string
|
35
|
-
assert_select 'input'
|
36
|
-
assert_no_select '.xlarge'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'text input generates autofocus attribute when autofocus option is true' do
|
41
|
-
with_input_for @user, :description, :text, autofocus: true
|
42
|
-
assert_select 'textarea.text[autofocus]'
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'numeric input generates autofocus attribute when autofocus option is true' do
|
46
|
-
with_input_for @user, :age, :integer, autofocus: true
|
47
|
-
assert_select 'input.integer[autofocus]'
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'date input generates autofocus attribute when autofocus option is true' do
|
51
|
-
with_input_for @user, :born_at, :date, autofocus: true
|
52
|
-
assert_select 'select.date[autofocus]'
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'datetime input generates autofocus attribute when autofocus option is true' do
|
56
|
-
with_input_for @user, :created_at, :datetime, autofocus: true
|
57
|
-
assert_select 'select.datetime[autofocus]'
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'string input generates autofocus attribute when autofocus option is false' do
|
61
|
-
with_input_for @user, :name, :string, autofocus: false
|
62
|
-
assert_no_select 'input.string[autofocus]'
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'text input generates autofocus attribute when autofocus option is false' do
|
66
|
-
with_input_for @user, :description, :text, autofocus: false
|
67
|
-
assert_no_select 'textarea.text[autofocus]'
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'numeric input generates autofocus attribute when autofocus option is false' do
|
71
|
-
with_input_for @user, :age, :integer, autofocus: false
|
72
|
-
assert_no_select 'input.integer[autofocus]'
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'date input generates autofocus attribute when autofocus option is false' do
|
76
|
-
with_input_for @user, :born_at, :date, autofocus: false
|
77
|
-
assert_no_select 'select.date[autofocus]'
|
78
|
-
end
|
79
|
-
|
80
|
-
test 'datetime input generates autofocus attribute when autofocus option is false' do
|
81
|
-
with_input_for @user, :created_at, :datetime, autofocus: false
|
82
|
-
assert_no_select 'select.datetime[autofocus]'
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'string input generates autofocus attribute when autofocus option is not present' do
|
86
|
-
with_input_for @user, :name, :string
|
87
|
-
assert_no_select 'input.string[autofocus]'
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'text input generates autofocus attribute when autofocus option is not present' do
|
91
|
-
with_input_for @user, :description, :text
|
92
|
-
assert_no_select 'textarea.text[autofocus]'
|
93
|
-
end
|
94
|
-
|
95
|
-
test 'numeric input generates autofocus attribute when autofocus option is not present' do
|
96
|
-
with_input_for @user, :age, :integer
|
97
|
-
assert_no_select 'input.integer[autofocus]'
|
98
|
-
end
|
99
|
-
|
100
|
-
test 'date input generates autofocus attribute when autofocus option is not present' do
|
101
|
-
with_input_for @user, :born_at, :date
|
102
|
-
assert_no_select 'select.date[autofocus]'
|
103
|
-
end
|
104
|
-
|
105
|
-
test 'datetime input generates autofocus attribute when autofocus option is not present' do
|
106
|
-
with_input_for @user, :created_at, :datetime
|
107
|
-
assert_no_select 'select.datetime[autofocus]'
|
108
|
-
end
|
109
|
-
|
110
|
-
# With no object
|
111
|
-
test 'input is generated properly when object is not present' do
|
112
|
-
with_input_for :project, :name, :string
|
113
|
-
assert_select 'input.string.required#project_name'
|
114
|
-
end
|
115
|
-
|
116
|
-
test 'input as radio is generated properly when object is not present ' do
|
117
|
-
with_input_for :project, :name, :radio_buttons
|
118
|
-
assert_select 'input.radio_buttons#project_name_true'
|
119
|
-
assert_select 'input.radio_buttons#project_name_false'
|
120
|
-
end
|
121
|
-
|
122
|
-
test 'input as select with collection is generated properly when object is not present' do
|
123
|
-
with_input_for :project, :name, :select, collection: %w[Jose Carlos]
|
124
|
-
assert_select 'select.select#project_name'
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'input does not generate empty css class' do
|
128
|
-
swap SimpleForm, generate_additional_classes_for: %i[wrapper label] do
|
129
|
-
with_input_for :project, :name, :string
|
130
|
-
assert_no_select 'input#project_name[class]'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class GroupedCollectionSelectInputTest < ActionView::TestCase
|
6
|
-
test 'grouped collection accepts array collection form' do
|
7
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
8
|
-
collection: [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]],
|
9
|
-
group_method: :last
|
10
|
-
|
11
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
12
|
-
assert_select 'optgroup[label=Authors]' do
|
13
|
-
assert_select 'option', 'Jose'
|
14
|
-
assert_select 'option', 'Carlos'
|
15
|
-
end
|
16
|
-
|
17
|
-
assert_select 'optgroup[label=General]' do
|
18
|
-
assert_select 'option', 'Bob'
|
19
|
-
assert_select 'option', 'John'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'grouped collection accepts empty array collection form' do
|
25
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
26
|
-
collection: [],
|
27
|
-
group_method: :last
|
28
|
-
|
29
|
-
assert_select 'select.grouped_select#user_tag_ids'
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
test 'grouped collection accepts proc as collection' do
|
34
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
35
|
-
collection: proc { [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]] },
|
36
|
-
group_method: :last
|
37
|
-
|
38
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
39
|
-
assert_select 'optgroup[label=Authors]' do
|
40
|
-
assert_select 'option', 'Jose'
|
41
|
-
assert_select 'option', 'Carlos'
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_select 'optgroup[label=General]' do
|
45
|
-
assert_select 'option', 'Bob'
|
46
|
-
assert_select 'option', 'John'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'grouped collection accepts hash collection form' do
|
52
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
53
|
-
collection: { Authors: %w[Jose Carlos], General: %w[Bob John] },
|
54
|
-
group_method: :last
|
55
|
-
|
56
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
57
|
-
assert_select 'optgroup[label=Authors]' do
|
58
|
-
assert_select 'option', 'Jose'
|
59
|
-
assert_select 'option', 'Carlos'
|
60
|
-
end
|
61
|
-
|
62
|
-
assert_select 'optgroup[label=General]' do
|
63
|
-
assert_select 'option', 'Bob'
|
64
|
-
assert_select 'option', 'John'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'grouped collection accepts group_label_method option' do
|
70
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
71
|
-
collection: { %w[Jose Carlos] => 'Authors' },
|
72
|
-
group_method: :first,
|
73
|
-
group_label_method: :last
|
74
|
-
|
75
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
76
|
-
assert_select 'optgroup[label=Authors]' do
|
77
|
-
assert_select 'option', 'Jose'
|
78
|
-
assert_select 'option', 'Carlos'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
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
|
-
|
119
|
-
test 'grouped collection accepts label and value methods options' do
|
120
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
121
|
-
collection: { Authors: %w[Jose Carlos] },
|
122
|
-
group_method: :last,
|
123
|
-
label_method: :upcase,
|
124
|
-
value_method: :downcase
|
125
|
-
|
126
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
127
|
-
assert_select 'optgroup[label=Authors]' do
|
128
|
-
assert_select 'option[value=jose]', 'JOSE'
|
129
|
-
assert_select 'option[value=carlos]', 'CARLOS'
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
test 'grouped collection allows overriding label and value methods using a lambda' do
|
135
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
136
|
-
collection: { Authors: %w[Jose Carlos] },
|
137
|
-
group_method: :last,
|
138
|
-
label_method: ->(i) { i.upcase },
|
139
|
-
value_method: ->(i) { i.downcase }
|
140
|
-
|
141
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
142
|
-
assert_select 'optgroup[label=Authors]' do
|
143
|
-
assert_select 'option[value=jose]', 'JOSE'
|
144
|
-
assert_select 'option[value=carlos]', 'CARLOS'
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'grouped collection with associations' do
|
150
|
-
tag_groups = [
|
151
|
-
TagGroup.new(1, "Group of Tags", [Tag.new(1, "Tag 1"), Tag.new(2, "Tag 2")]),
|
152
|
-
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4, "Tag 4")])
|
153
|
-
]
|
154
|
-
|
155
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
156
|
-
collection: tag_groups, group_method: :tags
|
157
|
-
|
158
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
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'
|
162
|
-
end
|
163
|
-
|
164
|
-
assert_select 'optgroup[label="Other group"]' do
|
165
|
-
assert_select 'option[value="3"]', 'Tag 3'
|
166
|
-
assert_select 'option[value="4"]', 'Tag 4'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
test 'grouped collection accepts html options as the last element of collection' do
|
172
|
-
with_input_for @user, :tag_ids, :grouped_select,
|
173
|
-
collection: [['Authors', [['Jose', 'jose', class: 'foo'], ['Carlos', 'carlos', class: 'bar']]]],
|
174
|
-
group_method: :last
|
175
|
-
|
176
|
-
assert_select 'select.grouped_select#user_tag_ids' do
|
177
|
-
assert_select 'optgroup[label=Authors]' do
|
178
|
-
assert_select 'option.foo', 'Jose'
|
179
|
-
assert_select 'option.bar', 'Carlos'
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class HiddenInputTest < ActionView::TestCase
|
6
|
-
test 'input generates a hidden field' do
|
7
|
-
with_input_for @user, :name, :hidden
|
8
|
-
assert_no_select 'input[type=text]'
|
9
|
-
assert_select 'input#user_name[type=hidden]'
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'hint does not be generated for hidden fields' do
|
13
|
-
store_translations(:en, simple_form: { hints: { user: { name: "text" } } }) do
|
14
|
-
with_input_for @user, :name, :hidden
|
15
|
-
assert_no_select 'span.hint'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'label does not be generated for hidden inputs' do
|
20
|
-
with_input_for @user, :name, :hidden
|
21
|
-
assert_no_select 'label'
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'required/aria-required/optional options does not be generated for hidden inputs' do
|
25
|
-
with_input_for @user, :name, :hidden
|
26
|
-
assert_no_select 'input.required'
|
27
|
-
assert_no_select 'input[required]'
|
28
|
-
assert_no_select 'input[aria-required]'
|
29
|
-
assert_no_select 'input.optional'
|
30
|
-
assert_select 'input.hidden#user_name'
|
31
|
-
end
|
32
|
-
end
|
@@ -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
|