simple_form 1.2.0 → 1.2.1

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.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (38) hide show
  1. data/README.rdoc +30 -30
  2. data/lib/generators/simple_form/USAGE +1 -1
  3. data/lib/generators/simple_form/install_generator.rb +5 -6
  4. data/lib/generators/simple_form/templates/_form.html.haml +18 -0
  5. data/lib/generators/simple_form/templates/en.yml +14 -0
  6. data/lib/generators/simple_form/templates/simple_form.rb +21 -8
  7. data/lib/simple_form.rb +29 -8
  8. data/lib/simple_form/action_view_extensions/form_helper.rb +24 -1
  9. data/lib/simple_form/components.rb +5 -4
  10. data/lib/simple_form/components/errors.rb +13 -5
  11. data/lib/simple_form/components/hints.rb +1 -1
  12. data/lib/simple_form/components/label_input.rb +13 -0
  13. data/lib/simple_form/components/labels.rb +1 -1
  14. data/lib/simple_form/components/wrapper.rb +12 -2
  15. data/lib/simple_form/error_notification.rb +44 -0
  16. data/lib/simple_form/form_builder.rb +17 -1
  17. data/lib/simple_form/inputs.rb +1 -0
  18. data/lib/simple_form/inputs/base.rb +17 -9
  19. data/lib/simple_form/inputs/boolean_input.rb +22 -0
  20. data/lib/simple_form/inputs/collection_input.rb +6 -6
  21. data/lib/simple_form/inputs/date_time_input.rb +4 -4
  22. data/lib/simple_form/inputs/mapping_input.rb +0 -1
  23. data/lib/simple_form/inputs/numeric_input.rb +5 -1
  24. data/lib/simple_form/inputs/string_input.rb +5 -6
  25. data/lib/simple_form/version.rb +1 -1
  26. data/test/action_view_extensions/builder_test.rb +18 -18
  27. data/test/action_view_extensions/form_helper_test.rb +5 -5
  28. data/test/components/error_test.rb +14 -5
  29. data/test/components/hint_test.rb +1 -1
  30. data/test/components/label_test.rb +4 -3
  31. data/test/components/wrapper_test.rb +54 -0
  32. data/test/error_notification_test.rb +61 -0
  33. data/test/form_builder_test.rb +31 -11
  34. data/test/inputs_test.rb +55 -51
  35. data/test/support/mock_controller.rb +4 -4
  36. data/test/support/models.rb +11 -8
  37. data/test/test_helper.rb +8 -9
  38. metadata +30 -4
@@ -9,28 +9,28 @@ class FormHelperTest < ActionView::TestCase
9
9
  end
10
10
 
11
11
  test 'simple form should add default class to form' do
12
- concat(simple_form_for :user do |f| end)
12
+ concat(simple_form_for(:user) do |f| end)
13
13
  assert_select 'form.simple_form'
14
14
  end
15
15
 
16
16
  test 'simple form should add object name as css class to form when object is not present' do
17
- concat(simple_form_for :user do |f| end)
17
+ concat(simple_form_for(:user) do |f| end)
18
18
  assert_select 'form.simple_form.user'
19
19
  end
20
20
 
21
21
  test 'simple form should add object class name as css class to form' do
22
- concat(simple_form_for @user do |f| end)
22
+ concat(simple_form_for(@user) do |f| end)
23
23
  assert_select 'form.simple_form.user'
24
24
  end
25
25
 
26
26
  test 'pass options to simple form' do
27
- concat(simple_form_for :user, :url => '/account', :html => { :id => 'my_form' } do |f| end)
27
+ concat(simple_form_for(:user, :url => '/account', :html => { :id => 'my_form' }) do |f| end)
28
28
  assert_select 'form#my_form'
29
29
  assert_select 'form[action=/account]'
30
30
  end
31
31
 
32
32
  test 'fields for yields an instance of FormBuilder' do
