Created
May 22, 2013 06:50
-
-
Save ngan/5625707 to your computer and use it in GitHub Desktop.
proof of concept for POST instead of GET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/config/routes.rb b/config/routes.rb | |
index acc4f35..39d734c 100644 | |
--- a/config/routes.rb | |
+++ b/config/routes.rb | |
@@ -1,5 +1,5 @@ | |
Teabag::Engine.routes.draw do | |
get "/fixtures/*filename", to: "spec#fixtures" | |
- get "/:suite", to: "spec#runner", defaults: { suite: "default" } | |
+ match "/:suite", to: "spec#runner", defaults: { suite: "default" } | |
root to: "spec#suites" | |
end | |
diff --git a/lib/teabag/drivers/phantomjs/runner.coffee b/lib/teabag/drivers/phantomjs/runner.coffee | |
index 0449718..f692902 100755 | |
--- a/lib/teabag/drivers/phantomjs/runner.coffee | |
+++ b/lib/teabag/drivers/phantomjs/runner.coffee | |
@@ -19,8 +19,29 @@ class @Runner | |
loadPage: -> | |
- @page.open(@url) | |
+ chunks = @url.split("?") | |
+ url = chunks[0] | |
+ console.log("URL: #{url}") | |
+ console.log("after: #{chunks[1]}") | |
+ params = for param in chunks[1].split("&") | |
+ param.match(/(.*)=(.*)/)[1..-1] | |
+ console.log(params) | |
+ | |
+ @page.setContent("<!DOCTYPE html><html><body></body></html>", "loader") | |
@page[name] = method for name, method of @pageCallbacks() | |
+ @page.evaluate((url, params) -> | |
+ form = document.createElement("form") | |
+ form.method = "post" | |
+ form.action = url | |
+ for param in params | |
+ input = document.createElement("input") | |
+ input.type = "hidden" | |
+ input.name = param[0] | |
+ input.value = param[1] | |
+ form.appendChild(input) | |
+ document.body.appendChild(form) | |
+ form.submit() | |
+ , url, params) | |
waitForResults: => | |
@@ -55,6 +76,8 @@ class @Runner | |
onLoadFinished: (status) => | |
+ return if @page.url == "loader" | |
+ console.info("status: #{status}, url: #{@page.url}, content: #{@page.content}") | |
return if @start | |
@start = new Date().getTime() | |
defined = @page.evaluate(-> window.Teabag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment