actionpack 1.11.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +392 -5
- data/lib/action_controller.rb +8 -4
- data/lib/action_controller/assertions.rb +9 -10
- data/lib/action_controller/base.rb +177 -88
- data/lib/action_controller/benchmarking.rb +5 -5
- data/lib/action_controller/caching.rb +44 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
- data/lib/action_controller/cgi_process.rb +36 -24
- data/lib/action_controller/components.rb +152 -52
- data/lib/action_controller/dependencies.rb +1 -1
- data/lib/action_controller/deprecated_redirects.rb +2 -2
- data/lib/action_controller/deprecated_request_methods.rb +34 -0
- data/lib/action_controller/filters.rb +59 -19
- data/lib/action_controller/flash.rb +53 -47
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/integration.rb +524 -0
- data/lib/action_controller/layout.rb +58 -23
- data/lib/action_controller/mime_responds.rb +163 -0
- data/lib/action_controller/mime_type.rb +142 -0
- data/lib/action_controller/pagination.rb +13 -7
- data/lib/action_controller/request.rb +59 -56
- data/lib/action_controller/rescue.rb +1 -1
- data/lib/action_controller/routing.rb +29 -10
- data/lib/action_controller/scaffolding.rb +8 -0
- data/lib/action_controller/session/active_record_store.rb +21 -10
- data/lib/action_controller/session/mem_cache_store.rb +18 -12
- data/lib/action_controller/session_management.rb +30 -11
- data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
- data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +189 -118
- data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
- data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
- data/lib/action_controller/vendor/xml_node.rb +97 -0
- data/lib/action_controller/verification.rb +2 -0
- data/lib/action_pack/version.rb +3 -3
- data/lib/action_view.rb +0 -2
- data/lib/action_view/base.rb +109 -36
- data/lib/action_view/compiled_templates.rb +1 -1
- data/lib/action_view/helpers/active_record_helper.rb +4 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
- data/lib/action_view/helpers/capture_helper.rb +49 -12
- data/lib/action_view/helpers/date_helper.rb +14 -4
- data/lib/action_view/helpers/form_helper.rb +136 -20
- data/lib/action_view/helpers/form_options_helper.rb +29 -7
- data/lib/action_view/helpers/form_tag_helper.rb +22 -20
- data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
- data/lib/action_view/helpers/javascript_helper.rb +50 -446
- data/lib/action_view/helpers/javascripts/controls.js +95 -30
- data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
- data/lib/action_view/helpers/javascripts/effects.js +310 -211
- data/lib/action_view/helpers/javascripts/prototype.js +228 -28
- data/lib/action_view/helpers/number_helper.rb +9 -9
- data/lib/action_view/helpers/pagination_helper.rb +1 -1
- data/lib/action_view/helpers/prototype_helper.rb +900 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
- data/lib/action_view/helpers/text_helper.rb +7 -6
- data/lib/action_view/helpers/url_helper.rb +23 -14
- data/lib/action_view/partials.rb +12 -4
- data/rakefile +13 -5
- data/test/abstract_unit.rb +4 -3
- data/test/active_record_unit.rb +88 -0
- data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
- data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
- data/test/activerecord/pagination_test.rb +161 -0
- data/test/controller/action_pack_assertions_test.rb +18 -15
- data/test/controller/base_test.rb +31 -42
- data/test/controller/benchmark_test.rb +8 -11
- data/test/controller/capture_test.rb +33 -1
- data/test/controller/cgi_test.rb +33 -0
- data/test/controller/custom_handler_test.rb +8 -0
- data/test/controller/fake_controllers.rb +9 -17
- data/test/controller/filters_test.rb +32 -3
- data/test/controller/flash_test.rb +26 -41
- data/test/controller/fragment_store_setting_test.rb +1 -1
- data/test/controller/layout_test.rb +73 -0
- data/test/controller/mime_responds_test.rb +257 -0
- data/test/controller/mime_type_test.rb +24 -0
- data/test/controller/new_render_test.rb +157 -1
- data/test/controller/redirect_test.rb +23 -0
- data/test/controller/render_test.rb +54 -56
- data/test/controller/request_test.rb +25 -0
- data/test/controller/routing_test.rb +74 -66
- data/test/controller/test_test.rb +66 -1
- data/test/controller/verification_test.rb +3 -1
- data/test/controller/webservice_test.rb +255 -0
- data/test/fixtures/companies.yml +24 -0
- data/test/fixtures/company.rb +9 -0
- data/test/fixtures/db_definitions/sqlite.sql +42 -0
- data/test/fixtures/developer.rb +7 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +13 -0
- data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
- data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
- data/test/fixtures/multipart/mona_lisa.jpg +0 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/replies.yml +13 -0
- data/test/fixtures/reply.rb +5 -0
- data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
- data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
- data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults.rxml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
- data/test/fixtures/test/block_content_for.rhtml +2 -0
- data/test/fixtures/test/delete_with_js.rjs +2 -0
- data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
- data/test/fixtures/test/enum_rjs_test.rjs +6 -0
- data/test/fixtures/test/erb_content_for.rhtml +2 -0
- data/test/fixtures/test/hello_world.rxml +3 -0
- data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
- data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/template/active_record_helper_test.rb +4 -0
- data/test/template/asset_tag_helper_test.rb +7 -2
- data/test/template/date_helper_test.rb +39 -2
- data/test/template/form_helper_test.rb +238 -5
- data/test/template/form_options_helper_test.rb +78 -0
- data/test/template/form_tag_helper_test.rb +11 -0
- data/test/template/java_script_macros_helper_test.rb +51 -6
- data/test/template/javascript_helper_test.rb +7 -153
- data/test/template/number_helper_test.rb +14 -13
- data/test/template/prototype_helper_test.rb +423 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/text_helper_test.rb +12 -9
- data/test/template/url_helper_test.rb +31 -15
- metadata +291 -246
- data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
- data/lib/action_controller/upload_progress.rb +0 -473
- data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
- data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
- data/lib/action_view/vendor/builder.rb +0 -13
- data/lib/action_view/vendor/builder/blankslate.rb +0 -53
- data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
- data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
- data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
- data/test/controller/multipart_progress_testx.rb +0 -365
- data/test/controller/upload_progress_testx.rb +0 -89
- data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -23,6 +23,7 @@ end
|
|
23
23
|
ActionView::Helpers::FormOptionsHelper::TimeZone = MockTimeZone
|
24
24
|
|
25
25
|
class FormOptionsHelperTest < Test::Unit::TestCase
|
26
|
+
include ActionView::Helpers::FormHelper
|
26
27
|
include ActionView::Helpers::FormOptionsHelper
|
27
28
|
|
28
29
|
silence_warnings do
|
@@ -222,6 +223,22 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
222
223
|
)
|
223
224
|
end
|
224
225
|
|
226
|
+
def test_select_under_fields_for
|
227
|
+
@post = Post.new
|
228
|
+
@post.category = "<mus>"
|
229
|
+
|
230
|
+
_erbout = ''
|
231
|
+
|
232
|
+
fields_for :post, @post do |f|
|
233
|
+
_erbout.concat f.select(:category, %w( abe <mus> hest))
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_dom_equal(
|
237
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
238
|
+
_erbout
|
239
|
+
)
|
240
|
+
end
|
241
|
+
|
225
242
|
def test_select_with_blank
|
226
243
|
@post = Post.new
|
227
244
|
@post.category = "<mus>"
|
@@ -266,6 +283,24 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
266
283
|
select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
|
267
284
|
)
|
268
285
|
end
|
286
|
+
|
287
|
+
def test_select_with_selected_value
|
288
|
+
@post = Post.new
|
289
|
+
@post.category = "<mus>"
|
290
|
+
assert_dom_equal(
|
291
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
292
|
+
select("post", "category", %w( abe <mus> hest ), :selected => 'abe')
|
293
|
+
)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_select_with_selected_nil
|
297
|
+
@post = Post.new
|
298
|
+
@post.category = "<mus>"
|
299
|
+
assert_dom_equal(
|
300
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
301
|
+
select("post", "category", %w( abe <mus> hest ), :selected => nil)
|
302
|
+
)
|
303
|
+
end
|
269
304
|
|
270
305
|
def test_collection_select
|
271
306
|
@posts = [
|
@@ -283,6 +318,28 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
283
318
|
)
|
284
319
|
end
|
285
320
|
|
321
|
+
def test_collection_select_under_fields_for
|
322
|
+
@posts = [
|
323
|
+
Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
|
324
|
+
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
|
325
|
+
Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
|
326
|
+
]
|
327
|
+
|
328
|
+
@post = Post.new
|
329
|
+
@post.author_name = "Babe"
|
330
|
+
|
331
|
+
_erbout = ''
|
332
|
+
|
333
|
+
fields_for :post, @post do |f|
|
334
|
+
_erbout.concat f.collection_select(:author_name, @posts, :author_name, :author_name)
|
335
|
+
end
|
336
|
+
|
337
|
+
assert_dom_equal(
|
338
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
339
|
+
_erbout
|
340
|
+
)
|
341
|
+
end
|
342
|
+
|
286
343
|
def test_collection_select_with_blank_and_style
|
287
344
|
@posts = [
|
288
345
|
Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
|
@@ -324,6 +381,27 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
324
381
|
html
|
325
382
|
end
|
326
383
|
|
384
|
+
def test_time_zone_select_under_fields_for
|
385
|
+
@firm = Firm.new("D")
|
386
|
+
|
387
|
+
_erbout = ''
|
388
|
+
|
389
|
+
fields_for :firm, @firm do |f|
|
390
|
+
_erbout.concat f.time_zone_select(:time_zone)
|
391
|
+
end
|
392
|
+
|
393
|
+
assert_dom_equal(
|
394
|
+
"<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
395
|
+
"<option value=\"A\">A</option>\n" +
|
396
|
+
"<option value=\"B\">B</option>\n" +
|
397
|
+
"<option value=\"C\">C</option>\n" +
|
398
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
399
|
+
"<option value=\"E\">E</option>" +
|
400
|
+
"</select>",
|
401
|
+
_erbout
|
402
|
+
)
|
403
|
+
end
|
404
|
+
|
327
405
|
def test_time_zone_select_with_blank
|
328
406
|
@firm = Firm.new("D")
|
329
407
|
html = time_zone_select("firm", "time_zone", nil, :include_blank => true)
|
@@ -93,5 +93,16 @@ class FormTagHelperTest < Test::Unit::TestCase
|
|
93
93
|
expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
|
94
94
|
assert_dom_equal expected, actual
|
95
95
|
end
|
96
|
+
|
97
|
+
def test_submit_tag
|
98
|
+
assert_dom_equal(
|
99
|
+
%(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';this.form.submit();alert('hello!')" />),
|
100
|
+
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_pass
|
105
|
+
assert_equal 1, 1
|
106
|
+
end
|
96
107
|
end
|
97
108
|
|
@@ -23,15 +23,15 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
|
25
25
|
def test_auto_complete_field
|
26
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\
|
26
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})\n//]]>\n</script>),
|
27
27
|
auto_complete_field("some_input", :url => { :action => "autocomplete" });
|
28
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\
|
28
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})\n//]]>\n</script>),
|
29
29
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
|
30
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\
|
30
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})\n//]]>\n</script>),
|
31
31
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
|
32
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\
|
32
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {minChars:3})\n//]]>\n</script>),
|
33
33
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3);
|
34
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\
|
34
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){Alert('me');}})\n//]]>\n</script>),
|
35
35
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){Alert('me');}");
|
36
36
|
end
|
37
37
|
|
@@ -50,7 +50,52 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase
|
|
50
50
|
def test_text_field_with_auto_complete
|
51
51
|
assert_match "<style>",
|
52
52
|
text_field_with_auto_complete(:message, :recipient)
|
53
|
-
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\
|
53
|
+
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\nvar message_recipient_auto_completer = new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})\n//]]>\n</script>),
|
54
54
|
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
55
55
|
end
|
56
|
+
|
57
|
+
def test_in_place_editor_external_control
|
58
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {externalControl:'blah'})\n//]]>\n</script>),
|
59
|
+
in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'})
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_in_place_editor_size
|
63
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {size:4})\n//]]>\n</script>),
|
64
|
+
in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4})
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_in_place_editor_cols_no_rows
|
68
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:4})\n//]]>\n</script>),
|
69
|
+
in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4})
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_in_place_editor_cols_with_rows
|
73
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:40, rows:5})\n//]]>\n</script>),
|
74
|
+
in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40})
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_inplace_editor_loading_text
|
78
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {loadingText:'Why are we waiting?'})\n//]]>\n</script>),
|
79
|
+
in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :loading_text => 'Why are we waiting?'})
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_in_place_editor_url
|
83
|
+
assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value')",
|
84
|
+
in_place_editor( 'id-goes-here', :url => { :action => "action_to_set_value" })
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_in_place_editor_load_text_url
|
88
|
+
assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {loadTextURL:'http://www.example.com/action_to_get_value'})",
|
89
|
+
in_place_editor( 'id-goes-here',
|
90
|
+
:url => { :action => "action_to_set_value" },
|
91
|
+
:load_text_url => { :action => "action_to_get_value" })
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_in_place_editor_eval_scripts
|
95
|
+
assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {evalScripts:true})",
|
96
|
+
in_place_editor( 'id-goes-here',
|
97
|
+
:url => { :action => "action_to_set_value" },
|
98
|
+
:script => true )
|
99
|
+
end
|
100
|
+
|
56
101
|
end
|
@@ -9,17 +9,6 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
|
9
9
|
include ActionView::Helpers::FormHelper
|
10
10
|
include ActionView::Helpers::CaptureHelper
|
11
11
|
|
12
|
-
def setup
|
13
|
-
@controller = Class.new do
|
14
|
-
def url_for(options, *parameters_for_method_reference)
|
15
|
-
url = "http://www.example.com/"
|
16
|
-
url << options[:action].to_s if options and options[:action]
|
17
|
-
url
|
18
|
-
end
|
19
|
-
end
|
20
|
-
@controller = @controller.new
|
21
|
-
end
|
22
|
-
|
23
12
|
def test_define_javascript_functions
|
24
13
|
# check if prototype.js is included first
|
25
14
|
assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
|
@@ -37,148 +26,13 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
|
37
26
|
link_to_function("Greeting", "alert('Hello world!')")
|
38
27
|
end
|
39
28
|
|
40
|
-
def
|
41
|
-
assert_dom_equal %(<a
|
42
|
-
|
43
|
-
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
44
|
-
link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
45
|
-
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
46
|
-
link_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
47
|
-
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
48
|
-
link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_periodically_call_remote
|
52
|
-
assert_dom_equal %(<script type="text/javascript">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)\n//]]>\n</script>),
|
53
|
-
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_form_remote_tag
|
57
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
58
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
|
59
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
60
|
-
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast })
|
61
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
62
|
-
form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast })
|
63
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
64
|
-
form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast })
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_on_callbacks
|
68
|
-
callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure]
|
69
|
-
callbacks.each do |callback|
|
70
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
71
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
72
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
73
|
-
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
74
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
75
|
-
form_remote_tag(:update => { :failure => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
76
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
77
|
-
form_remote_tag(:update => { :success => "glass_of_beer", :failure => "glass_of_water" }, :url => { :action => :fast }, callback=>"monkeys();")
|
78
|
-
end
|
79
|
-
|
80
|
-
#HTTP status codes 200 up to 599 have callbacks
|
81
|
-
#these should work
|
82
|
-
100.upto(599) do |callback|
|
83
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
84
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
85
|
-
end
|
86
|
-
|
87
|
-
#test 200 and 404
|
88
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, parameters:Form.serialize(this)}); return false;">),
|
89
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, 200=>"monkeys();", 404=>"bananas();")
|
90
|
-
|
91
|
-
#these shouldn't
|
92
|
-
1.upto(99) do |callback|
|
93
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
94
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
95
|
-
end
|
96
|
-
600.upto(999) do |callback|
|
97
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
98
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
99
|
-
end
|
100
|
-
|
101
|
-
#test ultimate combo
|
102
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, onComplete:function(request){c();}, onFailure:function(request){f();}, onLoading:function(request){c1()}, onSuccess:function(request){s()}, parameters:Form.serialize(this)}); return false;\">),
|
103
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :loading => "c1()", :success => "s()", :failure => "f();", :complete => "c();", 200=>"monkeys();", 404=>"bananas();")
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_submit_to_remote
|
108
|
-
assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />),
|
109
|
-
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
|
29
|
+
def test_link_to_function_with_existing_onclick
|
30
|
+
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
|
31
|
+
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
|
110
32
|
end
|
111
|
-
|
112
|
-
def
|
113
|
-
assert_dom_equal %(<
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_observe_form
|
118
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>),
|
119
|
-
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_effect
|
123
|
-
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, "posts")
|
124
|
-
assert_equal "new Effect.Highlight('posts',{});", visual_effect("highlight", :posts)
|
125
|
-
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, :posts)
|
126
|
-
assert_equal "new Effect.Fade('fademe',{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
|
127
|
-
assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
|
128
|
-
assert_equal "new Effect.DropOut('dropme',{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_sortable_element
|
132
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})\n//]]>\n</script>),
|
133
|
-
sortable_element("mylist", :url => { :action => "order" })
|
134
|
-
assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create('mylist', {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}, tag:'div'})\n//]]>\n</script>),
|
135
|
-
sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
|
136
|
-
assert_dom_equal %|<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create('mylist', {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})\n//]]>\n</script>|,
|
137
|
-
sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
|
138
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create('mylist', {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})\n//]]>\n</script>),
|
139
|
-
sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_draggable_element
|
143
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable('product_13', {})\n//]]>\n</script>),
|
144
|
-
draggable_element('product_13')
|
145
|
-
assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable('product_13', {revert:true})\n//]]>\n</script>),
|
146
|
-
draggable_element('product_13', :revert => true)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_drop_receiving_element
|
150
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
151
|
-
drop_receiving_element('droptarget1')
|
152
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
153
|
-
drop_receiving_element('droptarget1', :accept => 'products')
|
154
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
155
|
-
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
|
156
|
-
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
157
|
-
drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox')
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_update_element_function
|
161
|
-
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
162
|
-
update_element_function('myelement', :content => 'blub')
|
163
|
-
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
164
|
-
update_element_function('myelement', :action => :update, :content => 'blub')
|
165
|
-
assert_equal %($('myelement').innerHTML = '';\n),
|
166
|
-
update_element_function('myelement', :action => :empty)
|
167
|
-
assert_equal %(Element.remove('myelement');\n),
|
168
|
-
update_element_function('myelement', :action => :remove)
|
169
|
-
|
170
|
-
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
171
|
-
update_element_function('myelement', :position => 'bottom', :content => 'blub')
|
172
|
-
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
173
|
-
update_element_function('myelement', :action => :update, :position => :bottom, :content => 'blub')
|
174
|
-
|
175
|
-
_erbout = ""
|
176
|
-
assert_equal %($('myelement').innerHTML = 'test';\n),
|
177
|
-
update_element_function('myelement') { _erbout << "test" }
|
178
|
-
|
179
|
-
_erbout = ""
|
180
|
-
assert_equal %($('myelement').innerHTML = 'blockstuff';\n),
|
181
|
-
update_element_function('myelement', :content => 'paramstuff') { _erbout << "blockstuff" }
|
33
|
+
|
34
|
+
def test_button_to_function
|
35
|
+
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
|
36
|
+
button_to_function("Greeting", "alert('Hello world!')")
|
182
37
|
end
|
183
|
-
|
184
38
|
end
|
@@ -34,19 +34,20 @@ class NumberHelperTest < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_number_to_human_size
|
37
|
-
assert_equal
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
46
|
-
assert_equal
|
47
|
-
assert_equal
|
48
|
-
assert_equal
|
49
|
-
assert_nil
|
37
|
+
assert_equal '0 Bytes', human_size(0)
|
38
|
+
assert_equal '3 Bytes', human_size(3.14159265)
|
39
|
+
assert_equal '123 Bytes', human_size(123.0)
|
40
|
+
assert_equal '123 Bytes', human_size(123)
|
41
|
+
assert_equal '1.2 KB', human_size(1234)
|
42
|
+
assert_equal '12.1 KB', human_size(12345)
|
43
|
+
assert_equal '1.2 MB', human_size(1234567)
|
44
|
+
assert_equal '1.1 GB', human_size(1234567890)
|
45
|
+
assert_equal '1.1 TB', human_size(1234567890123)
|
46
|
+
assert_equal '444 KB', human_size(444.kilobytes)
|
47
|
+
assert_equal '1023 MB', human_size(1023.megabytes)
|
48
|
+
assert_equal '3 TB', human_size(3.terabytes)
|
49
|
+
assert_nil human_size('x')
|
50
|
+
assert_nil human_size(nil)
|
50
51
|
end
|
51
52
|
|
52
53
|
def test_number_with_precision
|
@@ -0,0 +1,423 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
module BaseTest
|
4
|
+
include ActionView::Helpers::JavaScriptHelper
|
5
|
+
include ActionView::Helpers::PrototypeHelper
|
6
|
+
include ActionView::Helpers::ScriptaculousHelper
|
7
|
+
|
8
|
+
include ActionView::Helpers::UrlHelper
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
include ActionView::Helpers::TextHelper
|
11
|
+
include ActionView::Helpers::FormHelper
|
12
|
+
include ActionView::Helpers::CaptureHelper
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@controller = Class.new do
|
16
|
+
def url_for(options, *parameters_for_method_reference)
|
17
|
+
url = "http://www.example.com/"
|
18
|
+
url << options[:action].to_s if options and options[:action]
|
19
|
+
url << "?a=#{options[:a]}" if options && options[:a]
|
20
|
+
url << "&b=#{options[:b]}" if options && options[:a] && options[:b]
|
21
|
+
url
|
22
|
+
end
|
23
|
+
end.new
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def create_generator
|
28
|
+
block = Proc.new { |*args| yield *args if block_given? }
|
29
|
+
JavaScriptGenerator.new self, &block
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class PrototypeHelperTest < Test::Unit::TestCase
|
34
|
+
include BaseTest
|
35
|
+
|
36
|
+
def test_link_to_remote
|
37
|
+
assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outpost</a>),
|
38
|
+
link_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
|
39
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
40
|
+
link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
41
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
42
|
+
link_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
43
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
44
|
+
link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
45
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
46
|
+
link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_periodically_call_remote
|
50
|
+
assert_dom_equal %(<script type="text/javascript">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)\n//]]>\n</script>),
|
51
|
+
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_form_remote_tag
|
55
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
56
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
|
57
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
58
|
+
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast })
|
59
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
60
|
+
form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast })
|
61
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
62
|
+
form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast })
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_on_callbacks
|
66
|
+
callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure]
|
67
|
+
callbacks.each do |callback|
|
68
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
69
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
70
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
71
|
+
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
72
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
73
|
+
form_remote_tag(:update => { :failure => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
74
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
75
|
+
form_remote_tag(:update => { :success => "glass_of_beer", :failure => "glass_of_water" }, :url => { :action => :fast }, callback=>"monkeys();")
|
76
|
+
end
|
77
|
+
|
78
|
+
#HTTP status codes 200 up to 599 have callbacks
|
79
|
+
#these should work
|
80
|
+
100.upto(599) do |callback|
|
81
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
82
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
83
|
+
end
|
84
|
+
|
85
|
+
#test 200 and 404
|
86
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, parameters:Form.serialize(this)}); return false;">),
|
87
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, 200=>"monkeys();", 404=>"bananas();")
|
88
|
+
|
89
|
+
#these shouldn't
|
90
|
+
1.upto(99) do |callback|
|
91
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
92
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
93
|
+
end
|
94
|
+
600.upto(999) do |callback|
|
95
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
96
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
97
|
+
end
|
98
|
+
|
99
|
+
#test ultimate combo
|
100
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, onComplete:function(request){c();}, onFailure:function(request){f();}, onLoading:function(request){c1()}, onSuccess:function(request){s()}, parameters:Form.serialize(this)}); return false;\">),
|
101
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :loading => "c1()", :success => "s()", :failure => "f();", :complete => "c();", 200=>"monkeys();", 404=>"bananas();")
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_submit_to_remote
|
106
|
+
assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />),
|
107
|
+
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_observe_field
|
111
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>),
|
112
|
+
observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_observe_field_using_function_for_callback
|
116
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>),
|
117
|
+
observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')")
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_observe_form
|
121
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>),
|
122
|
+
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_observe_form_using_function_for_callback
|
126
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {alert('Form changed')})\n//]]>\n</script>),
|
127
|
+
observe_form("cart", :frequency => 2, :function => "alert('Form changed')")
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_update_element_function
|
131
|
+
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
132
|
+
update_element_function('myelement', :content => 'blub')
|
133
|
+
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
134
|
+
update_element_function('myelement', :action => :update, :content => 'blub')
|
135
|
+
assert_equal %($('myelement').innerHTML = '';\n),
|
136
|
+
update_element_function('myelement', :action => :empty)
|
137
|
+
assert_equal %(Element.remove('myelement');\n),
|
138
|
+
update_element_function('myelement', :action => :remove)
|
139
|
+
|
140
|
+
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
141
|
+
update_element_function('myelement', :position => 'bottom', :content => 'blub')
|
142
|
+
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
143
|
+
update_element_function('myelement', :action => :update, :position => :bottom, :content => 'blub')
|
144
|
+
|
145
|
+
_erbout = ""
|
146
|
+
assert_equal %($('myelement').innerHTML = 'test';\n),
|
147
|
+
update_element_function('myelement') { _erbout << "test" }
|
148
|
+
|
149
|
+
_erbout = ""
|
150
|
+
assert_equal %($('myelement').innerHTML = 'blockstuff';\n),
|
151
|
+
update_element_function('myelement', :content => 'paramstuff') { _erbout << "blockstuff" }
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_update_page
|
155
|
+
block = Proc.new { |page| page.replace_html('foo', 'bar') }
|
156
|
+
assert_equal create_generator(&block).to_s, update_page(&block)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_update_page_tag
|
160
|
+
block = Proc.new { |page| page.replace_html('foo', 'bar') }
|
161
|
+
assert_equal javascript_tag(create_generator(&block).to_s), update_page_tag(&block)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class JavaScriptGeneratorTest < Test::Unit::TestCase
|
166
|
+
include BaseTest
|
167
|
+
|
168
|
+
def setup
|
169
|
+
super
|
170
|
+
@generator = create_generator
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_insert_html_with_string
|
174
|
+
assert_equal 'new Insertion.Top("element", "<p>This is a test</p>");',
|
175
|
+
@generator.insert_html(:top, 'element', '<p>This is a test</p>')
|
176
|
+
assert_equal 'new Insertion.Bottom("element", "<p>This is a test</p>");',
|
177
|
+
@generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
|
178
|
+
assert_equal 'new Insertion.Before("element", "<p>This is a test</p>");',
|
179
|
+
@generator.insert_html(:before, 'element', '<p>This is a test</p>')
|
180
|
+
assert_equal 'new Insertion.After("element", "<p>This is a test</p>");',
|
181
|
+
@generator.insert_html(:after, 'element', '<p>This is a test</p>')
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_replace_html_with_string
|
185
|
+
assert_equal 'Element.update("element", "<p>This is a test</p>");',
|
186
|
+
@generator.replace_html('element', '<p>This is a test</p>')
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_replace_element_with_string
|
190
|
+
assert_equal 'Element.replace("element", "<div id=\"element\"><p>This is a test</p></div>");',
|
191
|
+
@generator.replace('element', '<div id="element"><p>This is a test</p></div>')
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_remove
|
195
|
+
assert_equal '["foo"].each(Element.remove);',
|
196
|
+
@generator.remove('foo')
|
197
|
+
assert_equal '["foo", "bar", "baz"].each(Element.remove);',
|
198
|
+
@generator.remove('foo', 'bar', 'baz')
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_show
|
202
|
+
assert_equal 'Element.show("foo");',
|
203
|
+
@generator.show('foo')
|
204
|
+
assert_equal 'Element.show("foo", "bar", "baz");',
|
205
|
+
@generator.show('foo', 'bar', 'baz')
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_hide
|
209
|
+
assert_equal 'Element.hide("foo");',
|
210
|
+
@generator.hide('foo')
|
211
|
+
assert_equal 'Element.hide("foo", "bar", "baz");',
|
212
|
+
@generator.hide('foo', 'bar', 'baz')
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_alert
|
216
|
+
assert_equal 'alert("hello");', @generator.alert('hello')
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_redirect_to
|
220
|
+
assert_equal 'window.location.href = "http://www.example.com/welcome";',
|
221
|
+
@generator.redirect_to(:action => 'welcome')
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_delay
|
225
|
+
@generator.delay(20) do
|
226
|
+
@generator.hide('foo')
|
227
|
+
end
|
228
|
+
|
229
|
+
assert_equal "setTimeout(function() {\n;\nElement.hide(\"foo\");\n}, 20000);", @generator.to_s
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_to_s
|
233
|
+
@generator.insert_html(:top, 'element', '<p>This is a test</p>')
|
234
|
+
@generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
|
235
|
+
@generator.remove('foo', 'bar')
|
236
|
+
@generator.replace_html('baz', '<p>This is a test</p>')
|
237
|
+
|
238
|
+
assert_equal <<-EOS.chomp, @generator.to_s
|
239
|
+
new Insertion.Top("element", "<p>This is a test</p>");
|
240
|
+
new Insertion.Bottom("element", "<p>This is a test</p>");
|
241
|
+
["foo", "bar"].each(Element.remove);
|
242
|
+
Element.update("baz", "<p>This is a test</p>");
|
243
|
+
EOS
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_element_access
|
247
|
+
assert_equal %($("hello");), @generator['hello']
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_element_proxy_one_deep
|
251
|
+
@generator['hello'].hide
|
252
|
+
assert_equal %($("hello").hide();), @generator.to_s
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_element_proxy_assignment
|
256
|
+
@generator['hello'].width = 400
|
257
|
+
assert_equal %($("hello").width = 400;), @generator.to_s
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_element_proxy_two_deep
|
261
|
+
@generator['hello'].hide("first").clean_whitespace
|
262
|
+
assert_equal %($("hello").hide("first").cleanWhitespace();), @generator.to_s
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_select_access
|
266
|
+
assert_equal %($$("div.hello");), @generator.select('div.hello')
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_select_proxy_one_deep
|
270
|
+
@generator.select('p.welcome b').first.hide
|
271
|
+
assert_equal %($$("p.welcome b").first().hide();), @generator.to_s
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_visual_effect
|
275
|
+
assert_equal %(new Effect.Puff("blah",{});),
|
276
|
+
@generator.visual_effect(:puff,'blah')
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_visual_effect_toggle
|
280
|
+
assert_equal %(Effect.toggle("blah",'appear',{});),
|
281
|
+
@generator.visual_effect(:toggle_appear,'blah')
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_sortable
|
285
|
+
assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
|
286
|
+
@generator.sortable('blah', :url => { :action => "order" })
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_draggable
|
290
|
+
assert_equal %(new Draggable("blah", {});),
|
291
|
+
@generator.draggable('blah')
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_drop_receiving
|
295
|
+
assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
|
296
|
+
@generator.drop_receiving('blah', :url => { :action => "order" })
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_collection_first_and_last
|
300
|
+
@generator.select('p.welcome b').first.hide()
|
301
|
+
@generator.select('p.welcome b').last.show()
|
302
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
303
|
+
$$("p.welcome b").first().hide();
|
304
|
+
$$("p.welcome b").last().show();
|
305
|
+
EOS
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_collection_proxy_with_each
|
309
|
+
@generator.select('p.welcome b').each do |value|
|
310
|
+
value.remove_class_name 'selected'
|
311
|
+
end
|
312
|
+
@generator.select('p.welcome b').each do |value, index|
|
313
|
+
@generator.visual_effect :highlight, value
|
314
|
+
end
|
315
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
316
|
+
$$("p.welcome b").each(function(value, index) {
|
317
|
+
value.removeClassName("selected");
|
318
|
+
});
|
319
|
+
$$("p.welcome b").each(function(value, index) {
|
320
|
+
new Effect.Highlight(value,{});
|
321
|
+
});
|
322
|
+
EOS
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_collection_proxy_on_collect
|
326
|
+
@generator.select('p').collect('a') { |para| para.show }
|
327
|
+
@generator.select('p').collect { |para| para.hide }
|
328
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
329
|
+
var a = $$("p").collect(function(value, index) {
|
330
|
+
return value.show();
|
331
|
+
});
|
332
|
+
$$("p").collect(function(value, index) {
|
333
|
+
return value.hide();
|
334
|
+
});
|
335
|
+
EOS
|
336
|
+
@generator = create_generator
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_collection_proxy_with_grep
|
340
|
+
@generator.select('p').grep 'a', /^a/ do |value|
|
341
|
+
@generator << '(value.className == "welcome")'
|
342
|
+
end
|
343
|
+
@generator.select('p').grep 'b', /b$/ do |value, index|
|
344
|
+
@generator.call 'alert', value
|
345
|
+
@generator << '(value.className == "welcome")'
|
346
|
+
end
|
347
|
+
|
348
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
349
|
+
var a = $$("p").grep(/^a/, function(value, index) {
|
350
|
+
return (value.className == "welcome");
|
351
|
+
});
|
352
|
+
var b = $$("p").grep(/b$/, function(value, index) {
|
353
|
+
alert(value);
|
354
|
+
return (value.className == "welcome");
|
355
|
+
});
|
356
|
+
EOS
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_collection_proxy_with_inject
|
360
|
+
@generator.select('p').inject 'a', [] do |memo, value|
|
361
|
+
@generator << '(value.className == "welcome")'
|
362
|
+
end
|
363
|
+
@generator.select('p').inject 'b', nil do |memo, value, index|
|
364
|
+
@generator.call 'alert', memo
|
365
|
+
@generator << '(value.className == "welcome")'
|
366
|
+
end
|
367
|
+
|
368
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
369
|
+
var a = $$("p").inject([], function(memo, value, index) {
|
370
|
+
return (value.className == "welcome");
|
371
|
+
});
|
372
|
+
var b = $$("p").inject(null, function(memo, value, index) {
|
373
|
+
alert(memo);
|
374
|
+
return (value.className == "welcome");
|
375
|
+
});
|
376
|
+
EOS
|
377
|
+
end
|
378
|
+
|
379
|
+
def test_collection_proxy_with_pluck
|
380
|
+
@generator.select('p').pluck('a', 'className')
|
381
|
+
assert_equal %(var a = $$("p").pluck("className");), @generator.to_s
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_collection_proxy_with_zip
|
385
|
+
ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('a', [4, 5, 6], [7, 8, 9])
|
386
|
+
ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('b', [4, 5, 6], [7, 8, 9]) do |array|
|
387
|
+
@generator.call 'array.reverse'
|
388
|
+
end
|
389
|
+
|
390
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
391
|
+
var a = [1, 2, 3].zip([4, 5, 6], [7, 8, 9]);
|
392
|
+
var b = [1, 2, 3].zip([4, 5, 6], [7, 8, 9], function(array) {
|
393
|
+
return array.reverse();
|
394
|
+
});
|
395
|
+
EOS
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_collection_proxy_with_find_all
|
399
|
+
@generator.select('p').find_all 'a' do |value, index|
|
400
|
+
@generator << '(value.className == "welcome")'
|
401
|
+
end
|
402
|
+
|
403
|
+
assert_equal <<-EOS.strip, @generator.to_s
|
404
|
+
var a = $$("p").findAll(function(value, index) {
|
405
|
+
return (value.className == "welcome");
|
406
|
+
});
|
407
|
+
EOS
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_debug_rjs
|
411
|
+
ActionView::Base.debug_rjs = true
|
412
|
+
@generator['welcome'].replace_html 'Welcome'
|
413
|
+
assert_equal "try {\n$(\"welcome\").update(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('$(\\\"welcome\\\").update(\\\"Welcome\\\");'); throw e }", @generator.to_s
|
414
|
+
ensure
|
415
|
+
ActionView::Base.debug_rjs = false
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_class_proxy
|
419
|
+
@generator.form.focus('my_field')
|
420
|
+
assert_equal "Form.focus(\"my_field\");", @generator.to_s
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|