manatee 0.0.1.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.mdown +55 -0
  5. data/Rakefile +7 -0
  6. data/app/assets/javascripts/manatee.js +1 -0
  7. data/app/assets/javascripts/manatee/helpers.js +4 -0
  8. data/app/assets/javascripts/manatee/helpers/asset_tag.jsh.coffee +138 -0
  9. data/app/assets/javascripts/manatee/helpers/asset_url.jsh.coffee +90 -0
  10. data/app/assets/javascripts/manatee/helpers/csrf.jsh.coffee +5 -0
  11. data/app/assets/javascripts/manatee/helpers/date.jsh.coffee +54 -0
  12. data/app/assets/javascripts/manatee/helpers/debug.jsh.coffee +2 -0
  13. data/app/assets/javascripts/manatee/helpers/form.jsh.coffee +25 -0
  14. data/app/assets/javascripts/manatee/helpers/form_builder.jsh.coffee +24 -0
  15. data/app/assets/javascripts/manatee/helpers/form_options.jsh.coffee +267 -0
  16. data/app/assets/javascripts/manatee/helpers/form_tag.jsh.coffee +204 -0
  17. data/app/assets/javascripts/manatee/helpers/javascript.jsh.coffee +15 -0
  18. data/app/assets/javascripts/manatee/helpers/number.jsh.coffee +58 -0
  19. data/app/assets/javascripts/manatee/helpers/sanitize.jsh.coffee +5 -0
  20. data/app/assets/javascripts/manatee/helpers/tag.jsh.coffee +58 -0
  21. data/app/assets/javascripts/manatee/helpers/text.jsh.coffee +12 -0
  22. data/app/assets/javascripts/manatee/helpers/translation.jsh.coffee +7 -0
  23. data/app/assets/javascripts/manatee/helpers/url.jsh.coffee +36 -0
  24. data/app/assets/javascripts/manatee/helpers/util.jsh.coffee +41 -0
  25. data/app/assets/javascripts/manatee/rails_helpers.js +2 -0
  26. data/app/assets/javascripts/manatee/rails_helpers/routes.js.erb +195 -0
  27. data/app/assets/javascripts/manatee/rails_routes.js +1 -0
  28. data/app/assets/javascripts/manatee/renderer.js.erb +53 -0
  29. data/app/assets/javascripts/manatee_railsless.js +1 -0
  30. data/lib/manatee.rb +87 -0
  31. data/lib/manatee/config.rb +51 -0
  32. data/lib/manatee/handler.rb +45 -0
  33. data/lib/manatee/rails.rb +6 -0
  34. data/lib/manatee/rails/extensions.rb +23 -0
  35. data/lib/manatee/rails/handler.rb +16 -0
  36. data/lib/manatee/rails/hash_visitor.rb +35 -0
  37. data/lib/manatee/rails/helper.rb +9 -0
  38. data/lib/manatee/rails/resolver.rb +70 -0
  39. data/lib/manatee/rails/routes_compiler.rb +34 -0
  40. data/lib/manatee/sprockets.rb +8 -0
  41. data/lib/manatee/sprockets/jsh_processor_2x.rb +32 -0
  42. data/lib/manatee/sprockets/jsh_processor_3x.rb +31 -0
  43. data/lib/manatee/version.rb +3 -0
  44. data/manatee.gemspec +32 -0
  45. data/test/example/renderer.js.erb +8 -0
  46. data/test/example/translations.en.yml +410 -0
  47. data/test/example/views/index.jst.eco +12 -0
  48. data/test/helpers/asset_tag_test.rb +175 -0
  49. data/test/helpers/asset_url_test.rb +349 -0
  50. data/test/helpers/form_options_test.rb +718 -0
  51. data/test/helpers/form_tag_test.rb +387 -0
  52. data/test/helpers/javascript_test.rb +39 -0
  53. data/test/helpers/number_test.rb +111 -0
  54. data/test/helpers/tag_test.rb +71 -0
  55. data/test/support/dom_assertion.rb +49 -0
  56. data/test/support/view_test.rb +91 -0
  57. data/test/test_helper.rb +17 -0
  58. metadata +213 -0
