In the following test I was checkeing out of the javascript that is generated using the render :update call. Note that using a functional test is also a nice way to explore some of the prototype_helper functionality.
page.call 'mycall', 'a', 2, 3 # --> mycall("a", 2, 3);' page.my_class.my_method 'a', 12 # --> MyClass.myMethod("a", 12);
Now one issue I had was figuring out how to pass a javascript variable to a javascript call. I.e. mycall(p1, p2). The only way I found it so to use the page << method. After a little hacking I managed to pass javascript variables to a method using the page.call. See the use of the JsArugmentList class here after. Note it does get’s a little cluttered and the page << remains easier to read. Please let me know if you find a more elegant way to achieve this.
require File.dirname(FILE) + ‘/../test_helper’
class RjsController < ActionController::Base
def rescue_action(e) raise e end;
class RjsControllerTest < Test::Unit::TestCase
def setup
@controller = RjsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_page_call
get :page_call
javascript = @response.body.split(“\n”)
assert_equal ‘mycall(“a”, 2, 3);’, javascript0
assert_equal ‘p1 = “str1”;’, javascript1
assert_equal ‘mycall(p1, p2);’, javascript2
assert_equal ‘mycall(p1, p2);’, javascript3
assert_equal ‘MyClass.myMethod(“a”, 12);’, javascript4
end
end