summaryrefslogtreecommitdiff
path: root/billing/lib
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-03 12:55:19 +0200
committerAzul <azul@leap.se>2013-07-17 10:47:14 +0200
commite4460bffe2e6a2a4b4edb663332aa57ac17b3370 (patch)
treefc47e214106765bc2937fde58b232dbea1b1ca5f /billing/lib
parentb51f300fe374e9eecf7e98266c96631fa3c8a278 (diff)
billing: fix integration test
This actually required three little fixes: * couchrest_session_store updated to 0.1.2 to make sure we store sessions * use BraintreeTestApp to proxy braintree requests that RackTest assumes are local * do not attempt to read status after a capybara request Also refactored the test a bit to set @user and login during setup.
Diffstat (limited to 'billing/lib')
-rw-r--r--billing/lib/braintree_test_app.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/billing/lib/braintree_test_app.rb b/billing/lib/braintree_test_app.rb
new file mode 100644
index 0000000..41c327d
--- /dev/null
+++ b/billing/lib/braintree_test_app.rb
@@ -0,0 +1,36 @@
+# RackTest assumes all requests to be local.
+# Braintree requests need to go out to a different server though.
+# So we use a middleware to catch these and send them out again.
+
+class BraintreeTestApp
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ @env = env
+ config = Braintree::Configuration.instantiate
+ if request.path =~ /\/merchants\/#{config.merchant_id}\/transparent_redirect_requests$/
+ #proxy post to braintree
+ uri = URI.parse(config.protocol + "://" + config.server + ":" +
+ config.port.to_s + request.path)
+ http = Net::HTTP.new(uri.host, uri.port)
+ res = http.post(uri.path, request.body.read)
+
+ if res.code == "303"
+ header_hash = res.header.to_hash
+ header_hash["location"].first.gsub!("http://localhost:3000/", "http://www.example.com/")
+ [303, {"location" => header_hash["location"].first}, ""]
+ else
+ raise "unexpected response from Braintree: expected a 303"
+ end
+ else
+ @app.call(env)
+ end
+ end
+
+ def request
+ @request = Rack::Request.new(@env)
+ end
+end
+