@@ -0,0 +1,718 @@
1
+ require_relative '../test_helper'
2
+
3
+ class FormOptionsTest < Manatee::ViewTest
4
+
5
+ Post = Struct.new 'Post', :title, :author_name, :body, :secret, :written_on, :category, :origin, :allow_comments
6
+ Album = Struct.new 'Album', :id, :title, :genre
7
+ Country = Struct.new 'Country', :country_id, :country_name
8
+ Continent = Struct.new 'Continent', :continent_name, :countries
9
+
10
+ [ Post, Album, Country, Continent ].each do |klass|
11
+ klass.send :define_method, :to_json do |*args|
12
+ hash = Hash[ self.class.members.map{ |key| [key, public_send(key)] } ]
13
+ hash['_class'] = self.class.name.match('::').post_match
14
+ hash.to_json
15
+ end
16
+
17
+ klass.send :define_method, :[] do |key|
18
+ begin
19
+ super key
20
+ rescue NameError
21
+ key == 'class' ? self.class.name.match('::').post_match : nil
22
+ end
23
+ end
24
+ end
25
+
26
+ def setup
27
+ config_renderer do |config|
28
+ config.fonts_path = '/fonts'
29
+ config.audios_path = '/audios'
30
+ config.videos_path = '/videos'
31
+ config.images_path = '/images'
32
+ config.javascript_path = ''
33
+ config.stylesheet_path = ''
34
+ end
35
+ end
36
+
37
+ def test_string_options_for_select
38
+ options = '<option value="Denmark">Denmark</option><option value="USA">USA</option><option value="Sweden">Sweden</option>'
39
+ assert_dom_helper options, :optionsForSelect, options
40
+ end
41
+
42
+ def test_array_options_for_select
43
+ expected = '<option value="&lt;Denmark&gt;">&lt;Denmark&gt;</option><option value="USA">USA</option><option value="Sweden">Sweden</option>'
44
+ assert_dom_helper expected, :optionsForSelect, [ '<Denmark>', 'USA', 'Sweden' ]
45
+ end
46
+
47
+ def test_array_options_for_select_with_custom_defined_selected
48
+ options = [
49
+ ['Richard Bandler', 1, { type: 'Coach', selected: 'selected' } ],
50
+ ['Richard Bandler', 1, { type: 'Coachee' } ]
51
+ ]
52
+ expected = '<option selected="selected" type="Coach" value="1">Richard Bandler</option><option type="Coachee" value="1">Richard Bandler</option>'
53
+ assert_dom_helper expected, :optionsForSelect, options
54
+
55
+ options = [
56
+ ['Richard Bandler', 1, { type: 'Coach', selected: true } ],
57
+ ['Richard Bandler', 1, { type: 'Coachee' } ]
58
+ ]
59
+ assert_dom_helper expected, :optionsForSelect, options
60
+ end
61
+
62
+ def test_array_options_for_select_with_custom_defined_disabled
63
+ options = [
64
+ ['Richard Bandler', 1, { type: 'Coach', disabled: 'disabled' } ],
65
+ ['Richard Bandler', 1, { type: 'Coachee' } ]
66
+ ]
67
+ expected = '<option disabled="disabled" type="Coach" value="1">Richard Bandler</option><option type="Coachee" value="1">Richard Bandler</option>'
68
+ assert_dom_helper expected, :optionsForSelect, options
69
+
70
+ options = [
71
+ ['Richard Bandler', 1, { type: 'Coach', disabled: true } ],
72
+ ['Richard Bandler', 1, { type: 'Coachee' } ]
73
+ ]
74
+ assert_dom_helper expected, :optionsForSelect, options
75
+ end
76
+
77
+ def test_array_options_for_select_with_selection
78
+ expected = '<option value="Denmark">Denmark</option><option value="&lt;USA&gt;" selected="selected">&lt;USA&gt;</option><option value="Sweden">Sweden</option>'
79
+ assert_dom_helper expected, :optionsForSelect, [ 'Denmark', '<USA>', 'Sweden' ], '<USA>'
80
+ end
81
+
82
+ def test_array_options_for_select_with_selection_array
83
+ expected = '<option value="Denmark">Denmark</option><option value="&lt;USA&gt;" selected="selected">&lt;USA&gt;</option><option value="Sweden" selected="selected">Sweden</option>'
84
+ assert_dom_helper expected, :optionsForSelect, ['Denmark', '<USA>', 'Sweden'], ['<USA>', 'Sweden']
85
+ end
86
+
87
+ def test_array_options_for_select_with_disabled_value
88
+ expected = '<option value="Denmark">Denmark</option><option value="&lt;USA&gt;" disabled="disabled">&lt;USA&gt;</option><option value="Sweden">Sweden</option>'
89
+ assert_dom_helper expected, :optionsForSelect, [ 'Denmark', '<USA>', 'Sweden' ], disabled: '<USA>'
90
+ end
91
+
92
+ def test_array_options_for_select_with_disabled_array
93
+ expected = '<option value="Denmark">Denmark</option><option value="&lt;USA&gt;" disabled="disabled">&lt;USA&gt;</option><option value="Sweden" disabled="disabled">Sweden</option>'
94
+ assert_dom_helper expected, :optionsForSelect, [ 'Denmark', '<USA>', 'Sweden' ], disabled: ['<USA>', 'Sweden']
95
+ end
96
+
97
+ def test_array_options_for_select_with_selection_and_disabled_value
98
+ expected = '<option value="Denmark" selected="selected">Denmark</option><option value="&lt;USA&gt;" disabled="disabled">&lt;USA&gt;</option><option value="Sweden">Sweden</option>'
99
+ assert_dom_helper expected, :optionsForSelect, [ 'Denmark', '<USA>', 'Sweden' ], selected: 'Denmark', disabled: '<USA>'
100
+ end
101
+
102
+ def test_boolean_array_options_for_select_with_selection_and_disabled_value
103
+ expected = '<option value="true">true</option><option value="false" selected="selected">false</option>'
104
+ assert_dom_helper expected, :optionsForSelect, [ true, false ], selected: false, disabled: nil
105
+ end
106
+
107
+ # # TODO: I didn't found a nice way to support ranges on optionsForSelect helper
108
+ # def test_range_options_for_select
109
+ # expected = '<option value="1">1</option><option value="2">2</option><option value="3">3</option>'
110
+ # assert_dom_helper expected, :optionsForSelect, 1..3
111
+ # end
112
+
113
+ def test_array_options_for_string_include_in_other_string_bug_fix
114
+ expected = '<option value="ruby">ruby</option><option value="rubyonrails" selected="selected">rubyonrails</option>'
115
+ assert_dom_helper expected, :optionsForSelect, [ 'ruby', 'rubyonrails' ], 'rubyonrails'
116
+
117
+ expected = '<option value="ruby" selected="selected">ruby</option><option value="rubyonrails">rubyonrails</option>'
118
+ assert_dom_helper expected, :optionsForSelect, [ 'ruby', 'rubyonrails' ], 'ruby'
119
+
120
+ expected = '<option value="ruby" selected="selected">ruby</option><option value="rubyonrails">rubyonrails</option><option value=""></option>'
121
+ assert_dom_helper expected, :optionsForSelect, [ 'ruby', 'rubyonrails', nil ], 'ruby'
122
+ end
123
+
124
+ def test_hash_options_for_select_should_behave_like_array_options
125
+ expected = '<option value="Dollar">$</option><option value="&lt;Kroner&gt;">&lt;DKR&gt;</option>'
126
+ assert_dom_helper expected, :optionsForSelect, [ ['$', 'Dollar'], ['<DKR>', '<Kroner>'] ]
127
+ assert_dom_helper expected, :optionsForSelect, '$' => 'Dollar', '<DKR>' => '<Kroner>'
128
+
129
+ expected = '<option value="Dollar" selected="selected">$</option><option value="&lt;Kroner&gt;">&lt;DKR&gt;</option>'
130
+ assert_dom_helper expected, :optionsForSelect, [ ['$', 'Dollar'], ['<DKR>', '<Kroner>'] ], 'Dollar'
131
+ assert_dom_helper expected, :optionsForSelect, { '$' => 'Dollar', '<DKR>' => '<Kroner>' }, 'Dollar'
132
+
133
+ expected = '<option value="Dollar" selected="selected">$</option><option value="&lt;Kroner&gt;" selected="selected">&lt;DKR&gt;</option>'
134
+ assert_dom_helper expected, :optionsForSelect, [ ['$', 'Dollar'], ['<DKR>', '<Kroner>'] ], [ 'Dollar', '<Kroner>' ]
135
+ assert_dom_helper expected, :optionsForSelect, { '$' => 'Dollar', '<DKR>' => '<Kroner>' }, [ 'Dollar', '<Kroner>' ]
136
+ end
137
+
138
+ # # TODO: Think about "ducktyped" params on optionsForSelect helper
139
+ # # Code commented below is a snipped extracted from actionview source code,
140
+ # # it needs to be modified before any attempt of running it
141
+ # def test_ducktyped_options_for_select
142
+ # quack = Struct.new(:first, :last)
143
+ # assert_dom_equal(
144
+ # "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option><option value=\"Dollar\">$</option>",
145
+ # options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")])
146
+ # )
147
+ # assert_dom_equal(
148
+ # "<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option><option value=\"Dollar\" selected=\"selected\">$</option>",
149
+ # options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], "Dollar")
150
+ # )
151
+ # assert_dom_equal(
152
+ # "<option value=\"&lt;Kroner&gt;\" selected=\"selected\">&lt;DKR&gt;</option><option value=\"Dollar\" selected=\"selected\">$</option>",
153
+ # options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], ["Dollar", "<Kroner>"])
154
+ # )
155
+ # end
156
+
157
+ def test_options_for_select_with_element_attributes
158
+ expected = '<option value="&lt;Denmark&gt;" class="bold">&lt;Denmark&gt;</option><option value="USA" onclick="alert(&#39;Hello World&#39;);">USA</option><option value="Sweden">Sweden</option><option value="Germany">Germany</option>'
159
+ assert_dom_helper expected, :optionsForSelect, [ [ '<Denmark>', { class: 'bold' } ], [ 'USA', { onclick: "alert('Hello World');" } ], [ 'Sweden' ], 'Germany' ]
160
+ end
161
+
162
+ def test_options_for_select_with_data_element
163
+ expected = '<option value="&lt;Denmark&gt;" data-test="bold">&lt;Denmark&gt;</option>'
164
+ assert_dom_helper expected, :optionsForSelect, [ [ "<Denmark>", { data: { test: 'bold' } } ] ]
165
+ end
166
+
167
+ def test_options_for_select_with_data_element_with_special_characters
168
+ expected = '<option value="&lt;Denmark&gt;" data-test="&lt;bold&gt;">&lt;Denmark&gt;</option>'
169
+ assert_dom_helper expected, :optionsForSelect, [ [ "<Denmark>", { data: { test: '<bold>' } } ] ]
170
+ end
171
+
172
+ def test_options_for_select_with_element_attributes_and_selection
173
+ expected = '<option value="&lt;Denmark&gt;">&lt;Denmark&gt;</option><option value="USA" class="bold" selected="selected">USA</option><option value="Sweden">Sweden</option>'
174
+ assert_dom_helper expected, :optionsForSelect, [ '<Denmark>', [ 'USA', { class: 'bold' } ], 'Sweden' ], 'USA'
175
+ end
176
+
177
+ def test_options_for_select_with_element_attributes_and_selection_array
178
+ expected = '<option value="&lt;Denmark&gt;">&lt;Denmark&gt;</option><option value="USA" class="bold" selected="selected">USA</option><option value="Sweden" selected="selected">Sweden</option>'
179
+ assert_dom_helper expected, :optionsForSelect, [ '<Denmark>', [ 'USA', { class: 'bold' } ], 'Sweden' ], [ 'USA', 'Sweden' ]
180
+ end
181
+
182
+ def test_options_for_select_with_special_characters
183
+ expected = '<option value="&lt;Denmark&gt;" onclick="alert(&quot;&lt;code&gt;&quot;)">&lt;Denmark&gt;</option>'
184
+ assert_dom_helper expected, :optionsForSelect, [ [ '<Denmark>', { onclick: %(alert("<code>")) } ] ]
185
+ end
186
+
187
+ def test_collection_options
188
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe">Babe went home</option><option value="Cabe">Cabe went home</option>'
189
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title'
190
+ end
191
+
192
+ def test_collection_options_with_preselected_value
193
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" selected="selected">Babe went home</option><option value="Cabe">Cabe went home</option>'
194
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', 'Babe'
195
+ end
196
+
197
+ def test_collection_options_with_preselected_value_array
198
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" selected="selected">Babe went home</option><option value="Cabe" selected="selected">Cabe went home</option>'
199
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', [ 'Babe', 'Cabe' ]
200
+ end
201
+
202
+ def test_collection_options_with_proc_for_selected
203
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" selected="selected">Babe went home</option><option value="Cabe">Cabe went home</option>'
204
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', lambda{ |jr, post| post.author_name == 'Babe' }
205
+ assert_dom_js_helper expected, :optionsFromCollectionForSelect, %( #{ dummy_posts.to_json }, 'author_name', 'title', function(post){ return post.author_name == 'Babe'; } )
206
+ end
207
+
208
+ def test_collection_options_with_disabled_value
209
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" disabled="disabled">Babe went home</option><option value="Cabe">Cabe went home</option>'
210
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', disabled: 'Babe'
211
+ end
212
+
213
+ def test_collection_options_with_disabled_array
214
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" disabled="disabled">Babe went home</option><option value="Cabe" disabled="disabled">Cabe went home</option>'
215
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', disabled: [ 'Babe', 'Cabe' ]
216
+ end
217
+
218
+ def test_collection_options_with_preselected_and_disabled_value
219
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" disabled="disabled">Babe went home</option><option value="Cabe" selected="selected">Cabe went home</option>'
220
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', selected: 'Cabe', disabled: 'Babe'
221
+ end
222
+
223
+ def test_collection_options_with_proc_for_disabled
224
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe" disabled="disabled">Babe went home</option><option value="Cabe" disabled="disabled">Cabe went home</option>'
225
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', 'title', disabled: lambda { |jr, post| %w(Babe Cabe).include? post.author_name }
226
+ assert_dom_js_helper expected, :optionsFromCollectionForSelect, %( #{ dummy_posts.to_json }, 'author_name', 'title', { disabled: function(post){ return ['Babe', 'Cabe'].indexOf(post.author_name) > -1; } } )
227
+ end
228
+
229
+ def test_collection_options_with_proc_for_value_method
230
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe">Babe went home</option><option value="Cabe">Cabe went home</option>'
231
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, lambda{ |jr, post| post.author_name }, 'title'
232
+ assert_dom_js_helper expected, :optionsFromCollectionForSelect, %( #{ dummy_posts.to_json }, function(post){ return post.author_name; }, 'title' )
233
+ end
234
+
235
+ def test_collection_options_with_proc_for_text_method
236
+ expected = '<option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe">Babe went home</option><option value="Cabe">Cabe went home</option>'
237
+ assert_dom_helper expected, :optionsFromCollectionForSelect, dummy_posts, 'author_name', lambda { |jr, post| post.title }
238
+ assert_dom_js_helper expected, :optionsFromCollectionForSelect, %( #{ dummy_posts.to_json }, 'author_name', function(post){ return post.title; } )
239
+ end
240
+
241
+ def test_collection_options_with_element_attributes
242
+ expected = '<option value="USA" class="bold">USA</option>'
243
+ assert_dom_helper expected, :optionsFromCollectionForSelect, [ [ 'USA', 'USA', { class: 'bold' } ] ], 0, 1
244
+ end
245
+
246
+ def test_collection_options_with_preselected_value_as_string_and_option_value_is_integer
247
+ albums = [ Album.new(1, 'first', 'rap'), Album.new(2, 'second', 'pop') ]
248
+ expected = %(<option selected="selected" value="1">rap</option><option value="2">pop</option>)
249
+ assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', selected: '1'
250
+ end
251
+
252
+ def test_collection_options_with_preselected_value_as_integer_and_option_value_is_string
253
+ albums = [ Album.new('1', 'first', 'rap'), Album.new('2', 'second', 'pop') ]
254
+ expected = %(<option selected="selected" value="1">rap</option><option value="2">pop</option>)
255
+ assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', selected: 1
256
+ end
257
+
258
+ # # TODO: It seems to be impossible to handle "integer floats" on Javascript on optionsFromCollectionForSelect
259
+ # Those tests below fails because I could not make that 100% Rails-compatible
260
+ # def test_collection_options_with_preselected_value_as_string_and_option_value_is_float
261
+ # albums = [ Album.new(1.0, 'first', 'rap'), Album.new(2.0, 'second', 'pop') ]
262
+ # expected = %(<option value="1.0">rap</option><option value="2.0" selected="selected">pop</option>)
263
+ # assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', selected: '2.0'
264
+ # end
265
+ #
266
+ # def test_collection_options_with_preselected_value_as_nil
267
+ # albums = [ Album.new(1.0, 'first', 'rap'), Album.new(2.0, 'second', 'pop') ]
268
+ # expected = %(<option value="1.0">rap</option><option value="2.0">pop</option>)
269
+ # assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', selected: nil
270
+ # end
271
+ #
272
+ # def test_collection_options_with_disabled_value_as_nil
273
+ # albums = [ Album.new(1.0, 'first', 'rap'), Album.new(2.0, 'second', 'pop') ]
274
+ # expected = %(<option value="1.0">rap</option><option value="2.0">pop</option>)
275
+ # assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', disabled: nil
276
+ # end
277
+ #
278
+ # def test_collection_options_with_disabled_value_as_array
279
+ # albums = [ Album.new(1.0, 'first', 'rap'), Album.new(2.0, 'second', 'pop') ]
280
+ # expected = %(<option value="1.0">rap</option><option value="2.0">pop</option>)
281
+ # assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', disabled: ['1.0', 2.0]
282
+ # end
283
+ #
284
+ # def test_collection_options_with_preselected_values_as_string_array_and_option_value_is_float
285
+ # albums = [ Album.new(1.0, 'first', 'rap'), Album.new(2.0, 'second', 'pop'), Album.new(3.0, 'third', 'country') ]
286
+ # expected = %(<option value="1.0" selected="selected">rap</option><option value="2.0">pop</option><option value="3.0" selected="selected">country</option>)
287
+ # assert_dom_helper expected, :optionsFromCollectionForSelect, albums, 'id', 'genre', ['1.0', '3.0']
288
+ # end
289
+
290
+ def test_grouped_options_for_select_with_array
291
+ options = [
292
+ [ 'North America',
293
+ [ [ 'United States', 'US' ], 'Canada' ]
294
+ ],
295
+ [ 'Europe',
296
+ [ [ 'Great Britain', 'GB' ], 'Germany' ]
297
+ ]
298
+ ]
299
+ expected = %(<optgroup label="North America"><option value="US">United States</option><option value="Canada">Canada</option></optgroup><optgroup label="Europe"><option value="GB">Great Britain</option><option value="Germany">Germany</option></optgroup>)
300
+ assert_dom_helper expected, :groupedOptionsForSelect, options
301
+ end
302
+
303
+ def test_grouped_options_for_select_with_array_and_html_attributes
304
+ options = [
305
+ [ 'North America',
306
+ [ [ 'United States', 'US'], 'Canada' ], data: { foo: 'bar' }
307
+ ],
308
+ [ 'Europe',
309
+ [ [ 'Great Britain', 'GB'], 'Germany' ], disabled: 'disabled'
310
+ ]
311
+ ]
312
+ expected = %(<optgroup label="North America" data-foo="bar"><option value="US">United States</option><option value="Canada">Canada</option></optgroup><optgroup label="Europe" disabled="disabled"><option value="GB">Great Britain</option><option value="Germany">Germany</option></optgroup>)
313
+ assert_dom_helper expected, :groupedOptionsForSelect, options
314
+ end
315
+
316
+ def test_grouped_options_for_select_with_optional_divider
317
+ expected = %(<optgroup label="----------"><option value="US">US</option><option value="Canada">Canada</option></optgroup><optgroup label="----------"><option value="GB">GB</option><option value="Germany">Germany</option></optgroup>)
318
+ assert_dom_helper expected, :groupedOptionsForSelect, [ [ 'US', 'Canada' ] , [ 'GB', 'Germany' ] ], nil, divider: '----------'
319
+ end
320
+
321
+ def test_grouped_options_for_select_with_selected_and_prompt
322
+ expected = %(<option value="">Choose a product...</option><optgroup label="Hats"><option value="Baseball Cap">Baseball Cap</option><option selected="selected" value="Cowboy Hat">Cowboy Hat</option></optgroup>)
323
+ assert_dom_helper expected, :groupedOptionsForSelect, [ ['Hats', [ 'Baseball Cap', 'Cowboy Hat' ] ] ], 'Cowboy Hat', prompt: 'Choose a product...'
324
+ end
325
+
326
+ def test_grouped_options_for_select_with_selected_and_prompt_true
327
+ expected = %(<option value="">Please select</option><optgroup label="Hats"><option value="Baseball Cap">Baseball Cap</option><option selected="selected" value="Cowboy Hat">Cowboy Hat</option></optgroup>)
328
+ assert_dom_helper expected, :groupedOptionsForSelect, [ ['Hats', [ 'Baseball Cap', 'Cowboy Hat' ] ] ], 'Cowboy Hat', prompt: true
329
+ end
330
+
331
+ def test_grouped_options_for_select_with_prompt_returns_html_escaped_string
332
+ expected = %(<option value="">&lt;Choose One&gt;</option><optgroup label="Hats"><option value="Baseball Cap">Baseball Cap</option><option value="Cowboy Hat">Cowboy Hat</option></optgroup>)
333
+ assert_dom_helper expected, :groupedOptionsForSelect, [ ['Hats', [ 'Baseball Cap', 'Cowboy Hat' ] ] ], nil, prompt: '<Choose One>'
334
+ end
335
+
336
+ def test_optgroups_with_with_options_with_hash
337
+ options = {
338
+ 'North America' => [ 'United States', 'Canada' ],
339
+ 'Europe' => [ 'Denmark', 'Germany' ]
340
+ }
341
+ expected = %(<optgroup label="North America"><option value="United States">United States</option><option value="Canada">Canada</option></optgroup><optgroup label="Europe"><option value="Denmark">Denmark</option><option value="Germany">Germany</option></optgroup>)
342
+ assert_dom_helper expected, :groupedOptionsForSelect, options
343
+ end
344
+
345
+ def test_option_groups_from_collection_for_select
346
+ expected = %(<optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option><option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option><option value="ie">Ireland</option></optgroup>)
347
+ assert_dom_helper expected, :optionGroupsFromCollectionForSelect, dummy_continents, 'countries', 'continent_name', 'country_id', 'country_name', 'dk'
348
+ end
349
+
350
+ def test_select
351
+ post = Post.new '<mus>'
352
+ expected = '<select id="post_title" name="post[title]"><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest">hest</option></select>'
353
+ assert_dom_helper expected, :selectForObject, post, ['post', 'title'], %w( abe <mus> hest)
354
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, ['post', 'title'], ['abe', '<mus>', 'hest'] )
355
+ assert_dom_helper expected, :selectForObject, post, 'title' , %w( abe <mus> hest)
356
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'title', ['abe', '<mus>', 'hest'] )
357
+ end
358
+
359
+ def test_select_without_multiple
360
+ post = Post.new '<mus>'
361
+ expected = '<select id="post_category" name="post[category]"></select>'
362
+ assert_dom_helper expected, :selectForObject, post, :category, '', multiple: false
363
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', '', { multiple: false } )
364
+ end
365
+
366
+
367
+ def test_select_with_grouped_collection_as_nested_array
368
+ countries_by_continent = [
369
+ [ '<Africa>', [ [ '<South Africa>', '<sa>' ], [ 'Somalia', 'so' ] ] ],
370
+ [ 'Europe', [ [ 'Denmark', 'dk' ], [ 'Ireland', 'ie' ] ] ]
371
+ ]
372
+
373
+ post = Post.new
374
+ expected = [
375
+ %(<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>),
376
+ %(<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>),
377
+ %(<option value="ie">Ireland</option></optgroup></select>)
378
+ ].join
379
+ assert_dom_helper expected, :selectForObject, post, :origin, countries_by_continent
380
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'origin', #{ countries_by_continent.to_json } )
381
+ end
382
+
383
+ def test_select_with_grouped_collection_as_hash
384
+ countries_by_continent = {
385
+ '<Africa>' => [ [ '<South Africa>', '<sa>' ], [ 'Somalia', 'so' ] ],
386
+ 'Europe' => [ [ 'Denmark', 'dk' ], [ 'Ireland', 'ie' ] ]
387
+ }
388
+
389
+ post = Post.new
390
+ expected = [
391
+ %(<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>),
392
+ %(<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>),
393
+ %(<option value="ie">Ireland</option></optgroup></select>)
394
+ ].join
395
+ assert_dom_helper expected, :selectForObject, post, :origin, countries_by_continent
396
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'origin', #{ countries_by_continent.to_json } )
397
+ end
398
+
399
+ def test_select_with_boolean_method
400
+ post = Post.new
401
+ post.allow_comments = false
402
+
403
+ expected = '<select id="post_allow_comments" name="post[allow_comments]"><option value="true">true</option><option value="false" selected="selected">false</option></select>'
404
+ assert_dom_helper expected, :selectForObject, post, :allow_comments, [ true, false ]
405
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'allow_comments', [ true, false ] )
406
+ end
407
+
408
+ def test_select_with_multiple_to_add_hidden_input
409
+ post = Post.new
410
+ expected = '<input type="hidden" name="post[category][]" value=""/><select multiple="multiple" id="post_category" name="post[category][]"></select>'
411
+ assert_dom_helper expected, :selectForObject, post, :category, '', multiple: true
412
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', '', { multiple: true } )
413
+ end
414
+
415
+ def test_select_with_multiple_and_without_hidden_input
416
+ post = Post.new
417
+ expected = '<select multiple="multiple" id="post_category" name="post[category][]"></select>'
418
+ assert_dom_helper expected, :selectForObject, post, :category, '', include_hidden: false, multiple: true
419
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', '', { include_hidden: false, multiple: true } )
420
+ end
421
+
422
+ def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
423
+ post = Post.new
424
+ expected = '<select multiple="multiple" id="post_category" name="post[category][]"></select>'
425
+ assert_dom_helper expected, :selectForObject, post, :category, '', include_hidden: false, multiple: true, name: 'post[category][]'
426
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', '', { include_hidden: false, multiple: true, name: 'post[category][]' } )
427
+ end
428
+
429
+ def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
430
+ post = Post.new
431
+ expected = '<input disabled="disabled" type="hidden" name="post[category][]" value=""/><select multiple="multiple" disabled="disabled" id="post_category" name="post[category][]"></select>'
432
+ assert_dom_helper expected, :selectForObject, post, :category, '', multiple: true, disabled: true
433
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', '', { multiple: true, disabled: true } )
434
+ end
435
+
436
+ def test_select_with_blank
437
+ post = Post.new
438
+ post.category = '<mus>'
439
+ expected = '<select id="post_category" name="post[category]"><option value=""></option><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest">hest</option></select>'
440
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], include_blank: true
441
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { include_blank: true } )
442
+ end
443
+
444
+ def test_select_with_blank_as_string
445
+ post = Post.new
446
+ post.category = '<mus>'
447
+ expected = '<select id="post_category" name="post[category]"><option value="">None</option><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest">hest</option></select>'
448
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], include_blank: 'None'
449
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { include_blank: 'None' } )
450
+ end
451
+
452
+ def test_select_with_blank_as_string_escaped
453
+ post = Post.new
454
+ post.category = '<mus>'
455
+ expected = '<select id="post_category" name="post[category]"><option value="">&lt;None&gt;</option><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest">hest</option></select>'
456
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], include_blank: '<None>'
457
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { include_blank: '<None>' } )
458
+ end
459
+
460
+ def test_select_with_default_prompt
461
+ post = Post.new
462
+ post.category = ''
463
+ expected = '<select id="post_category" name="post[category]"><option value="">Please select</option><option value="abe">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
464
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], prompt: true
465
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { prompt: true } )
466
+ end
467
+
468
+ def test_select_no_prompt_when_select_has_value
469
+ post = Post.new
470
+ post.category = '<mus>'
471
+ expected = '<select id="post_category" name="post[category]"><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest">hest</option></select>'
472
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], prompt: true
473
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { prompt: true } )
474
+ end
475
+
476
+ def test_select_with_given_prompt
477
+ post = Post.new
478
+ post.category = ''
479
+ expected = '<select id="post_category" name="post[category]"><option value="">The prompt</option><option value="abe">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
480
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], prompt: 'The prompt'
481
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { prompt: 'The prompt' } )
482
+ end
483
+
484
+ def test_select_with_given_prompt_escaped
485
+ post = Post.new
486
+ post.category = ''
487
+ expected = '<select id="post_category" name="post[category]"><option value="">&lt;The prompt&gt;</option><option value="abe">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
488
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], prompt: '<The prompt>'
489
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { prompt: '<The prompt>' } )
490
+ end
491
+
492
+ def test_select_with_prompt_and_blank
493
+ post = Post.new
494
+ post.category = ''
495
+ expected = '<select id="post_category" name="post[category]"><option value="">Please select</option><option value=""></option><option value="abe">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
496
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], prompt: true, include_blank: true
497
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { prompt: true, include_blank: true } )
498
+ end
499
+
500
+ def test_empty
501
+ post = Post.new
502
+ post.category = ''
503
+ expected = '<select id="post_category" name="post[category]"><option value="">Please select</option><option value=""></option></select>'
504
+ assert_dom_helper expected, :selectForObject, post, :category, [], prompt: true, include_blank: true
505
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', [], { prompt: true, include_blank: true } )
506
+ end
507
+
508
+ def test_select_with_nil
509
+ post = Post.new
510
+ post.category = 'othervalue'
511
+ expected = '<select id="post_category" name="post[category]"><option value=""></option><option value="othervalue" selected="selected">othervalue</option></select>'
512
+ assert_dom_helper expected, :selectForObject, post, :category, [ nil, 'othervalue' ]
513
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', [ null, 'othervalue' ] )
514
+ end
515
+
516
+ def test_required_select
517
+ post = Post.new
518
+ expected = '<select id="post_category" name="post[category]" required="required"><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
519
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], required: true
520
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { required: true } )
521
+ end
522
+
523
+ def test_required_select_with_include_blank_prompt
524
+ post = Post.new
525
+ expected = '<select id="post_category" name="post[category]" required="required"><option value="">Select one</option><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
526
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], include_blank: 'Select one', required: true
527
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { include_blank: 'Select one', required: true } )
528
+ end
529
+
530
+ def test_required_select_with_prompt
531
+ post = Post.new
532
+ expected = '<select id="post_category" name="post[category]" required="required"><option value="">Select one</option><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
533
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], prompt: 'Select one', required: true
534
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { prompt: 'Select one', required: true } )
535
+ end
536
+
537
+ def test_required_select_display_size_equals_to_one
538
+ post = Post.new
539
+ expected = '<select id="post_category" name="post[category]" required="required" size="1"><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
540
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], required: true, size: 1
541
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { required: true, size: 1 } )
542
+ end
543
+
544
+ def test_required_select_with_display_size_bigger_than_one
545
+ post = Post.new
546
+ expected = '<select id="post_category" name="post[category]" required="required" size="2"><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
547
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], required: true, size: 2
548
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { required: true, size: 2 } )
549
+ end
550
+
551
+ def test_required_select_with_multiple_option
552
+ post = Post.new
553
+ expected = '<input name="post[category][]" type="hidden" value=""/><select id="post_category" multiple="multiple" name="post[category][]" required="required"><option value="abe">abe</option><option value="mus">mus</option><option value="hest">hest</option></select>'
554
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', 'mus', 'hest'], required: true, multiple: true
555
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', 'mus', 'hest'], { required: true, multiple: true } )
556
+ end
557
+
558
+ def test_select_with_fixnum
559
+ post = Post.new
560
+ expected = '<select id="post_category" name="post[category]"><option value="">Please select</option><option value=""></option><option value="1">1</option></select>'
561
+ assert_dom_helper expected, :selectForObject, post, :category, [1], prompt: true, include_blank: true
562
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', [1], { prompt: true, include_blank: true } )
563
+ end
564
+
565
+ def test_list_of_lists
566
+ post = Post.new
567
+ expected = '<select id="post_category" name="post[category]"><option value="">Please select</option><option value=""></option><option value="1">1</option></select>'
568
+ assert_dom_helper expected, :selectForObject, post, :category, [1], prompt: true, include_blank: true
569
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', [1], { prompt: true, include_blank: true } )
570
+ end
571
+
572
+ def test_select_not_escapes_string_content
573
+ post = Post.new
574
+ expected = '<select id="post_title" name="post[title]"><script>alert(1)</script></select>'
575
+ assert_dom_helper expected, :selectForObject, post, 'title', '<script>alert(1)</script>'
576
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'title', '<script>alert(1)</script>' )
577
+ end
578
+
579
+ def test_select_with_blocks
580
+ post = Post.new
581
+ expected = '<select id="post_title" name="post[title]"><option value="some_value">Some Option</option></select>'
582
+ assert_dom_helper( expected, :selectForObject, post, 'title'){ '<option value="some_value">Some Option</option>' }
583
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'title', function(){ return '<option value="some_value">Some Option</option>'; } )
584
+ end
585
+
586
+
587
+ def test_select_with_selected_value
588
+ post = Post.new
589
+ expected = '<select id="post_category" name="post[category]"><option value="abe" selected="selected">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
590
+ assert_dom_helper expected, :selectForObject, post, :category, ['abe', '<mus>', 'hest'], selected: 'abe'
591
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { selected: 'abe' } )
592
+ end
593
+
594
+ def test_select_with_selected_nil
595
+ post = Post.new
596
+ post.category = '<mus>'
597
+ expected = '<select id="post_category" name="post[category]"><option value="abe">abe</option><option value="&lt;mus&gt;">&lt;mus&gt;</option><option value="hest">hest</option></select>'
598
+ assert_dom_helper expected, :selectForObject, post, 'category', ['abe', '<mus>', 'hest'], selected: nil
599
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { selected: null } )
600
+ end
601
+
602
+ def test_select_not_existing_method_with_selected_value
603
+ post = Post.new
604
+ expected = '<select id="post_locale" name="post[locale]"><option value="en">en</option><option value="ru" selected="selected">ru</option></select>'
605
+ assert_dom_helper expected, :selectForObject, post, 'locale', ['en', 'ru'], selected: 'ru'
606
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'locale', ['en', 'ru'], { selected: 'ru' } )
607
+ end
608
+
609
+ def test_select_with_prompt_and_selected_value
610
+ post = Post.new
611
+ expected = '<select id="post_category" name="post[category]"><option value="one">one</option><option selected="selected" value="two">two</option></select>'
612
+ assert_dom_helper expected, :selectForObject, post, 'category', ['one', 'two'], selected: 'two', prompt: true
613
+ assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['one', 'two'], { selected: 'two', prompt: true } )
614
+ end
615
+
616
+ # # TODO: Think about not handle disabled option on selectForObject helper
617
+ # def test_select_with_disabled_value
618
+ # post = Post.new
619
+ # post.category = '<mus>'
620
+ # expected = '<select id="post_category" name="post[category]"><option value="abe">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest" disabled="disabled">hest</option></select>'
621
+ # assert_dom_helper expected, :selectForObject, post, 'category', ['abe', '<mus>', 'hest'], disabled: 'hest'
622
+ # assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { disabled: 'hest' } )
623
+ # end
624
+ #
625
+ # def test_select_with_disabled_array
626
+ # post = Post.new
627
+ # expected = '<select id="post_category" name="post[category]"><option value="abe" disabled="disabled">abe</option><option value="&lt;mus&gt;" selected="selected">&lt;mus&gt;</option><option value="hest" disabled="disabled">hest</option></select>'
628
+ # assert_dom_helper expected, :selectForObject, post, 'category', ['abe', '<mus>', 'hest'], disabled: [ 'hest', 'abe' ]
629
+ # assert_dom_js_helper expected, :selectForObject, %( #{ post.to_json }, 'category', ['abe', '<mus>', 'hest'], { disabled: [ 'hest', 'abe' ] } )
630
+ # end
631
+
632
+ # # TODO: I didn't found a nice way to support ranges on selectForObject helper
633
+ # def test_select_with_range
634
+ # post = Post.new
635
+ # post.category = 0
636
+ # expected = '<select id="post_category" name="post[category]"><option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option></select>'
637
+ # assert_dom_helper expected, :selectForObject, post, 'category', 1..3
638
+ # end
639
+
640
+ def test_collection_select
641
+ post = Post.new
642
+ post.author_name = 'Babe'
643
+ expected = '<select id="post_author_name" name="post[author_name]"><option value="&lt;Abe&gt;">&lt;Abe&gt;</option><option value="Babe" selected="selected">Babe</option><option value="Cabe">Cabe</option></select>'
644
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name
645
+ end
646
+
647
+ def test_collection_select_with_blank_and_style
648
+ post = Post.new
649
+ post.author_name = 'Babe'
650
+ expected = '<select id="post_author_name" name="post[author_name]" style="width: 200px"><option value=""></option><option value="&lt;Abe&gt;">&lt;Abe&gt;</option><option value="Babe" selected="selected">Babe</option><option value="Cabe">Cabe</option></select>'
651
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name, include_blank: true, style: 'width: 200px'
652
+ end
653
+
654
+ def test_collection_select_with_blank_as_string_and_style
655
+ post = Post.new
656
+ post.author_name = 'Babe'
657
+ expected = '<select id="post_author_name" name="post[author_name]" style="width: 200px"><option value="">No Selection</option><option value="&lt;Abe&gt;">&lt;Abe&gt;</option><option value="Babe" selected="selected">Babe</option><option value="Cabe">Cabe</option></select>'
658
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name, include_blank: 'No Selection', style: 'width: 200px'
659
+ end
660
+
661
+ def test_collection_select_with_multiple_option_appends_array_brackets_and_hidden_input
662
+ post = Post.new
663
+ post.author_name = 'Babe'
664
+ expected = '<input type="hidden" name="post[author_name][]" value=""/><select id="post_author_name" name="post[author_name][]" multiple="multiple"><option value=""></option><option value="&lt;Abe&gt;">&lt;Abe&gt;</option><option value="Babe" selected="selected">Babe</option><option value="Cabe">Cabe</option></select>'
665
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name, include_blank: true, multiple: true
666
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name, include_blank: true, multiple: true, name: 'post[author_name][]'
667
+ end
668
+
669
+ def test_collection_select_with_blank_and_selected
670
+ post = Post.new
671
+ post.author_name = 'Babe'
672
+ expected = '<select id="post_author_name" name="post[author_name]"><option value=""></option><option value="&lt;Abe&gt;" selected="selected">&lt;Abe&gt;</option><option value="Babe">Babe</option><option value="Cabe">Cabe</option></select>'
673
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, :author_name, :author_name, include_blank: true, selected: '<Abe>'
674
+ end
675
+
676
+ def test_collection_select_with_proc_for_value_method
677
+ post = Post.new
678
+ expected = '<select id="post_author_name" name="post[author_name]"><option value="&lt;Abe&gt;">&lt;Abe&gt; went home</option><option value="Babe">Babe went home</option><option value="Cabe">Cabe went home</option></select>'
679
+ assert_dom_helper expected, :collectionSelectForObject, post, :author_name, dummy_posts, lambda{ |jr, post| post.author_name }, :title
680
+ end
681
+
682
+ # def test_collection_select_with_proc_for_text_method
683
+ # @post = Post.new
684
+ #
685
+ # assert_dom_equal(
686
+ # "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option></select>",
687
+ # collection_select("post", "author_name", dummy_posts, "author_name", lambda { |p| p.title })
688
+ # )
689
+ # end
690
+
691
+ # # TODO: Think about not handle disabled option on collectionSelectForObject helper
692
+ # def test_collection_select_with_disabled
693
+ # @post = Post.new
694
+ # @post.author_name = "Babe"
695
+ #
696
+ # assert_dom_equal(
697
+ # "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe</option></select>",
698
+ # collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => 'Cabe')
699
+ # )
700
+ # end
701
+
702
+ protected
703
+ def dummy_posts
704
+ [
705
+ Post.new('<Abe> went home', '<Abe>', 'To a little house', 'shh!'),
706
+ Post.new('Babe went home', 'Babe', 'To a little house', 'shh!'),
707
+ Post.new('Cabe went home', 'Cabe', 'To a little house', 'shh!')
708
+ ]
709
+ end
710
+
711
+ def dummy_continents
712
+ [
713
+ Continent.new('<Africa>', [ Country.new('<sa>', '<South Africa>'), Country.new('so', 'Somalia') ]),
714
+ Continent.new('Europe', [ Country.new('dk', 'Denmark'), Country.new('ie', 'Ireland') ])
715
+ ]
716
+ end
717
+
718
+ end