Michael Klett
posted this on May 10, 2011 08:41 pm
def make_transactions_response
payment = [{:product_id => 4707,
:ending_balance_in_cents => 0,
:memo => "Yeah",
:id => Sham.unique_id,
:amount_in_cents => 2000,
:type => "Payment",
:success => true }]
charge = [{:product_id => 4707,
:ending_balance_in_cents => 2000,
:memo => "Basic Monthly",
:id => Sham.unique_id,
:amount_in_cents => 2000,
:type => "Charge",
:success => true }]
resp = payment + charge
FakeWeb.register_uri(:get, %r|#{test_domain}/subscriptions/\d+/transactions.xml$|, :status => 200, :body => resp.to_xml(:root => "transactions"))
FakeWeb.register_uri(:get, %r|#{test_domain}/subscriptions/\d+/transactions.xml\?kinds.*payment|, :status => 200, :body => payment.to_xml(:root => "transactions"))
FakeWeb.register_uri(:get, %r|#{test_domain}/subscriptions/\d+/transactions.xml\?kinds.*charge|, :status => 200, :body => charge.to_xml(:root => "transactions"))
end
resp is a successful subscription creation
resp2 is the same as resp but with the balance set to 0
FakeWeb.register_uri(:get, %r|#{test_domain}/subscriptions/\d+.xml|,
[{:status => 200, :body => resp.to_xml, :times => 2},
{:status => 200, :body => resp2.to_xml}])
Also I prefer using FakeWeb.allow_net_connect = false to alert me when I've missed a URL.##
I stole test_domain from the chargify gem. Here's the definition:
def test_domain
"#{Chargify::Base.connection.site.scheme}://#{Chargify::Base.connection.user}:#{Chargify::Base.connection.password}@#{Chargify::Base.connection.site.host}:#{Chargify::Base.connection.site.port}"
end