ehoch_simple_form 2.0.2.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG.md +257 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +797 -0
  4. data/lib/generators/simple_form/USAGE +3 -0
  5. data/lib/generators/simple_form/install_generator.rb +32 -0
  6. data/lib/generators/simple_form/templates/README +12 -0
  7. data/lib/generators/simple_form/templates/_form.html.erb +13 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +10 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +10 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +181 -0
  11. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +26 -0
  12. data/lib/simple_form.rb +215 -0
  13. data/lib/simple_form/action_view_extensions/builder.rb +338 -0
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +74 -0
  15. data/lib/simple_form/components.rb +20 -0
  16. data/lib/simple_form/components/errors.rb +35 -0
  17. data/lib/simple_form/components/hints.rb +18 -0
  18. data/lib/simple_form/components/html5.rb +26 -0
  19. data/lib/simple_form/components/label_input.rb +15 -0
  20. data/lib/simple_form/components/labels.rb +79 -0
  21. data/lib/simple_form/components/maxlength.rb +41 -0
  22. data/lib/simple_form/components/min_max.rb +50 -0
  23. data/lib/simple_form/components/pattern.rb +34 -0
  24. data/lib/simple_form/components/placeholders.rb +16 -0
  25. data/lib/simple_form/components/readonly.rb +22 -0
  26. data/lib/simple_form/core_ext/hash.rb +16 -0
  27. data/lib/simple_form/error_notification.rb +48 -0
  28. data/lib/simple_form/form_builder.rb +472 -0
  29. data/lib/simple_form/helpers.rb +12 -0
  30. data/lib/simple_form/helpers/autofocus.rb +11 -0
  31. data/lib/simple_form/helpers/disabled.rb +15 -0
  32. data/lib/simple_form/helpers/readonly.rb +15 -0
  33. data/lib/simple_form/helpers/required.rb +35 -0
  34. data/lib/simple_form/helpers/validators.rb +44 -0
  35. data/lib/simple_form/i18n_cache.rb +22 -0
  36. data/lib/simple_form/inputs.rb +21 -0
  37. data/lib/simple_form/inputs/base.rb +162 -0
  38. data/lib/simple_form/inputs/block_input.rb +14 -0
  39. data/lib/simple_form/inputs/boolean_input.rb +64 -0
  40. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  41. data/lib/simple_form/inputs/collection_input.rb +101 -0
  42. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +63 -0
  43. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  44. data/lib/simple_form/inputs/date_time_input.rb +28 -0
  45. data/lib/simple_form/inputs/file_input.rb +9 -0
  46. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  47. data/lib/simple_form/inputs/hidden_input.rb +17 -0
  48. data/lib/simple_form/inputs/numeric_input.rb +24 -0
  49. data/lib/simple_form/inputs/password_input.rb +12 -0
  50. data/lib/simple_form/inputs/priority_input.rb +24 -0
  51. data/lib/simple_form/inputs/range_input.rb +14 -0
  52. data/lib/simple_form/inputs/string_input.rb +23 -0
  53. data/lib/simple_form/inputs/text_input.rb +11 -0
  54. data/lib/simple_form/map_type.rb +16 -0
  55. data/lib/simple_form/version.rb +3 -0
  56. data/lib/simple_form/wrappers.rb +8 -0
  57. data/lib/simple_form/wrappers/builder.rb +103 -0
  58. data/lib/simple_form/wrappers/many.rb +69 -0
  59. data/lib/simple_form/wrappers/root.rb +34 -0
  60. data/lib/simple_form/wrappers/single.rb +18 -0
  61. data/test/action_view_extensions/builder_test.rb +577 -0
  62. data/test/action_view_extensions/form_helper_test.rb +104 -0
  63. data/test/components/label_test.rb +310 -0
  64. data/test/form_builder/association_test.rb +177 -0
  65. data/test/form_builder/button_test.rb +47 -0
  66. data/test/form_builder/error_notification_test.rb +79 -0
  67. data/test/form_builder/error_test.rb +121 -0
  68. data/test/form_builder/general_test.rb +356 -0
  69. data/test/form_builder/hint_test.rb +139 -0
  70. data/test/form_builder/input_field_test.rb +63 -0
  71. data/test/form_builder/label_test.rb +71 -0
  72. data/test/form_builder/wrapper_test.rb +149 -0
  73. data/test/generators/simple_form_generator_test.rb +32 -0
  74. data/test/inputs/boolean_input_test.rb +108 -0
  75. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  76. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  77. data/test/inputs/collection_select_input_test.rb +241 -0
  78. data/test/inputs/datetime_input_test.rb +99 -0
  79. data/test/inputs/disabled_test.rb +38 -0
  80. data/test/inputs/discovery_test.rb +61 -0
  81. data/test/inputs/file_input_test.rb +16 -0
  82. data/test/inputs/general_test.rb +69 -0
  83. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  84. data/test/inputs/hidden_input_test.rb +30 -0
  85. data/test/inputs/numeric_input_test.rb +173 -0
  86. data/test/inputs/priority_input_test.rb +43 -0
  87. data/test/inputs/readonly_test.rb +61 -0
  88. data/test/inputs/required_test.rb +113 -0
  89. data/test/inputs/string_input_test.rb +140 -0
  90. data/test/inputs/text_input_test.rb +24 -0
  91. data/test/simple_form_test.rb +9 -0
  92. data/test/support/discovery_inputs.rb +21 -0
  93. data/test/support/misc_helpers.rb +102 -0
  94. data/test/support/mock_controller.rb +24 -0
  95. data/test/support/models.rb +210 -0
  96. data/test/test_helper.rb +90 -0
  97. metadata +210 -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,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