aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2006-10-19 22:03:27 +0000
committerSam Stephenson <sam@37signals.com>2006-10-19 22:03:27 +0000
commit351a224d90d5d485cb30743f1266ec2624ae7853 (patch)
treec29ff0df75b03db11dcfac6f2d95df233399d066 /actionpack/test
parentdbd0bd5e5c9946ffb48bf8651f81ebc6dd9b52e5 (diff)
downloadrails-351a224d90d5d485cb30743f1266ec2624ae7853.tar.gz
rails-351a224d90d5d485cb30743f1266ec2624ae7853.tar.bz2
rails-351a224d90d5d485cb30743f1266ec2624ae7853.zip
Add support for converting blocks into function arguments in JavaScriptGenerator#call and JavaScriptProxy#call.
Add JavaScriptGenerator#literal for wrapping a string in an object whose #to_json is the string itself. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5323 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/template/prototype_helper_test.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index a88d0f7c9f..0364ceea62 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -448,10 +448,37 @@ return (value.className == "welcome");
ensure
ActionView::Base.debug_rjs = false
end
+
+ def test_literal
+ literal = @generator.literal("function() {}")
+ assert_equal "function() {}", literal.to_json
+ assert_equal "", @generator.to_s
+ end
def test_class_proxy
@generator.form.focus('my_field')
assert_equal "Form.focus(\"my_field\");", @generator.to_s
end
+
+ def test_call_with_block
+ @generator.call(:before)
+ @generator.call(:my_method) do |p|
+ p[:one].show
+ p[:two].hide
+ end
+ @generator.call(:in_between)
+ @generator.call(:my_method_with_arguments, true, "hello") do |p|
+ p[:three].visual_effect(:highlight)
+ end
+ assert_equal "before();\nmy_method(function() { $(\"one\").show();\n$(\"two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { $(\"three\").visualEffect(\"highlight\"); });", @generator.to_s
+ end
+
+ def test_class_proxy_call_with_block
+ @generator.my_object.my_method do |p|
+ p[:one].show
+ p[:two].hide
+ end
+ assert_equal "MyObject.myMethod(function() { $(\"one\").show();\n$(\"two\").hide(); });", @generator.to_s
+ end
end