From c44682f6ab7f9b6dd3773752723aa8c46d019bde Mon Sep 17 00:00:00 2001 From: Bob Remeika Date: Wed, 23 Sep 2009 01:05:45 -0700 Subject: Implemented a fuller stub in AjaxTestCase for url_for because link_to calls url_for on all urls passed to it. Tests that were testing different input types for the url were failing because of this. --- actionpack/test/template/ajax_test.rb | 37 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/ajax_test.rb b/actionpack/test/template/ajax_test.rb index d212134d1d..afaa16874d 100644 --- a/actionpack/test/template/ajax_test.rb +++ b/actionpack/test/template/ajax_test.rb @@ -4,6 +4,17 @@ class AjaxTestCase < ActiveSupport::TestCase include ActionView::Helpers::AjaxHelper include ActionView::Helpers::TagHelper + def url_for(url) + case url + when Hash + "/url/hash" + when String + url + else + raise TypeError.new("Unsupported url type (#{url.class}) for this test helper") + end + end + def assert_html(html, matches) matches.each do |match| assert_match(Regexp.new(Regexp.escape(match)), html) @@ -23,26 +34,27 @@ class AjaxTestCase < ActiveSupport::TestCase end class LinkToRemoteTest < AjaxTestCase - def url_for(hash) - "/blog/destroy/4" - end - def link(options = {}) link_to_remote("Delete this post", "/blog/destroy/3", options) end - test "with no update" do - assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true") - end - test "basic" do assert_html link(:update => "#posts"), %w(data-update-success="#posts") end + test "using a url string" do + assert_html link_to_remote("Test", "/blog/update/1"), + %w(href="/blog/update/1") + end + test "using a url hash" do link = link_to_remote("Delete this post", {:controller => :blog}, :update => "#posts") - assert_html link, %w(href="/blog/destroy/4" data-update-success="#posts") + assert_html link, %w(href="/url/hash" data-update-success="#posts") + end + + test "with no update" do + assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true") end test "with :html options" do @@ -90,6 +102,7 @@ class ButtonToRemoteTest < AjaxTestCase button_to_remote("Remote outpost", options, html) end +<<<<<<< HEAD:actionpack/test/template/ajax_test.rb def url_for(*) "/whatnot" end @@ -101,6 +114,12 @@ class ButtonToRemoteTest < AjaxTestCase /data-url="\/whatnot"/].each do |match| assert_match(match, button) end +======= + class StandardTest < ButtonToRemoteTest + test "basic" do + assert_html button({:url => {:action => "whatnot"}}, {:class => "fine"}), + %w(input class="fine" type="button" value="Remote outpost" data-url="/url/hash") +>>>>>>> ea876bd... Implemented a fuller stub in AjaxTestCase for url_for because link_to calls url_for on all urls passed to it. Tests that were testing different input types for the url were failing because of this.:actionpack/test/javascript/ajax_test.rb end end -- cgit v1.2.3