From 4f7a85d2c66f100f83e2fe264e1f03bf079f13dc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 30 Jan 2010 14:39:41 -0600 Subject: Revert "Merge branch 'rails/master' into ujs" This reverts commit 3aa1ea1ae4baa4a03d03644e798eeb98a4745785, reversing changes made to 2c12a71378d2146c822acb389b00b866f6420ff5. Conflicts: actionpack/lib/action_view/helpers/javascript_helper.rb actionpack/lib/action_view/helpers/url_helper.rb actionpack/test/template/url_helper_test.rb --- actionpack/test/template/prototype_helper_test.rb | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) (limited to 'actionpack/test/template/prototype_helper_test.rb') diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 86f9c231c0..9225153798 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -82,6 +82,199 @@ class PrototypeHelperTest < PrototypeHelperBaseTest super end + def test_link_to_remote + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :success => "alert(request.responseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :type => :synchronous) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :position => :bottom) + end + + def test_link_to_remote_html_options + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } }) + end + + def test_link_to_remote_url_quote_escaping + assert_dom_equal %(Remote), + link_to_remote("Remote", { :url => { :action => "whatnot's" } }) + end + + def test_button_to_remote + assert_dom_equal %(), + button_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" }) + assert_dom_equal %(), + button_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(), + button_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(), + button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" }) + assert_dom_equal %(), + button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) + end + + def test_periodically_call_remote + assert_dom_equal %(), + periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" }) + end + + def test_periodically_call_remote_with_frequency + assert_dom_equal( + "", + periodically_call_remote(:frequency => 2) + ) + end + + def test_form_remote_tag + assert_dom_equal %(
), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) + assert_dom_equal %(), + form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast }) + assert_dom_equal %(), + form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast }) + assert_dom_equal %(), + form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast }) + end + + def test_form_remote_tag_with_method + assert_dom_equal %(
), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :html => { :method => :put }) + end + + def test_form_remote_tag_with_block_in_erb + __in_erb_template = '' + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { concat "Hello world!" } + assert_dom_equal %(Hello world!
), output_buffer + end + + def test_remote_form_for_with_record_identification_with_new_record + remote_form_for(@record, {:html => { :id => 'create-author' }}) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + def test_remote_form_for_with_record_identification_without_html_options + remote_form_for(@record) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + def test_remote_form_for_with_record_identification_with_existing_record + @record.save + remote_form_for(@record) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + def test_remote_form_for_with_new_object_in_list + remote_form_for([@author, @article]) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + def test_remote_form_for_with_existing_object_in_list + @author.save + @article.save + remote_form_for([@author, @article]) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + def test_on_callbacks + callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure] + callbacks.each do |callback| + assert_dom_equal %(
), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();") + assert_dom_equal %(), + form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();") + assert_dom_equal %(), + form_remote_tag(:update => { :failure => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();") + assert_dom_equal %(), + form_remote_tag(:update => { :success => "glass_of_beer", :failure => "glass_of_water" }, :url => { :action => :fast }, callback=>"monkeys();") + end + + #HTTP status codes 200 up to 599 have callbacks + #these should work + 100.upto(599) do |callback| + assert_dom_equal %(), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();") + end + + #test 200 and 404 + assert_dom_equal %(), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, 200=>"monkeys();", 404=>"bananas();") + + #these shouldn't + 1.upto(99) do |callback| + assert_dom_equal %(), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();") + end + 600.upto(999) do |callback| + assert_dom_equal %(), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();") + end + + #test ultimate combo + assert_dom_equal %(), + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :loading => "c1()", :success => "s()", :failure => "f();", :complete => "c();", 200=>"monkeys();", 404=>"bananas();") + + end + + def test_submit_to_remote + assert_dom_equal %(), + submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle") + end + + def test_observe_field + assert_dom_equal %(), + observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" }) + end + + def test_observe_field_using_with_option + expected = %() + assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id') + assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + encodeURIComponent(value)") + end + + def test_observe_field_using_json_in_with_option + expected = %() + assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}") + end + + def test_observe_field_using_function_for_callback + assert_dom_equal %(), + observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')") + end + + def test_observe_form + assert_dom_equal %(), + observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" }) + end + + def test_observe_form_using_function_for_callback + assert_dom_equal %(), + observe_form("cart", :frequency => 2, :function => "alert('Form changed')") + end + + def test_observe_field_without_frequency + assert_dom_equal %(), + observe_field("glass") + end + def test_update_page old_output_buffer = output_buffer -- cgit v1.2.3