Skip to content

Instantly share code, notes, and snippets.

@aramisf
Last active August 29, 2015 14:16
Show Gist options
  • Save aramisf/099d4c2d51af810910a5 to your computer and use it in GitHub Desktop.
Save aramisf/099d4c2d51af810910a5 to your computer and use it in GitHub Desktop.
# /test/integration/subscribe_to_plan_test.rb
# rails 4.2.0
class SubscribeToPlanTest < ActionDispatch::IntegrationTest
def setup
@user = users(:user1)
@plan = plans(:plan)
@url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
@cmd = 'cmd=_express-checkout'
@token = 'token=EC-'
@user_action = 'useraction=commit'
end
test "should get paypal_checkout" do
login @user # Este eh um helper que faz um post no form de login
get paypal_checkout_path, plan_id: @plan.id
redirect?
assert_match @url, response.body
assert_match @cmd, response.body
assert_match /#{@token}[0-9A-Z]{17}/, response.body
assert_match @user_action, response.body
# Antes deste follow_redirect!, response.body contem: <html><body>You are being <a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&amp;token=EC-5N114043JK503121F&amp;useraction=commit">redirected</a>.</body></html>
follow_redirect!
# e depois do follow_redirect, response.body eh: <html><body>You are being <a href="https://www.sandbox.paypal.com/">redirected</a>.</body></html>
assert_match /#{@plan.description}/, response.body # Aqui o teste falha
assert_match /#{@plan.price}/, response.body
assert_match /#{paypal}/i, response.body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment