Skip to content

Instantly share code, notes, and snippets.

@pehrlich
Created September 11, 2012 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pehrlich/3702913 to your computer and use it in GitHub Desktop.
Save pehrlich/3702913 to your computer and use it in GitHub Desktop.
Implementing Google's hashbang/Ajax crawl with Jruby on Rails
class SiteController < ApplicationController
def index
# who the f*!@ knows how to make a rails route for a get parameter?
if frag = params[:'_escaped_fragment_']
# good read: (Akephalos)
# http://robots.thoughtbot.com/post/1658763359/thoughtbot-and-the-holy-grail
# http://robots.thoughtbot.com/post/4583605733/capybara-webkit
# todo: phantomjs (webkit based)
# https://github.com/jonleighton/poltergeist
render text: capybara(frag)
return
end
def capybara(path)
s = SignupTest.new(nil)
s.results(path)
end
class SignupTest < ActionController::IntegrationTest
include Capybara::DSL
def results(path)
#Capybara.current_driver = Capybara.javascript_driver # :selenium
require 'capybara/poltergeist'
Capybara.current_driver = :poltergeist
visit(path)
p "Capybara begin page load"
# http://stackoverflow.com/questions/9084134/timing-issues-when-checking-for-content-of-multiple-text-nodes-in-capybara
#wait_until wait until true is returned by the block (though it will timeout after a little bit). You can also pass it a timeout value, wait_until(5), to exit after the time allotted.
start_time = Time.now
page.wait_until(10) do # seconds, I hope
page.evaluate_script 'jQuery.active == 0'
end
p "Capybara finished page load in #{Time.now - start_time}"
#sleep(4)
page.body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment