Skip to content
This repository
Browse code

fixed failing tests

  • Loading branch information...
commit 77fc50a08be40abe7eea715755b5497f0e9b91f5 1 parent c44682f
Stefan Penner stefanpenner authored
114 actionpack/test/javascript/ajax_test.rb
... ... @@ -0,0 +1,114 @@
  1 +require "abstract_unit"
  2 +
  3 +class AjaxTestCase < ActiveSupport::TestCase
  4 + include ActionView::Helpers::AjaxHelper
  5 + include ActionView::Helpers::TagHelper
  6 +
  7 + def assert_html(html, matches)
  8 + matches.each do |match|
  9 + assert_match Regexp.new(Regexp.escape(match)), html
  10 + end
  11 + end
  12 +
  13 + def self.assert_callbacks_work(&blk)
  14 + define_method(:assert_callbacks_work, &blk)
  15 +
  16 + [:complete, :failure, :success, :interactive, :loaded, :loading, 404].each do |callback|
  17 + test "#{callback} callback" do
  18 + markup = assert_callbacks_work(callback)
  19 + assert_html markup, %W(data-#{callback}-code="undoRequestCompleted\(request\)")
  20 + end
  21 + end
  22 + end
  23 +end
  24 +
  25 +class LinkToRemoteTest < AjaxTestCase
  26 + def url_for(hash)
  27 + "/blog/destroy/4"
  28 + end
  29 +
  30 + def link(options = {})
  31 + link_to_remote("Delete this post", "/blog/destroy/4", options)
  32 + end
  33 +
  34 + test "with no update" do
  35 + assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true")
  36 + end
  37 +
  38 + test "basic" do
  39 + assert_html link(:update => "#posts"),
  40 + %w(data-update-success="#posts")
  41 + end
  42 +
  43 + test "using a url hash" do
  44 + link = link_to_remote("Delete this post", {:controller => :blog}, :update => "#posts")
  45 + assert_html link, %w(href="/blog/destroy/4" data-update-success="#posts")
  46 + end
  47 +
  48 + test "with :html options" do
  49 + expected = %{<a href="/blog/destroy/4" data-custom="me" data-remote="true" data-update-success="#posts">Delete this post</a>}
  50 + assert_equal expected, link(:update => "#posts", :html => {"data-custom" => "me"})
  51 + end
  52 +
  53 + test "with a hash for :update" do
  54 + link = link(:update => {:success => "#posts", :failure => "#error"})
  55 + assert_html link, %w(data-remote="true" data-update-success="#posts" data-update-failure="#error")
  56 + end
  57 +
  58 + test "with positional parameters" do
  59 + link = link(:position => :top, :update => "#posts")
  60 + assert_match /data\-update\-position="top"/, link
  61 + end
  62 +
  63 + test "with an optional method" do
  64 + link = link(:method => "delete")
  65 + assert_match /data-method="delete"/, link
  66 + end
  67 +
  68 + class LegacyLinkToRemoteTest < AjaxTestCase
  69 + include ActionView::Helpers::AjaxHelper::Rails2Compatibility
  70 +
  71 + def link(options)
  72 + link_to_remote("Delete this post", "/blog/destroy/4", options)
  73 + end
  74 +
  75 + test "basic link_to_remote with :url =>" do
  76 + expected = %{<a href="/blog/destroy/4" data-remote="true" data-update-success="#posts">Delete this post</a>}
  77 + assert_equal expected,
  78 + link_to_remote("Delete this post", :url => "/blog/destroy/4", :update => "#posts")
  79 + end
  80 +
  81 + assert_callbacks_work do |callback|
  82 + link(callback => "undoRequestCompleted(request)")
  83 + end
  84 + end
  85 +end
  86 +
  87 +class ButtonToRemoteTest < AjaxTestCase
  88 + def button(options, html = {})
  89 + button_to_remote("Remote outpost", options, html)
  90 + end
  91 +
  92 + def url_for(*)
  93 + "/whatnot"
  94 + end
  95 +
  96 + class StandardTest < ButtonToRemoteTest
  97 + test "basic" do
  98 + button = button({:url => {:action => "whatnot"}}, {:class => "fine"})
  99 + [/input/, /class="fine"/, /type="button"/, /value="Remote outpost"/,
  100 + /data-url="\/whatnot"/].each do |match|
  101 + assert_match match, button
  102 + end
  103 + end
  104 + end
  105 +
  106 + class LegacyButtonToRemoteTest < ButtonToRemoteTest
  107 + include ActionView::Helpers::AjaxHelper::Rails2Compatibility
  108 +
  109 + assert_callbacks_work do |callback|
  110 + button(callback => "undoRequestCompleted(request)")
  111 + end
  112 + end
  113 +
  114 +end
22 actionpack/test/template/ajax_test.rb
@@ -54,11 +54,11 @@ def link(options = {})
54 54 end
55 55
56 56 test "with no update" do
57   - assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true")
  57 + assert_html link, %w(href="/blog/destroy/3" Delete\ this\ post data-remote="true")
58 58 end
59 59
60 60 test "with :html options" do
61   - expected = %{<a href="/blog/destroy/4" data-custom="me" data-remote="true" data-update-success="#posts">Delete this post</a>}
  61 + expected = %{<a href="/blog/destroy/3" data-custom="me" data-remote="true" data-update-success="#posts">Delete this post</a>}
62 62 assert_equal expected, link(:update => "#posts", :html => {"data-custom" => "me"})
63 63 end
64 64
@@ -86,9 +86,9 @@ def link(options)
86 86 end
87 87
88 88 test "basic link_to_remote with :url =>" do
89   - expected = %{<a href="/blog/destroy/3" data-remote="true" data-update-success="#posts">Delete this post</a>}
  89 + expected = %{<a href="/blog/destroy/4" data-remote="true" data-update-success="#posts">Delete this post</a>}
90 90 assert_equal expected,
91   - link_to_remote("Delete this post", :url => "/blog/destroy/3", :update => "#posts")
  91 + link_to_remote("Delete this post", :url => "/blog/destroy/4", :update => "#posts")
92 92 end
93 93
94 94 assert_callbacks_work do |callback|
@@ -102,24 +102,10 @@ def button(options, html = {})
102 102 button_to_remote("Remote outpost", options, html)
103 103 end
104 104
105   -<<<<<<< HEAD:actionpack/test/template/ajax_test.rb
106   - def url_for(*)
107   - "/whatnot"
108   - end
109   -
110   - class StandardTest < ButtonToRemoteTest
111   - test "basic" do
112   - button = button({:url => {:action => "whatnot"}}, {:class => "fine"})
113   - [/input/, /class="fine"/, /type="button"/, /value="Remote outpost"/,
114   - /data-url="\/whatnot"/].each do |match|
115   - assert_match(match, button)
116   - end
117   -=======
118 105 class StandardTest < ButtonToRemoteTest
119 106 test "basic" do
120 107 assert_html button({:url => {:action => "whatnot"}}, {:class => "fine"}),
121 108 %w(input class="fine" type="button" value="Remote outpost" data-url="/url/hash")
122   ->>>>>>> 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
123 109 end
124 110 end
125 111

0 comments on commit 77fc50a

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