33
- concat(simple_fields_for :user do |f|
33
+ concat(simple_fields_for(:user) do |f|
34
34
  assert f.instance_of?(SimpleForm::FormBuilder)
35
35
  end)
36
36
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class ErrorTest < ActionView::TestCase
4
4
 
5
5
  def with_error_for(object, attribute_name, type, options={}, &block)
6
- concat(simple_form_for object do |f|
6
+ concat(simple_form_for(object) do |f|
7
7
  f.attribute_name = attribute_name
8
8
  f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
9
9
  f.input_type = type
@@ -28,9 +28,18 @@ class ErrorTest < ActionView::TestCase
28
28
  assert_select 'span.error', "can't be blank"
29
29
  end
30
30
 
31
- test 'error should generate messages for attribute with several errors' do
32
- with_error_for @user, :age, :numeric
33
- assert_select 'span.error', 'is not a number and must be greater than 18'
31
+ test 'error should generate messages for attribute with one error when using first' do
32
+ swap SimpleForm, :error_method => :first do
33
+ with_error_for @user, :age, :numeric
34
+ assert_select 'span.error', 'is not a number'
35
+ end
36
+ end
37
+
38
+ test 'error should generate messages for attribute with several errors when using to_sentence' do
39
+ swap SimpleForm, :error_method => :to_sentence do
40
+ with_error_for @user, :age, :numeric
41
+ assert_select 'span.error', 'is not a number and must be greater than 18'
42
+ end
34
43
  end
35
44
 
36
45
  test 'error should be able to pass html options' do
@@ -39,7 +48,7 @@ class ErrorTest < ActionView::TestCase
39
48
  end
40
49
 
41
50
  test 'error should find errors on attribute and association' do
42
- with_error_for @user, :company_id, :select, :setup_association => true
51
+ with_error_for @user, :company_id, :select, :setup_association => true, :error_method => :to_sentence
43
52
  assert_select 'span.error', 'must be valid and company must be present'
44
53
  end
45
54
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class HintTest < ActionView::TestCase
4
4
 
5
5
  def with_hint_for(object, attribute_name, type, options={}, &block)
6
- concat(simple_form_for object do |f|
6
+ concat(simple_form_for(object) do |f|
7
7
  f.attribute_name = attribute_name
8
8
  f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
9
9
  f.input_type = type
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
 
3
4
  class LabelTest < ActionView::TestCase
@@ -7,7 +8,7 @@ class LabelTest < ActionView::TestCase
7
8
  end
8
9
 
9
10
  def with_label_for(object, attribute_name, type, options={})
10
- concat(simple_form_for object do |f|
11
+ concat(simple_form_for(object) do |f|
11
12
  f.attribute_name = attribute_name
12
13
  f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
13
14
  f.input_type = type
@@ -94,14 +95,14 @@ class LabelTest < ActionView::TestCase
94
95
  with_label_for @user, :created_at, :datetime
95
96
  assert_select 'label.datetime'
96
97
  end
97
-
98
+
98
99
  test 'label should obtain required from ActiveModel::Validations when it is included' do
99
100
  with_label_for @validating_user, :name, :string
100
101
  assert_select 'label.required'
101
102
  with_label_for @validating_user, :status, :string
102
103
  assert_select 'label.optional'
103
104
  end
104
-
105
+
105
106
  test 'label should allow overriding required when ActiveModel::Validations is included' do
106
107
  with_label_for @validating_user, :name, :string, :required => false
107
108
  assert_select 'label.optional'
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class WrapperTest < ActionView::TestCase
4
+ def with_error_for(object, attribute_name, options={}, &block)
5
+ concat(simple_form_for(object) do |f|
6
+ f.options = options
7
+ f.input attribute_name
8
+ end)
9
+ end
10
+
11
+ def with_form_for(object, *args, &block)
12
+ concat(simple_form_for(object) do |f|
13
+ concat f.input(*args, &block)
14
+ end)
15
+ end
16
+
17
+ test 'wrapper should not have error class for attribute without errors' do
18
+ with_error_for @user, :active
19
+ assert_no_select 'div.field_with_errors'
20
+ end
21
+
22
+ test 'wrapper should not have error class when object is not present' do
23
+ with_error_for :project, :name
24
+ assert_no_select 'div.field_with_errors'
25
+ end
26
+
27
+ test 'wrapper should add error class for attribute with errors' do
28
+ with_error_for @user, :name
29
+ assert_select 'div.field_with_errors'
30
+ end
31
+
32
+ test 'wrapper should add chosen error class for attribute with errors' do
33
+ swap SimpleForm, :wrapper_error_class => "omgError" do
34
+ with_error_for @user, :name
35
+ assert_select 'div.omgError'
36
+ end
37
+ end
38
+
39
+ test 'wrapper should add chosen wrapper class' do
40
+ swap SimpleForm, :wrapper_class => "wrapper" do
41
+ with_form_for @user, :active
42
+ assert_select 'div.wrapper'
43
+ assert_no_select 'div.input'
44
+
45
+ with_form_for @user, :name
46
+ assert_select 'div.wrapper'
47
+ assert_no_select 'div.input'
48
+
49
+ with_form_for :project, :name
50
+ assert_select 'div.wrapper'
51
+ assert_no_select 'div.input'
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class ErrorNotificationTest < ActionView::TestCase
4
+
5
+ def with_error_notification_for(object, options={}, &block)
6
+ concat(simple_form_for(object) do |f|
7
+ concat(f.error_notification(options))
8
+ end)
9
+ end
10
+
11
+ test 'error notification is not generated when the object has no error' do
12
+ assert @validating_user.valid?
13
+ with_error_notification_for @validating_user
14
+ assert_no_select 'p.error_notification'
15
+ end
16
+
17
+ test 'error notification is not generated for forms without objects' do
18
+ with_error_notification_for :user
19
+ assert_no_select 'p.error_notification'
20
+ end
21
+
22
+ test 'error notification is generated when the object has some error' do
23
+ with_error_notification_for @user
24
+ assert_select 'p.error_notification', 'Some errors were found, please take a look:'
25
+ end
26
+
27
+ test 'error notification uses I18n based on model to generate the notification message' do
28
+ store_translations(:en, :simple_form => { :error_notification => { :user =>
29
+ 'Alguns erros foram encontrados para o usuário:'
30
+ } }) do
31
+ with_error_notification_for @user
32
+ assert_select 'p.error_notification', 'Alguns erros foram encontrados para o usuário:'
33
+ end
34
+ end
35
+
36
+ test 'error notification uses I18n fallbacking to default message' do
37
+ store_translations(:en, :simple_form => { :error_notification => {
38
+ :default_message => 'Opa! Alguns erros foram encontrados, poderia verificar?'
39
+ } }) do
40
+ with_error_notification_for @user
41
+ assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
42
+ end
43
+ end
44
+
45
+ test 'error notification allows passing the notification message' do
46
+ with_error_notification_for @user, :message => 'Erro encontrado ao criar usuario'
47
+ assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
48
+ end
49
+
50
+ test 'error notification accepts other html options' do
51
+ with_error_notification_for @user, :id => 'user_error_message', :class => 'form_error'
52
+ assert_select 'p#user_error_message.form_error.error_notification'
53
+ end
54
+
55
+ test 'error notification allows configuring the wrapper element' do
56
+ swap SimpleForm, :error_notification_tag => :div do
57
+ with_error_notification_for @user
58
+ assert_select 'div.error_notification'
59
+ end
60
+ end
61
+ end
@@ -1,39 +1,40 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
 
3
4
  class FormBuilderTest < ActionView::TestCase
4
5
 
5
6
  def with_form_for(object, *args, &block)
6
- concat(simple_form_for object do |f|
7
+ concat(simple_form_for(object) do |f|
7
8
  concat f.input(*args, &block)
8
9
  end)
9
10
  end
10
11
 
11
12
  def with_button_for(object, *args)
12
- concat(simple_form_for object do |f|
13
+ concat(simple_form_for(object) do |f|
13
14
  concat f.button(*args)
14
15
  end)
15
16
  end
16
17
 
17
18
  def with_error_for(object, *args)
18
- concat(simple_form_for object do |f|
19
+ concat(simple_form_for(object) do |f|
19
20
  concat f.error(*args)
20
21
  end)
21
22
  end
22
23
 
23
24
  def with_hint_for(object, *args)
24
- concat(simple_form_for object do |f|
25
+ concat(simple_form_for(object) do |f|
25
26
  concat f.hint(*args)
26
27
  end)
27
28
  end
28
29
 
29
30
  def with_label_for(object, *args)
30
- concat(simple_form_for object do |f|
31
+ concat(simple_form_for(object) do |f|
31
32
  concat f.label(*args)
32
33
  end)
33
34
  end
34
35
 
35
36
  def with_association_for(object, *args)
36
- concat(simple_form_for object do |f|
37
+ concat(simple_form_for(object) do |f|
37
38
  concat f.association(*args)
38
39
  end)
39
40
  end
@@ -229,26 +230,33 @@ class FormBuilderTest < ActionView::TestCase
229
230
  assert_select 'span.error#cool', "can't be blank"
230
231
  end
231
232
 
232
- # REQUIRED AND PRESENCE VALIDATION
233
+ # REQUIRED AND PRESENCE VALIDATION
233
234
  test 'builder input should obtain required from ActiveModel::Validations when it is included' do
234
235
  with_form_for @validating_user, :name
235
236
  assert_select 'input.required#validating_user_name'
236
237
  with_form_for @validating_user, :status
237
238
  assert_select 'input.optional#validating_user_status'
238
239
  end
239
-
240
+
240
241
  test 'builder input should allow overriding required when ActiveModel::Validations is included' do
241
242
  with_form_for @validating_user, :name, :required => false
242
243
  assert_select 'input.optional#validating_user_name'
243
244
  with_form_for @validating_user, :status, :required => true
244
245
  assert_select 'input.required#validating_user_status'
245
246
  end
246
-
247
+
247
248
  test 'builder input should be required by default when ActiveModel::Validations is not included' do
248
249
  with_form_for @user, :name
249
250
  assert_select 'input.required#user_name'
250
251
  end
251
-
252
+
253
+ test 'builder input should not be required by default when ActiveModel::Validations is not included if option is set to false' do
254
+ swap SimpleForm, :required_by_default => false do
255
+ with_form_for @user, :name
256
+ assert_select 'input.optional#user_name'
257
+ end
258
+ end
259
+
252
260
  test 'builder input should allow disabling required when ActiveModel::Validations is not included' do
253
261
  with_form_for @user, :name, :required => false
254
262
  assert_no_select 'input.required'
@@ -282,12 +290,24 @@ class FormBuilderTest < ActionView::TestCase
282
290
  end
283
291
 
284
292
  test 'builder allows wrapper tag to be given on demand' do
285
- concat(simple_form_for @user do |f|
293
+ concat(simple_form_for(@user) do |f|
286
294
  concat f.input :name, :wrapper_tag => :b
287
295
  end)
288
296
  assert_select 'form b.required.string'
289
297
  end
290
298
 
299
+ test 'builder allows wrapper class to be given on demand' do
300
+ concat(simple_form_for(@user) do |f|
301
+ concat f.input :name, :wrapper_class => :wrapper
302
+ end)
303
+ assert_select 'form div.wrapper.required.string'
304
+ end
305
+
306
+ test 'builder wrapping tag adds errors class for attribute with errors' do
307
+ with_form_for @user, :name
308
+ assert_select 'form div.input.required.string.field_with_errors'
309
+ end
310
+
291
311
  # WITHOUT OBJECT
292
312
  test 'builder should generate properly when object is not present' do
293
313
  with_form_for :project, :name
data/test/inputs_test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
 
3
4
  class InputTest < ActionView::TestCase
@@ -5,13 +6,13 @@ class InputTest < ActionView::TestCase
5
6
  setup do
6
7
  SimpleForm::Inputs::CollectionInput.reset_i18n_cache :boolean_collection
7
8
  end
8
-
9
+
9
10
  def with_input_for(object, attribute_name, type, options={})
10
- concat(simple_form_for object do |f|
11
+ concat(simple_form_for(object) do |f|
11
12
  concat f.input(attribute_name, options.merge(:as => type))
12
13
  end)
13
14
  end
14
-
15
+
15
16
  # ALL
16
17
  test 'input should generate css class based on default input type' do
17
18
  with_input_for @user, :name, :string
@@ -26,27 +27,12 @@ class InputTest < ActionView::TestCase
26
27
  assert_select 'select.datetime'
27
28
  end
28
29
 
29
- # TextFieldInput
30
+ # StringInput
30
31
  test 'input should map text field to string attribute' do
31
32
  with_input_for @user, :name, :string
32
33
  assert_select 'input[name=\'user[name]\'][id=user_name][value=New in Simple Form!][type=text]'
33
34
  end
34
35
 
35
- test 'input should generate an integer text field for integer attributes ' do
36
- with_input_for @user, :age, :integer
37
- assert_select 'input[type=text].integer#user_age'
38
- end
39
-
40
- test 'input should generate a float text field for float attributes ' do
41
- with_input_for @user, :age, :float
42
- assert_select 'input[type=text].float#user_age'
43
- end
44
-
45
- test 'input should generate a decimal text field for decimal attributes ' do
46
- with_input_for @user, :age, :decimal
47
- assert_select 'input[type=text].decimal#user_age'
48
- end
49
-
50
36
  test 'input should use default text size for decimal attributes' do
51
37
  with_input_for @user, :credit_limit, :decimal
52
38
  assert_select 'input.decimal[size=50]'
@@ -62,17 +48,35 @@ class InputTest < ActionView::TestCase
62
48
  assert_select 'input.string[size=50]'
63
49
  end
64
50
 
65
- # MappingInput
66
- test 'input should generate a text area for text attributes' do
67
- with_input_for @user, :description, :text
68
- assert_select 'textarea.text#user_description'
51
+ # NumericInput
52
+ test 'input should generate an integer text field for integer attributes ' do
53
+ with_input_for @user, :age, :integer
54
+ assert_select 'input[type=number].integer#user_age'
55
+ end
56
+
57
+ test 'input should generate a float text field for float attributes ' do
58
+ with_input_for @user, :age, :float
59
+ assert_select 'input[type=number].float#user_age'
69
60
  end
70
61
 
62
+ test 'input should generate a decimal text field for decimal attributes ' do
63
+ with_input_for @user, :age, :decimal
64
+ assert_select 'input[type=number].decimal#user_age'
65
+ end
66
+
67
+ # BooleanInput
71
68
  test 'input should generate a checkbox by default for boolean attributes' do
72
69
  with_input_for @user, :active, :boolean
73
70
  assert_select 'input[type=checkbox].boolean#user_active'
71
+ assert_select 'input.boolean + label.boolean.optional'
72
+ end
73
+
74
+ # MappingInput
75
+ test 'input should generate a text area for text attributes' do
76
+ with_input_for @user, :description, :text
77
+ assert_select 'textarea.text#user_description'
74
78
  end
75
-
79
+
76
80
  test 'input should generate a password field for password attributes' do
77
81
  with_input_for @user, :password, :password
78
82
  assert_select 'input[type=password].password#user_password'
@@ -107,7 +111,7 @@ class InputTest < ActionView::TestCase
107
111
  assert_select 'select option[value=Brazil]', 'Brazil'
108
112
  assert_no_select 'select option[value=][disabled=disabled]'
109
113
  end
110
-
114
+
111
115
  test 'input should generate a country select with simple form default' do
112
116
  swap SimpleForm, :country_priority => [ 'Brazil' ] do
113
117
  with_input_for @user, :country, :country
@@ -141,17 +145,17 @@ class InputTest < ActionView::TestCase
141
145
  assert_select "form select.datetime#user_created_at_#{i}i"
142
146
  end
143
147
  end
144
-
148
+
145
149
  test 'input should be able to pass options to datetime select' do
146
150
  with_input_for @user, :created_at, :datetime,
147
151
  :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
148
-
152
+
149
153
  assert_select 'select.datetime[disabled=disabled]'
150
154
  assert_select 'select.datetime option', 'ano'
151
155
  assert_select 'select.datetime option', 'mês'
152
156
  assert_select 'select.datetime option', 'dia'
153
157
  end
154
-
158
+
155
159
  test 'input should generate a date select for date attributes' do
156
160
  with_input_for @user, :born_at, :date
157
161
  assert_select 'select.date#user_born_at_1i'
@@ -159,11 +163,11 @@ class InputTest < ActionView::TestCase
159
163
  assert_select 'select.date#user_born_at_3i'
160
164
  assert_no_select 'select.date#user_born_at_4i'
161
165
  end
162
-
166
+
163
167
  test 'input should be able to pass options to date select' do
164
168
  with_input_for @user, :born_at, :date, :as => :date,
165
169
  :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' }
166
-
170
+
167
171
  assert_select 'select.date[disabled=disabled]'
168
172
  assert_select 'select.date option', 'ano'
169
173
  assert_select 'select.date option', 'mês'
@@ -183,11 +187,11 @@ class InputTest < ActionView::TestCase
183
187
  assert_select 'select.time#user_delivery_time_4i'
184
188
  assert_select 'select.time#user_delivery_time_5i'
185
189
  end
186
-
190
+
187
191
  test 'input should be able to pass options to time select' do
188
192
  with_input_for @user, :delivery_time, :time, :required => true,
189
193
  :disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' }
190
-
194
+
191
195
  assert_select 'select.time[disabled=disabled]'
192
196
  assert_select 'select.time option', 'hora'
193
197
  assert_select 'select.time option', 'minuto'
@@ -214,13 +218,13 @@ class InputTest < ActionView::TestCase
214
218
  assert_select 'input[type=radio][value=true].radio#user_active_true'
215
219
  assert_select 'input[type=radio][value=false].radio#user_active_false'
216
220
  end
217
-
221
+
218
222
  test 'input as radio should generate internal labels by default' do
219
223
  with_input_for @user, :active, :radio
220
224
  assert_select 'label[for=user_active_true]', 'Yes'
221
225
  assert_select 'label[for=user_active_false]', 'No'
222
226
  end
223
-
227
+
224
228
  test 'input as radio should use i18n to translate internal labels' do
225
229
  store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
226
230
  with_input_for @user, :active, :radio
@@ -228,14 +232,14 @@ class InputTest < ActionView::TestCase
228
232
  assert_select 'label[for=user_active_false]', 'Não'
229
233
  end
230
234
  end
231
-
235
+
232
236
  test 'input should generate a boolean select with options by default for select types' do
233
237
  with_input_for @user, :active, :select
234
238
  assert_select 'select.select#user_active'
235
239
  assert_select 'select option[value=true]', 'Yes'
236
240
  assert_select 'select option[value=false]', 'No'
237
241
  end
238
-
242
+
239
243
  test 'input as select should use i18n to translate select boolean options' do
240
244
  store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do
241
245
  with_input_for @user, :active, :select
@@ -243,53 +247,53 @@ class InputTest < ActionView::TestCase
243
247
  assert_select 'select option[value=false]', 'Não'
244
248
  end
245
249
  end
246
-
250
+
247
251
  test 'input should allow overriding collection for select types' do
248
252
  with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
249
253
  assert_select 'select.select#user_name'
250
254
  assert_select 'select option', 'Jose'
251
255
  assert_select 'select option', 'Carlos'
252
256
  end
253
-
257
+
254
258
  test 'input should mark the selected value by default' do
255
259
  @user.name = "Carlos"
256
260
  with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos']
257
261
  assert_select 'select option[selected=selected]', 'Carlos'
258
262
  end
259
-
263
+
260
264
  test 'input should mark the selected value also when using integers' do
261
265
  @user.age = 18
262
266
  with_input_for @user, :age, :select, :collection => 18..60
263
267
  assert_select 'select option[selected=selected]', '18'
264
268
  end
265
-
269
+
266
270
  test 'input should automatically set include blank' do
267
271
  with_input_for @user, :age, :select, :collection => 18..30
268
272
  assert_select 'select option[value=]', ''
269
273
  end
270
-
274
+
271
275
  test 'input should not set include blank if otherwise is told' do
272
276
  with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false
273
277
  assert_no_select 'select option[value=]', ''
274
278
  end
275
-
279
+
276
280
  test 'input should not set include blank if prompt is given' do
277
281
  with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo"
278
282
  assert_no_select 'select option[value=]', ''
279
283
  end
280
-
284
+
281
285
  test 'input should not set include blank if multiple is given' do
282
286
  with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true }
283
287
  assert_no_select 'select option[value=]', ''
284
288
  end
285
-
289
+
286
290
  test 'input should detect label and value on collections' do
287
291
  users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ]
288
292
  with_input_for @user, :description, :select, :collection => users
289
293
  assert_select 'select option[value=1]', 'Jose'
290
294
  assert_select 'select option[value=2]', 'Carlos'
291
295
  end
292
-
296
+
293
297
  test 'input should allow overriding collection for radio types' do
294
298
  with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
295
299
  assert_select 'input[type=radio][value=Jose]'
@@ -297,13 +301,13 @@ class InputTest < ActionView::TestCase
297
301
  assert_select 'label.collection_radio', 'Jose'
298
302
  assert_select 'label.collection_radio', 'Carlos'
299
303
  end
300
-
304
+
301
305
  test 'input should mark the current radio value by default' do
302
306
  @user.name = "Carlos"
303
307
  with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
304
308
  assert_select 'input[type=radio][value=Carlos][checked=checked]'
305
309
  end
306
-
310
+
307
311
  test 'input should allow using a collection with text/value arrays' do
308
312
  with_input_for @user, :name, :radio, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']]
309
313
  assert_select 'input[type=radio][value=jose]'
@@ -311,7 +315,7 @@ class InputTest < ActionView::TestCase
311
315
  assert_select 'label.collection_radio', 'Jose'
312
316
  assert_select 'label.collection_radio', 'Carlos'
313
317
  end
314
-
318
+
315
319
  test 'input should allow overriding label and value method for collections' do
316
320
  with_input_for @user, :name, :radio,
317
321
  :collection => ['Jose' , 'Carlos'],
@@ -322,19 +326,19 @@ class InputTest < ActionView::TestCase
322
326
  assert_select 'label.collection_radio', 'JOSE'
323
327
  assert_select 'label.collection_radio', 'CARLOS'
324
328
  end
325
-
329
+
326
330
  # With no object
327
331
  test 'input should be generated properly when object is not present' do
328
332
  with_input_for :project, :name, :string
329
333
  assert_select 'input.string.required#project_name'
330
334
  end
331
-
335
+
332
336
  test 'input as radio should be generated properly when object is not present ' do
333
337
  with_input_for :project, :name, :radio
334
338
  assert_select 'input.radio#project_name_true'
335
339
  assert_select 'input.radio#project_name_false'
336
340
  end
337
-
341
+
338
342
  test 'input as select with collection should be generated properly when object is not present' do
339
343
  with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
340
344
  assert_select 'select.select#project_name'