O'Reilly logo

Test Driven Ajax (on Rails) by Phlip

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conclusion(s)

For the insanely curious, here's the complete block of JavaScript that goes, via javascript:void() and update_iframe(), into the inner Wiki's IFRAME src attribute, reformatted:

function report(diagnostic)
{
  var transcript = window.parent.document.getElementById('transcript');
  transcript.innerHTML += diagnostic;
  onComplete ();
}

function onComplete()
{
  window.parent.location.href =
    'javascript:void(find_faults("TestWiki","//test_WikiTestPage"))';
}

if (!(!/Exception /.test (document.title)))
  report
    ("<span class='fault'>failed: !/Exception/.test(document.title)</span><br/>");

document.getElementById('link_node:test_uncle_wiggily').click ();

{
  var handler = {
    onComplete: function(request)
    {
      if (/^\\/wiki\\/find_faults.*test_uncle_wiggily/.test(request.url))
        {
        Ajax.Responders.unregister(handler);

        if (!($("title_node:test_uncle_wiggily").className == "wiki_red"))
          report( "<span class='fault'>" +
                   "failed: $(&quot;title_node:test_uncle_wiggily&quot;).
className == &quot;wiki_red&quot;" +
                  "</span><br/>" );
        }
      }
    };
  Ajax.Responders.register(handler);
}
onComplete();

When you click the test link on the outer Wiki, all these things happen:

  • link_to_remote calls the server, which dispatches to our controller

  • Our controller responds with JavaScript

  • The JavaScript creates an IFRAME and sets its onload handler

  • The load event stuffs more JavaScript into the IFRAME src

  • That JavaScript clicks the inner Wiki's test button

  • This whole sequence runs again, inside the inner Wiki

  • Its test script fails ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required