simple_form_awesome 2.2.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.
- data/CHANGELOG.md +327 -0
- data/MIT-LICENSE +20 -0
- data/README.md +25 -0
- data/lib/generators/simple_form/USAGE +3 -0
- data/lib/generators/simple_form/install_generator.rb +48 -0
- data/lib/generators/simple_form/templates/AUI_README +19 -0
- data/lib/generators/simple_form/templates/README +12 -0
- data/lib/generators/simple_form/templates/_form.html.erb +13 -0
- data/lib/generators/simple_form/templates/_form.html.haml +10 -0
- data/lib/generators/simple_form/templates/_form.html.slim +10 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +142 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_aui.rb +21 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +26 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +26 -0
- data/lib/simple_form/action_view_extensions/builder.rb +340 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +72 -0
- data/lib/simple_form/components/errors.rb +35 -0
- data/lib/simple_form/components/hints.rb +18 -0
- data/lib/simple_form/components/html5.rb +26 -0
- data/lib/simple_form/components/label_input.rb +15 -0
- data/lib/simple_form/components/labels.rb +79 -0
- data/lib/simple_form/components/maxlength.rb +41 -0
- data/lib/simple_form/components/min_max.rb +50 -0
- data/lib/simple_form/components/pattern.rb +34 -0
- data/lib/simple_form/components/placeholders.rb +16 -0
- data/lib/simple_form/components/readonly.rb +22 -0
- data/lib/simple_form/components.rb +20 -0
- data/lib/simple_form/core_ext/hash.rb +16 -0
- data/lib/simple_form/error_notification.rb +48 -0
- data/lib/simple_form/form_builder.rb +482 -0
- 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 +35 -0
- data/lib/simple_form/helpers/validators.rb +44 -0
- data/lib/simple_form/helpers.rb +12 -0
- data/lib/simple_form/i18n_cache.rb +22 -0
- data/lib/simple_form/inputs/aui_string_input.rb +10 -0
- data/lib/simple_form/inputs/base.rb +184 -0
- data/lib/simple_form/inputs/block_input.rb +14 -0
- data/lib/simple_form/inputs/boolean_input.rb +78 -0
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
- data/lib/simple_form/inputs/collection_input.rb +101 -0
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +63 -0
- data/lib/simple_form/inputs/collection_select_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +28 -0
- data/lib/simple_form/inputs/file_input.rb +9 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
- data/lib/simple_form/inputs/hidden_input.rb +17 -0
- data/lib/simple_form/inputs/numeric_input.rb +24 -0
- data/lib/simple_form/inputs/password_input.rb +12 -0
- data/lib/simple_form/inputs/priority_input.rb +24 -0
- data/lib/simple_form/inputs/range_input.rb +14 -0
- data/lib/simple_form/inputs/string_input.rb +23 -0
- data/lib/simple_form/inputs/text_area_input.rb +12 -0
- data/lib/simple_form/inputs/text_input.rb +11 -0
- data/lib/simple_form/inputs.rb +23 -0
- data/lib/simple_form/map_type.rb +16 -0
- data/lib/simple_form/version.rb +3 -0
- data/lib/simple_form/wrappers/builder.rb +103 -0
- data/lib/simple_form/wrappers/many.rb +73 -0
- data/lib/simple_form/wrappers/root.rb +36 -0
- data/lib/simple_form/wrappers/single.rb +24 -0
- data/lib/simple_form/wrappers.rb +8 -0
- data/lib/simple_form.rb +221 -0
- data/test/action_view_extensions/builder_test.rb +583 -0
- data/test/action_view_extensions/form_helper_test.rb +143 -0
- data/test/components/label_test.rb +327 -0
- data/test/form_builder/association_test.rb +186 -0
- data/test/form_builder/button_test.rb +47 -0
- data/test/form_builder/error_notification_test.rb +79 -0
- data/test/form_builder/error_test.rb +121 -0
- data/test/form_builder/general_test.rb +402 -0
- data/test/form_builder/hint_test.rb +138 -0
- data/test/form_builder/input_field_test.rb +63 -0
- data/test/form_builder/label_test.rb +71 -0
- data/test/form_builder/wrapper_test.rb +203 -0
- data/test/generators/simple_form_generator_test.rb +42 -0
- data/test/inputs/boolean_input_test.rb +140 -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 +99 -0
- data/test/inputs/disabled_test.rb +78 -0
- data/test/inputs/discovery_test.rb +69 -0
- data/test/inputs/file_input_test.rb +16 -0
- data/test/inputs/general_test.rb +116 -0
- data/test/inputs/grouped_collection_select_input_test.rb +118 -0
- data/test/inputs/hidden_input_test.rb +30 -0
- data/test/inputs/numeric_input_test.rb +173 -0
- data/test/inputs/priority_input_test.rb +43 -0
- data/test/inputs/readonly_test.rb +101 -0
- data/test/inputs/required_test.rb +113 -0
- data/test/inputs/string_input_test.rb +146 -0
- data/test/inputs/text_input_test.rb +24 -0
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +27 -0
- data/test/support/misc_helpers.rb +138 -0
- data/test/support/mock_controller.rb +24 -0
- data/test/support/models.rb +216 -0
- data/test/test_helper.rb +95 -0
- metadata +217 -0
@@ -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,99 @@
|
|
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 use i18n to get target for date input type' do
|
66
|
+
store_translations(:en, :date => { :order => [:month, :day, :year] }) do
|
67
|
+
with_input_for :project, :created_at, :date
|
68
|
+
assert_select 'label[for=project_created_at_2i]'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'label should use i18n to get target for datetime input type' do
|
73
|
+
store_translations(:en, :date => { :order => [:month, :day, :year] }) do
|
74
|
+
with_input_for :project, :created_at, :datetime
|
75
|
+
assert_select 'label[for=project_created_at_2i]'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'label should use order to get target when date input type' do
|
80
|
+
with_input_for :project, :created_at, :date, :order => [:month, :year, :day]
|
81
|
+
assert_select 'label[for=project_created_at_2i]'
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'label should use order to get target when datetime input type' do
|
85
|
+
with_input_for :project, :created_at, :datetime, :order => [:month, :year, :day]
|
86
|
+
assert_select 'label[for=project_created_at_2i]'
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'label should point to first option when time input type' do
|
90
|
+
with_input_for :project, :created_at, :time
|
91
|
+
assert_select 'label[for=project_created_at_4i]'
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'date time input should not generate invalid required html attribute' do
|
95
|
+
with_input_for @user, :delivery_time, :time, :required => true
|
96
|
+
assert_select 'select.required'
|
97
|
+
assert_no_select 'select[required]'
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DisabledTest < ActionView::TestCase
|
4
|
+
test 'string input should be disabled when disabled option is true' do
|
5
|
+
with_input_for @user, :name, :string, :disabled => true
|
6
|
+
assert_select 'input.string.disabled[disabled]'
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'text input should be disabled when disabled option is true' do
|
10
|
+
with_input_for @user, :description, :text, :disabled => true
|
11
|
+
assert_select 'textarea.text.disabled[disabled]'
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'numeric input should be disabled when disabled option is true' do
|
15
|
+
with_input_for @user, :age, :integer, :disabled => true
|
16
|
+
assert_select 'input.integer.disabled[disabled]'
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'date input should be disabled when disabled option is true' do
|
20
|
+
with_input_for @user, :born_at, :date, :disabled => true
|
21
|
+
assert_select 'select.date.disabled[disabled]'
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'datetime input should be disabled when disabled option is true' do
|
25
|
+
with_input_for @user, :created_at, :datetime, :disabled => true
|
26
|
+
assert_select 'select.datetime.disabled[disabled]'
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'string input should not be disabled when disabled option is false' do
|
30
|
+
with_input_for @user, :name, :string, :disabled => false
|
31
|
+
assert_no_select 'input.string.disabled[disabled]'
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'text input should not be disabled when disabled option is false' do
|
35
|
+
with_input_for @user, :description, :text, :disabled => false
|
36
|
+
assert_no_select 'textarea.text.disabled[disabled]'
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'numeric input should not be disabled when disabled option is false' do
|
40
|
+
with_input_for @user, :age, :integer, :disabled => false
|
41
|
+
assert_no_select 'input.integer.disabled[disabled]'
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'date input should not be disabled when disabled option is false' do
|
45
|
+
with_input_for @user, :born_at, :date, :disabled => false
|
46
|
+
assert_no_select 'select.date.disabled[disabled]'
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'datetime input should not be disabled when disabled option is false' do
|
50
|
+
with_input_for @user, :created_at, :datetime, :disabled => false
|
51
|
+
assert_no_select 'select.datetime.disabled[disabled]'
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'string input should not be disabled when disabled option is not present' do
|
55
|
+
with_input_for @user, :name, :string
|
56
|
+
assert_no_select 'input.string.disabled[disabled]'
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'text input should not be disabled when disabled option is not present' do
|
60
|
+
with_input_for @user, :description, :text
|
61
|
+
assert_no_select 'textarea.text.disabled[disabled]'
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'numeric input should not be disabled when disabled option is not present' do
|
65
|
+
with_input_for @user, :age, :integer
|
66
|
+
assert_no_select 'input.integer.disabled[disabled]'
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'date input should not be disabled when disabled option is not present' do
|
70
|
+
with_input_for @user, :born_at, :date
|
71
|
+
assert_no_select 'select.date.disabled[disabled]'
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'datetime input should not be disabled when disabled option is not present' do
|
75
|
+
with_input_for @user, :created_at, :datetime
|
76
|
+
assert_no_select 'select.datetime.disabled[disabled]'
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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
|
+
Object.send :remove_const, :CollectionSelectInput
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'builder should not discover new inputs if cached' do
|
21
|
+
with_form_for @user, :name
|
22
|
+
assert_select 'form input#user_name.string'
|
23
|
+
|
24
|
+
discovery(true) do
|
25
|
+
with_form_for @user, :name
|
26
|
+
assert_no_select 'form section input#user_name.string'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'builder should discover new inputs' do
|
31
|
+
discovery do
|
32
|
+
with_form_for @user, :name, :as => :customized
|
33
|
+
assert_select 'form section input#user_name.string'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'builder should not discover new inputs if discovery is off' do
|
38
|
+
with_form_for @user, :name
|
39
|
+
assert_select 'form input#user_name.string'
|
40
|
+
|
41
|
+
swap SimpleForm, :inputs_discovery => false do
|
42
|
+
discovery do
|
43
|
+
with_form_for @user, :name
|
44
|
+
assert_no_select 'form section input#user_name.string'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'builder should discover new inputs from mappings if not cached' do
|
50
|
+
discovery do
|
51
|
+
with_form_for @user, :name
|
52
|
+
assert_select 'form section input#user_name.string'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'builder should discover new inputs from internal fallbacks if not cached' do
|
57
|
+
discovery do
|
58
|
+
with_form_for @user, :age
|
59
|
+
assert_select 'form section input#user_age.numeric.integer'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'new inputs can override the input_html_options' do
|
64
|
+
discovery do
|
65
|
+
with_form_for @user, :active, :as => :select
|
66
|
+
assert_select 'form select#user_active.select.chosen'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
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,116 @@
|
|
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 'string input should generate autofocus attribute when autofocus option is true' do
|
19
|
+
with_input_for @user, :name, :string, :autofocus => true
|
20
|
+
assert_select 'input.string[autofocus]'
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'text input should generate autofocus attribute when autofocus option is true' do
|
24
|
+
with_input_for @user, :description, :text, :autofocus => true
|
25
|
+
assert_select 'textarea.text[autofocus]'
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'numeric input should generate autofocus attribute when autofocus option is true' do
|
29
|
+
with_input_for @user, :age, :integer, :autofocus => true
|
30
|
+
assert_select 'input.integer[autofocus]'
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'date input should generate autofocus attribute when autofocus option is true' do
|
34
|
+
with_input_for @user, :born_at, :date, :autofocus => true
|
35
|
+
assert_select 'select.date[autofocus]'
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'datetime input should generate autofocus attribute when autofocus option is true' do
|
39
|
+
with_input_for @user, :created_at, :datetime, :autofocus => true
|
40
|
+
assert_select 'select.datetime[autofocus]'
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'string input should generate autofocus attribute when autofocus option is false' do
|
44
|
+
with_input_for @user, :name, :string, :autofocus => false
|
45
|
+
assert_no_select 'input.string[autofocus]'
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'text input should generate autofocus attribute when autofocus option is false' do
|
49
|
+
with_input_for @user, :description, :text, :autofocus => false
|
50
|
+
assert_no_select 'textarea.text[autofocus]'
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'numeric input should generate autofocus attribute when autofocus option is false' do
|
54
|
+
with_input_for @user, :age, :integer, :autofocus => false
|
55
|
+
assert_no_select 'input.integer[autofocus]'
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'date input should generate autofocus attribute when autofocus option is false' do
|
59
|
+
with_input_for @user, :born_at, :date, :autofocus => false
|
60
|
+
assert_no_select 'select.date[autofocus]'
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'datetime input should generate autofocus attribute when autofocus option is false' do
|
64
|
+
with_input_for @user, :created_at, :datetime, :autofocus => false
|
65
|
+
assert_no_select 'select.datetime[autofocus]'
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'string input should generate autofocus attribute when autofocus option is not present' do
|
69
|
+
with_input_for @user, :name, :string
|
70
|
+
assert_no_select 'input.string[autofocus]'
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'text input should generate autofocus attribute when autofocus option is not present' do
|
74
|
+
with_input_for @user, :description, :text
|
75
|
+
assert_no_select 'textarea.text[autofocus]'
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'numeric input should generate autofocus attribute when autofocus option is not present' do
|
79
|
+
with_input_for @user, :age, :integer
|
80
|
+
assert_no_select 'input.integer[autofocus]'
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'date input should generate autofocus attribute when autofocus option is not present' do
|
84
|
+
with_input_for @user, :born_at, :date
|
85
|
+
assert_no_select 'select.date[autofocus]'
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'datetime input should generate autofocus attribute when autofocus option is not present' do
|
89
|
+
with_input_for @user, :created_at, :datetime
|
90
|
+
assert_no_select 'select.datetime[autofocus]'
|
91
|
+
end
|
92
|
+
|
93
|
+
# With no object
|
94
|
+
test 'input should be generated properly when object is not present' do
|
95
|
+
with_input_for :project, :name, :string
|
96
|
+
assert_select 'input.string.required#project_name'
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'input as radio should be generated properly when object is not present ' do
|
100
|
+
with_input_for :project, :name, :radio_buttons
|
101
|
+
assert_select 'input.radio_buttons#project_name_true'
|
102
|
+
assert_select 'input.radio_buttons#project_name_false'
|
103
|
+
end
|
104
|
+
|
105
|
+
test 'input as select with collection should be generated properly when object is not present' do
|
106
|
+
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
107
|
+
assert_select 'select.select#project_name'
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'input should not generate empty css class' do
|
111
|
+
swap SimpleForm, :generate_additional_classes_for => [:wrapper, :label] do
|
112
|
+
with_input_for :project, :name, :string
|
113
|
+
assert_no_select 'input#project_name[class]'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|