simple_form 1.5.2 → 2.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/CHANGELOG.md +224 -0
- data/MIT-LICENSE +1 -1
- data/README.md +817 -0
- data/lib/generators/simple_form/install_generator.rb +15 -1
- data/lib/generators/simple_form/templates/README +12 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +173 -0
- data/lib/simple_form.rb +109 -43
- data/lib/simple_form/action_view_extensions/builder.rb +158 -53
- data/lib/simple_form/action_view_extensions/form_helper.rb +29 -22
- data/lib/simple_form/components.rb +11 -1
- data/lib/simple_form/components/errors.rb +6 -24
- data/lib/simple_form/components/hints.rb +7 -21
- data/lib/simple_form/components/html5.rb +26 -0
- data/lib/simple_form/components/labels.rb +15 -13
- data/lib/simple_form/components/maxlength.rb +41 -0
- data/lib/simple_form/components/min_max.rb +49 -0
- data/lib/simple_form/components/pattern.rb +34 -0
- data/lib/simple_form/components/placeholders.rb +5 -17
- data/lib/simple_form/components/readonly.rb +22 -0
- data/lib/simple_form/core_ext/hash.rb +16 -0
- data/lib/simple_form/error_notification.rb +8 -1
- data/lib/simple_form/form_builder.rb +86 -22
- data/lib/simple_form/helpers.rb +7 -4
- data/lib/simple_form/helpers/autofocus.rb +11 -0
- data/lib/simple_form/helpers/disabled.rb +15 -0
- data/lib/simple_form/helpers/readonly.rb +15 -0
- data/lib/simple_form/helpers/required.rb +7 -10
- data/lib/simple_form/helpers/validators.rb +4 -4
- data/lib/simple_form/inputs.rb +17 -13
- data/lib/simple_form/inputs/base.rb +50 -81
- data/lib/simple_form/inputs/boolean_input.rb +43 -4
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
- data/lib/simple_form/inputs/collection_input.rb +27 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +69 -0
- data/lib/simple_form/inputs/collection_select_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +2 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
- data/lib/simple_form/inputs/hidden_input.rb +3 -6
- data/lib/simple_form/inputs/numeric_input.rb +3 -51
- data/lib/simple_form/inputs/password_input.rb +1 -2
- data/lib/simple_form/inputs/priority_input.rb +2 -2
- data/lib/simple_form/inputs/range_input.rb +1 -3
- data/lib/simple_form/inputs/string_input.rb +6 -8
- data/lib/simple_form/inputs/text_input.rb +1 -2
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers.rb +8 -0
- data/lib/simple_form/wrappers/builder.rb +75 -0
- data/lib/simple_form/wrappers/many.rb +68 -0
- data/lib/simple_form/wrappers/root.rb +34 -0
- data/lib/simple_form/wrappers/single.rb +18 -0
- data/test/action_view_extensions/builder_test.rb +195 -100
- data/test/action_view_extensions/form_helper_test.rb +24 -2
- data/test/components/label_test.rb +20 -5
- data/test/form_builder/association_test.rb +167 -0
- data/test/form_builder/button_test.rb +28 -0
- data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +2 -1
- data/test/form_builder/error_test.rb +101 -0
- data/test/form_builder/general_test.rb +348 -0
- data/test/form_builder/hint_test.rb +115 -0
- data/test/form_builder/input_field_test.rb +51 -0
- data/test/form_builder/label_test.rb +51 -0
- data/test/form_builder/wrapper_test.rb +140 -0
- data/test/generators/simple_form_generator_test.rb +32 -0
- data/test/inputs/boolean_input_test.rb +91 -0
- data/test/inputs/collection_check_boxes_input_test.rb +224 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
- data/test/inputs/collection_select_input_test.rb +241 -0
- data/test/inputs/datetime_input_test.rb +85 -0
- data/test/inputs/disabled_test.rb +38 -0
- data/test/inputs/discovery_test.rb +61 -0
- data/test/inputs/file_input_test.rb +16 -0
- data/test/inputs/general_test.rb +69 -0
- data/test/inputs/grouped_collection_select_input_test.rb +109 -0
- data/test/inputs/hidden_input_test.rb +30 -0
- data/test/inputs/numeric_input_test.rb +167 -0
- data/test/inputs/priority_input_test.rb +43 -0
- data/test/inputs/readonly_test.rb +61 -0
- data/test/inputs/required_test.rb +113 -0
- data/test/inputs/string_input_test.rb +140 -0
- data/test/inputs/text_input_test.rb +24 -0
- data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
- data/test/support/misc_helpers.rb +48 -6
- data/test/support/mock_controller.rb +2 -2
- data/test/support/models.rb +20 -5
- data/test/test_helper.rb +5 -8
- metadata +123 -98
- data/.gitignore +0 -3
- data/.gitmodules +0 -3
- data/.travis.yml +0 -15
- data/CHANGELOG.rdoc +0 -159
- data/Gemfile +0 -9
- data/README.rdoc +0 -466
- data/Rakefile +0 -27
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
- data/lib/simple_form/components/wrapper.rb +0 -38
- data/lib/simple_form/helpers/has_errors.rb +0 -15
- data/lib/simple_form/helpers/maxlength.rb +0 -24
- data/lib/simple_form/helpers/pattern.rb +0 -28
- data/simple_form.gemspec +0 -25
- data/test/components/error_test.rb +0 -56
- data/test/components/hint_test.rb +0 -74
- data/test/components/wrapper_test.rb +0 -63
- data/test/custom_components.rb +0 -7
- data/test/form_builder_test.rb +0 -930
- data/test/inputs_test.rb +0 -995
@@ -0,0 +1,241 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CollectionSelectInputTest < ActionView::TestCase
|
5
|
+
setup do
|
6
|
+
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'input should generate a boolean select with options by default for select types' do
|
10
|
+
with_input_for @user, :active, :select
|
11
|
+
assert_select 'select.select#user_active'
|
12
|
+
assert_select 'select option[value=true]', 'Yes'
|
13
|
+
assert_select 'select option[value=false]', 'No'
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'input as select should use i18n to translate select boolean options' do
|
17
|
+
store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
|
18
|
+
with_input_for @user, :active, :select
|
19
|
+
assert_select 'select option[value=true]', 'Sim'
|
20
|
+
assert_select 'select option[value=false]', 'Não'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'input should allow overriding collection for select types' do
|
25
|
+
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
26
|
+
assert_select 'select.select#user_name'
|
27
|
+
assert_select 'select option', 'Jose'
|
28
|
+
assert_select 'select option', 'Carlos'
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'input should do automatic collection translation for select types using defaults key' do
|
32
|
+
store_translations(:en, :simple_form => { :options => { :defaults => {
|
33
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
34
|
+
} } } ) do
|
35
|
+
with_input_for @user, :gender, :select, :collection => [:male, :female]
|
36
|
+
assert_select 'select.select#user_gender'
|
37
|
+
assert_select 'select option', 'Male'
|
38
|
+
assert_select 'select option', 'Female'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'input should do automatic collection translation for select types using specific object key' do
|
43
|
+
store_translations(:en, :simple_form => { :options => { :user => {
|
44
|
+
:gender => { :male => 'Male', :female => 'Female'}
|
45
|
+
} } } ) do
|
46
|
+
with_input_for @user, :gender, :select, :collection => [:male, :female]
|
47
|
+
assert_select 'select.select#user_gender'
|
48
|
+
assert_select 'select option', 'Male'
|
49
|
+
assert_select 'select option', 'Female'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'input should mark the selected value by default' do
|
54
|
+
@user.name = "Carlos"
|
55
|
+
with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
|
56
|
+
assert_select 'select option[selected=selected]', 'Carlos'
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'input should mark the selected value also when using integers' do
|
60
|
+
@user.age = 18
|
61
|
+
with_input_for @user, :age, :select, :collection => 18..60
|
62
|
+
assert_select 'select option[selected=selected]', '18'
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'input should mark the selected value when using booleans and select' do
|
66
|
+
@user.active = false
|
67
|
+
with_input_for @user, :active, :select
|
68
|
+
assert_no_select 'select option[selected][value=true]', 'Yes'
|
69
|
+
assert_select 'select option[selected][value=false]', 'No'
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'input should set the correct value when using a collection that includes floats' do
|
73
|
+
with_input_for @user, :age, :select, :collection => [2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
|
74
|
+
assert_select 'select option[value="2.0"]'
|
75
|
+
assert_select 'select option[value="2.5"]'
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'input should set the correct values when using a collection that uses mixed values' do
|
79
|
+
with_input_for @user, :age, :select, :collection => ["Hello Kitty", 2, 4.5, :johnny, nil, true, false]
|
80
|
+
assert_select 'select option[value="Hello Kitty"]'
|
81
|
+
assert_select 'select option[value="2"]'
|
82
|
+
assert_select 'select option[value="4.5"]'
|
83
|
+
assert_select 'select option[value="johnny"]'
|
84
|
+
assert_select 'select option[value=""]'
|
85
|
+
assert_select 'select option[value="true"]'
|
86
|
+
assert_select 'select option[value="false"]'
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'input should include a blank option even if :include_blank is set to false if the collection includes a nil value' do
|
90
|
+
with_input_for @user, :age, :select, :collection => [nil], :include_blank => false
|
91
|
+
assert_select 'select option[value=""]'
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'input should automatically set include blank' do
|
95
|
+
with_input_for @user, :age, :select, :collection => 18..30
|
96
|
+
assert_select 'select option[value=]', ''
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'input should not set include blank if otherwise is told' do
|
100
|
+
with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false
|
101
|
+
assert_no_select 'select option[value=]', ''
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'input should not set include blank if prompt is given' do
|
105
|
+
with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo"
|
106
|
+
assert_no_select 'select option[value=]', ''
|
107
|
+
end
|
108
|
+
|
109
|
+
test 'input should not set include blank if multiple is given' do
|
110
|
+
with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true }
|
111
|
+
assert_no_select 'select option[value=]', ''
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'input should detect label and value on collections' do
|
115
|
+
users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ]
|
116
|
+
with_input_for @user, :description, :select, :collection => users
|
117
|
+
assert_select 'select option[value=1]', 'Jose'
|
118
|
+
assert_select 'select option[value=2]', 'Carlos'
|
119
|
+
end
|
120
|
+
|
121
|
+
test 'input should disable the anothers components when the option is a object' do
|
122
|
+
with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => true
|
123
|
+
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
124
|
+
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
125
|
+
assert_select 'select[disabled=disabled]'
|
126
|
+
assert_select 'div.disabled'
|
127
|
+
end
|
128
|
+
|
129
|
+
test 'input should not disable the anothers components when the option is a object' do
|
130
|
+
with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => 'Jose'
|
131
|
+
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
132
|
+
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
133
|
+
assert_no_select 'select[disabled=disabled]'
|
134
|
+
assert_no_select 'div.disabled'
|
135
|
+
end
|
136
|
+
|
137
|
+
test 'input should allow overriding label and value method using a lambda for collection selects' do
|
138
|
+
with_input_for @user, :name, :select,
|
139
|
+
:collection => ['Jose' , 'Carlos'],
|
140
|
+
:label_method => lambda { |i| i.upcase },
|
141
|
+
:value_method => lambda { |i| i.downcase }
|
142
|
+
assert_select 'select option[value=jose]', "JOSE"
|
143
|
+
assert_select 'select option[value=carlos]', "CARLOS"
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'input should allow overriding only label but not value method using a lambda for collection select' do
|
147
|
+
with_input_for @user, :name, :select,
|
148
|
+
:collection => ['Jose' , 'Carlos'],
|
149
|
+
:label_method => lambda { |i| i.upcase }
|
150
|
+
assert_select 'select option[value=Jose]', "JOSE"
|
151
|
+
assert_select 'select option[value=Carlos]', "CARLOS"
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'input should allow overriding only value but not label method using a lambda for collection select' do
|
155
|
+
with_input_for @user, :name, :select,
|
156
|
+
:collection => ['Jose' , 'Carlos'],
|
157
|
+
:value_method => lambda { |i| i.downcase }
|
158
|
+
assert_select 'select option[value=jose]', "Jose"
|
159
|
+
assert_select 'select option[value=carlos]', "Carlos"
|
160
|
+
end
|
161
|
+
|
162
|
+
test 'input should allow symbols for collections' do
|
163
|
+
with_input_for @user, :name, :select, :collection => [:jose, :carlos]
|
164
|
+
assert_select 'select.select#user_name'
|
165
|
+
assert_select 'select option[value=jose]', 'jose'
|
166
|
+
assert_select 'select option[value=carlos]', 'carlos'
|
167
|
+
end
|
168
|
+
|
169
|
+
test 'collection input with select type should generate required html attribute only with blank option' do
|
170
|
+
with_input_for @user, :name, :select, :include_blank => true, :collection => ['Jose' , 'Carlos']
|
171
|
+
assert_select 'select.required'
|
172
|
+
assert_select 'select[required]'
|
173
|
+
end
|
174
|
+
|
175
|
+
test 'collection input with select type should not generate required html attribute without blank option' do
|
176
|
+
with_input_for @user, :name, :select, :include_blank => false, :collection => ['Jose' , 'Carlos']
|
177
|
+
assert_select 'select.required'
|
178
|
+
assert_no_select 'select[required]'
|
179
|
+
end
|
180
|
+
|
181
|
+
test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do
|
182
|
+
with_input_for @user, :name, :select, :include_blank => false, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
|
183
|
+
assert_select 'select.required'
|
184
|
+
assert_select 'select[required]'
|
185
|
+
end
|
186
|
+
|
187
|
+
test 'collection input with select type with multiple attribute should generate required html attribute with blank option' do
|
188
|
+
with_input_for @user, :name, :select, :include_blank => true, :input_html => {:multiple => true}, :collection => ['Jose' , 'Carlos']
|
189
|
+
assert_select 'select.required'
|
190
|
+
assert_select 'select[required]'
|
191
|
+
end
|
192
|
+
|
193
|
+
test 'input should allow disabled options with a lambda for collection select' do
|
194
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
195
|
+
:disabled => lambda { |x| x == "Carlos" }
|
196
|
+
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
197
|
+
assert_select 'select option[value=Antonio]', 'Antonio'
|
198
|
+
assert_no_select 'select option[value=Antonio][disabled]'
|
199
|
+
end
|
200
|
+
|
201
|
+
test 'input should allow disabled and label method with lambdas for collection select' do
|
202
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
203
|
+
:disabled => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
|
204
|
+
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
205
|
+
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
206
|
+
assert_no_select 'select option[value=Antonio][disabled]'
|
207
|
+
end
|
208
|
+
|
209
|
+
test 'input should allow a non lambda disabled option with lambda label method for collections' do
|
210
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
211
|
+
:disabled => "Carlos", :label_method => lambda { |x| x.upcase }
|
212
|
+
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
213
|
+
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
214
|
+
assert_no_select 'select option[value=Antonio][disabled]'
|
215
|
+
end
|
216
|
+
|
217
|
+
test 'input should allow selected and label method with lambdas for collection select' do
|
218
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
219
|
+
:selected => lambda { |x| x == "Carlos" }, :label_method => lambda { |x| x.upcase }
|
220
|
+
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
221
|
+
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
222
|
+
assert_no_select 'select option[value=Antonio][selected]'
|
223
|
+
end
|
224
|
+
|
225
|
+
test 'input should allow a non lambda selected option with lambda label method for collection select' do
|
226
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
227
|
+
:selected => "Carlos", :label_method => lambda { |x| x.upcase }
|
228
|
+
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
229
|
+
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
230
|
+
assert_no_select 'select option[value=Antonio][selected]'
|
231
|
+
end
|
232
|
+
|
233
|
+
test 'input should not override default selection through attribute value with label method as lambda for collection select' do
|
234
|
+
@user.name = "Carlos"
|
235
|
+
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
|
236
|
+
:label_method => lambda { |x| x.upcase }
|
237
|
+
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
238
|
+
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
239
|
+
assert_no_select 'select option[value=Antonio][selected]'
|
240
|
+
end
|
241
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
# Tests for all different kinds of inputs.
|
5
|
+
class DateTimeInputTest < ActionView::TestCase
|
6
|
+
# DateTime input
|
7
|
+
test 'input should generate a datetime select by default for datetime attributes' do
|
8
|
+
with_input_for @user, :created_at, :datetime
|
9
|
+
1.upto(5) do |i|
|
10
|
+
assert_select "form select.datetime#user_created_at_#{i}i"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'input should be able to pass options to datetime select' do
|
15
|
+
with_input_for @user, :created_at, :datetime,
|
16
|
+
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
17
|
+
|
18
|
+
assert_select 'select.datetime[disabled=disabled]'
|
19
|
+
assert_select 'select.datetime option', 'ano'
|
20
|
+
assert_select 'select.datetime option', 'mês'
|
21
|
+
assert_select 'select.datetime option', 'dia'
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'input should generate a date select for date attributes' do
|
25
|
+
with_input_for @user, :born_at, :date
|
26
|
+
assert_select 'select.date#user_born_at_1i'
|
27
|
+
assert_select 'select.date#user_born_at_2i'
|
28
|
+
assert_select 'select.date#user_born_at_3i'
|
29
|
+
assert_no_select 'select.date#user_born_at_4i'
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'input should be able to pass options to date select' do
|
33
|
+
with_input_for @user, :born_at, :date, :as => :date,
|
34
|
+
:disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
|
35
|
+
|
36
|
+
assert_select 'select.date[disabled=disabled]'
|
37
|
+
assert_select 'select.date option', 'ano'
|
38
|
+
assert_select 'select.date option', 'mês'
|
39
|
+
assert_select 'select.date option', 'dia'
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'input should be able to pass :default to date select' do
|
43
|
+
with_input_for @user, :born_at, :date, :default => Date.today
|
44
|
+
assert_select "select.date option[value=#{Date.today.year}][selected=selected]"
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'input should generate a time select for time attributes' do
|
48
|
+
with_input_for @user, :delivery_time, :time
|
49
|
+
assert_select 'input[type=hidden]#user_delivery_time_1i'
|
50
|
+
assert_select 'input[type=hidden]#user_delivery_time_2i'
|
51
|
+
assert_select 'input[type=hidden]#user_delivery_time_3i'
|
52
|
+
assert_select 'select.time#user_delivery_time_4i'
|
53
|
+
assert_select 'select.time#user_delivery_time_5i'
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'input should be able to pass options to time select' do
|
57
|
+
with_input_for @user, :delivery_time, :time, :required => true,
|
58
|
+
:disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
|
59
|
+
|
60
|
+
assert_select 'select.time[disabled=disabled]'
|
61
|
+
assert_select 'select.time option', 'hora'
|
62
|
+
assert_select 'select.time option', 'minuto'
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'label should point to first option when date input type' do
|
66
|
+
with_input_for :project, :created_at, :date
|
67
|
+
assert_select 'label[for=project_created_at_1i]'
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'label should point to first option when datetime input type' do
|
71
|
+
with_input_for :project, :created_at, :datetime
|
72
|
+
assert_select 'label[for=project_created_at_1i]'
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'label should point to first option when time input type' do
|
76
|
+
with_input_for :project, :created_at, :time
|
77
|
+
assert_select 'label[for=project_created_at_4i]'
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'date time input should not generate invalid required html attribute' do
|
81
|
+
with_input_for @user, :delivery_time, :time, :required => true
|
82
|
+
assert_select 'select.required'
|
83
|
+
assert_no_select 'select[required]'
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DisabledTest < ActionView::TestCase
|
4
|
+
test 'input should generate disabled elements based on the disabled option' do
|
5
|
+
with_input_for @user, :name, :string, :disabled => true
|
6
|
+
assert_select 'input.string.disabled[disabled]'
|
7
|
+
with_input_for @user, :description, :text, :disabled => true
|
8
|
+
assert_select 'textarea.text.disabled[disabled]'
|
9
|
+
with_input_for @user, :age, :integer, :disabled => true
|
10
|
+
assert_select 'input.integer.disabled[disabled]'
|
11
|
+
with_input_for @user, :born_at, :date, :disabled => true
|
12
|
+
assert_select 'select.date.disabled[disabled]'
|
13
|
+
with_input_for @user, :created_at, :datetime, :disabled => true
|
14
|
+
assert_select 'select.datetime.disabled[disabled]'
|
15
|
+
|
16
|
+
with_input_for @user, :name, :string, :disabled => false
|
17
|
+
assert_select 'input.string:not(.disabled[disabled])'
|
18
|
+
with_input_for @user, :description, :text, :disabled => false
|
19
|
+
assert_select 'textarea.text:not(.disabled[disabled])'
|
20
|
+
with_input_for @user, :age, :integer, :disabled => false
|
21
|
+
assert_select 'input.integer:not(.disabled[disabled])'
|
22
|
+
with_input_for @user, :born_at, :date, :disabled => false
|
23
|
+
assert_select 'select.date:not(.disabled[disabled])'
|
24
|
+
with_input_for @user, :created_at, :datetime, :disabled => false
|
25
|
+
assert_select 'select.datetime:not(.disabled[disabled])'
|
26
|
+
|
27
|
+
with_input_for @user, :name, :string
|
28
|
+
assert_select 'input.string:not(.disabled[disabled])'
|
29
|
+
with_input_for @user, :description, :text
|
30
|
+
assert_select 'textarea.text:not(.disabled[disabled])'
|
31
|
+
with_input_for @user, :age, :integer
|
32
|
+
assert_select 'input.integer:not(.disabled[disabled])'
|
33
|
+
with_input_for @user, :born_at, :date
|
34
|
+
assert_select 'select.date:not(.disabled[disabled])'
|
35
|
+
with_input_for @user, :created_at, :datetime
|
36
|
+
assert_select 'select.datetime:not(.disabled[disabled])'
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DiscoveryTest < ActionView::TestCase
|
4
|
+
# Setup new inputs and remove them after the test.
|
5
|
+
def discovery(value=false)
|
6
|
+
swap SimpleForm, :cache_discovery => value do
|
7
|
+
begin
|
8
|
+
load "support/discovery_inputs.rb"
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
SimpleForm::FormBuilder.discovery_cache.clear
|
12
|
+
Object.send :remove_const, :StringInput
|
13
|
+
Object.send :remove_const, :NumericInput
|
14
|
+
Object.send :remove_const, :CustomizedInput
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'builder should not discover new inputs if cached' do
|
20
|
+
with_form_for @user, :name
|
21
|
+
assert_select 'form input#user_name.string'
|
22
|
+
|
23
|
+
discovery(true) do
|
24
|
+
with_form_for @user, :name
|
25
|
+
assert_no_select 'form section input#user_name.string'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'builder should discover new inputs' do
|
30
|
+
discovery do
|
31
|
+
with_form_for @user, :name, :as => :customized
|
32
|
+
assert_select 'form section input#user_name.string'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'builder should not discover new inputs if discovery is off' do
|
37
|
+
with_form_for @user, :name
|
38
|
+
assert_select 'form input#user_name.string'
|
39
|
+
|
40
|
+
swap SimpleForm, :inputs_discovery => false do
|
41
|
+
discovery do
|
42
|
+
with_form_for @user, :name
|
43
|
+
assert_no_select 'form section input#user_name.string'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'builder should discover new inputs from mappings if not cached' do
|
49
|
+
discovery do
|
50
|
+
with_form_for @user, :name
|
51
|
+
assert_select 'form section input#user_name.string'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'builder should discover new inputs from internal fallbacks if not cached' do
|
56
|
+
discovery do
|
57
|
+
with_form_for @user, :age
|
58
|
+
assert_select 'form section input#user_age.numeric.integer'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class FileInputTest < ActionView::TestCase
|
5
|
+
test 'input should generate a file field' do
|
6
|
+
with_input_for @user, :name, :file
|
7
|
+
assert_select 'input#user_name[type=file]'
|
8
|
+
end
|
9
|
+
|
10
|
+
test "input should generate a file field that doesn't accept placeholder" do
|
11
|
+
store_translations(:en, :simple_form => { :placeholders => { :user => { :name => "text" } } }) do
|
12
|
+
with_input_for @user, :name, :file
|
13
|
+
assert_no_select 'input[placeholder]'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class InputTest < ActionView::TestCase
|
5
|
+
test 'input should generate css class based on default input type' do
|
6
|
+
with_input_for @user, :name, :string
|
7
|
+
assert_select 'input.string'
|
8
|
+
with_input_for @user, :description, :text
|
9
|
+
assert_select 'textarea.text'
|
10
|
+
with_input_for @user, :age, :integer
|
11
|
+
assert_select 'input.integer'
|
12
|
+
with_input_for @user, :born_at, :date
|
13
|
+
assert_select 'select.date'
|
14
|
+
with_input_for @user, :created_at, :datetime
|
15
|
+
assert_select 'select.datetime'
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'input should generate autofocus attribute based on the autofocus option' do
|
19
|
+
with_input_for @user, :name, :string, :autofocus => true
|
20
|
+
assert_select 'input.string[autofocus]'
|
21
|
+
with_input_for @user, :description, :text, :autofocus => true
|
22
|
+
assert_select 'textarea.text[autofocus]'
|
23
|
+
with_input_for @user, :age, :integer, :autofocus => true
|
24
|
+
assert_select 'input.integer[autofocus]'
|
25
|
+
with_input_for @user, :born_at, :date, :autofocus => true
|
26
|
+
assert_select 'select.date[autofocus]'
|
27
|
+
with_input_for @user, :created_at, :datetime, :autofocus => true
|
28
|
+
assert_select 'select.datetime[autofocus]'
|
29
|
+
|
30
|
+
with_input_for @user, :name, :string, :autofocus => false
|
31
|
+
assert_select 'input.string:not([autofocus])'
|
32
|
+
with_input_for @user, :description, :text, :autofocus => false
|
33
|
+
assert_select 'textarea.text:not([autofocus])'
|
34
|
+
with_input_for @user, :age, :integer, :autofocus => false
|
35
|
+
assert_select 'input.integer:not([autofocus])'
|
36
|
+
with_input_for @user, :born_at, :date, :autofocus => false
|
37
|
+
assert_select 'select.date:not([autofocus])'
|
38
|
+
with_input_for @user, :created_at, :datetime, :autofocus => false
|
39
|
+
assert_select 'select.datetime:not([autofocus])'
|
40
|
+
|
41
|
+
with_input_for @user, :name, :string
|
42
|
+
assert_select 'input.string:not([autofocus])'
|
43
|
+
with_input_for @user, :description, :text
|
44
|
+
assert_select 'textarea.text:not([autofocus])'
|
45
|
+
with_input_for @user, :age, :integer
|
46
|
+
assert_select 'input.integer:not([autofocus])'
|
47
|
+
with_input_for @user, :born_at, :date
|
48
|
+
assert_select 'select.date:not([autofocus])'
|
49
|
+
with_input_for @user, :created_at, :datetime
|
50
|
+
assert_select 'select.datetime:not([autofocus])'
|
51
|
+
end
|
52
|
+
|
53
|
+
# With no object
|
54
|
+
test 'input should be generated properly when object is not present' do
|
55
|
+
with_input_for :project, :name, :string
|
56
|
+
assert_select 'input.string.required#project_name'
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'input as radio should be generated properly when object is not present ' do
|
60
|
+
with_input_for :project, :name, :radio_buttons
|
61
|
+
assert_select 'input.radio_buttons#project_name_true'
|
62
|
+
assert_select 'input.radio_buttons#project_name_false'
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'input as select with collection should be generated properly when object is not present' do
|
66
|
+
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
67
|
+
assert_select 'select.select#project_name'
|
68
|
+
end
|
69
|
+
end
|