Skip to content
Browse files

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.
  • Loading branch information...
1 parent a792ee5 commit c44682f6ab7f9b6dd3773752723aa8c46d019bde @foobarfighter foobarfighter committed with stefanpenner
Showing with 29 additions and 10 deletions.
  1. +1 −1 actionpack/lib/action_view/helpers/ajax_helper.rb
  2. +28 −9 actionpack/test/template/ajax_test.rb
View
2 actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -19,7 +19,7 @@ def link_to_remote(name, url, options = {})
html["data-remote"] = "true"
html.merge!(options)
-
+
url = url_for(url) if url.is_a?(Hash)
link_to(name, url, html)
end
View
37 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 @@ def self.assert_callbacks_work(&blk)
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 @@ def button(options, html = {})
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 StandardTest < ButtonToRemoteTest
/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

0 comments on commit c44682f

Please sign in to comment.
Something went wrong with that request. Please try again.