diff options
Diffstat (limited to 'actionpack/test/template/javascript_helper_test.rb')
-rw-r--r-- | actionpack/test/template/javascript_helper_test.rb | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index f49b763881..c5c2a6b952 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -17,7 +17,7 @@ class JavaScriptHelperTest < ActionView::TestCase ActiveSupport.escape_html_entities_in_json = true @template = self end - + def teardown ActiveSupport.escape_html_entities_in_json = false end @@ -60,6 +60,35 @@ class JavaScriptHelperTest < ActionView::TestCase button_to_function("Greeting") end + def test_link_to_function + assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>), + link_to_function("Greeting", "alert('Hello world!')") + end + + def test_link_to_function_with_existing_onclick + assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>), + link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')") + end + + def test_link_to_function_with_rjs_block + html = link_to_function( "Greet me!" ) do |page| + page.replace_html 'header', "<h1>Greetings</h1>" + end + assert_dom_equal %(<a href="#" onclick="Element.update("header", "\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E");; return false;">Greet me!</a>), html + end + + def test_link_to_function_with_rjs_block_and_options + html = link_to_function( "Greet me!", :class => "updater" ) do |page| + page.replace_html 'header', "<h1>Greetings</h1>" + end + assert_dom_equal %(<a href="#" class="updater" onclick="Element.update("header", "\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E");; return false;">Greet me!</a>), html + end + + def test_link_to_function_with_href + assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>), + link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') + end + def test_javascript_tag self.output_buffer = 'foo' |