Skip to content

Commit

Permalink
Use basic JSON.generate instead of make_response abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed Feb 14, 2017
1 parent 360d4e9 commit 3cf2ba3
Show file tree
Hide file tree
Showing 37 changed files with 253 additions and 257 deletions.
24 changes: 12 additions & 12 deletions test/stripe/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AccountTest < Test::Unit::TestCase
:email => "[email protected]",
})
stub_request(:get, "#{Stripe.api_base}/v1/account").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a = Stripe::Account.retrieve
assert_equal "[email protected]", a.email
assert !a.charges_enabled
Expand All @@ -23,7 +23,7 @@ class AccountTest < Test::Unit::TestCase
:email => "[email protected]",
})
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a = Stripe::Account.retrieve('acct_foo')
assert_equal "[email protected]", a.email
assert !a.charges_enabled
Expand Down Expand Up @@ -51,10 +51,10 @@ class AccountTest < Test::Unit::TestCase
should "be rejectable" do
account_data = {:id => 'acct_foo'}
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
to_return(body: make_response(account_data))
to_return(body: JSON.generate(account_data))

stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject").
to_return(body: make_response(account_data))
to_return(body: JSON.generate(account_data))

account = Stripe::Account.retrieve('acct_foo')
account.reject(:reason => 'fraud')
Expand All @@ -70,10 +70,10 @@ class AccountTest < Test::Unit::TestCase
}
}
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))

stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))

a = Stripe::Account.retrieve('acct_foo')
a.legal_entity.first_name = 'Bob'
Expand All @@ -87,7 +87,7 @@ class AccountTest < Test::Unit::TestCase
:business_name => 'ACME Corp',
}
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))

a = Stripe::Account.update('acct_foo', :business_name => "ACME Corp")
assert_equal('ACME Corp', a.business_name)
Expand All @@ -114,12 +114,12 @@ class AccountTest < Test::Unit::TestCase
should "be able to deauthorize an account" do
resp = {:id => 'acct_1234', :email => "[email protected]", :charge_enabled => false, :details_submitted => false}
stub_request(:get, "#{Stripe.api_base}/v1/account").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a = Stripe::Account.retrieve

stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
with(body: { 'client_id' => 'ca_1234', 'stripe_user_id' => a.id}).
to_return(body: make_response({ 'stripe_user_id' => a.id }))
to_return(body: JSON.generate({ 'stripe_user_id' => a.id }))
a.deauthorize('ca_1234', 'sk_test_1234')
end

Expand All @@ -142,12 +142,12 @@ class AccountTest < Test::Unit::TestCase
}
}
stub_request(:get, "#{Stripe.api_base}/v1/account").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a = Stripe::Account.retrieve

stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_1234/external_accounts").
with(body: { :external_account => 'btok_1234' }).
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a.external_accounts.create({:external_account => 'btok_1234'})
end

Expand All @@ -164,7 +164,7 @@ class AccountTest < Test::Unit::TestCase
}
}
stub_request(:get, "#{Stripe.api_base}/v1/account").
to_return(body: make_response(resp))
to_return(body: JSON.generate(resp))
a = Stripe::Account.retrieve
assert_equal(BankAccount, a.external_accounts.data[0].class)
end
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/api_operations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.protected_fields
should "post the correct parameters to the resource URL" do
stub_request(:post, "#{Stripe.api_base}/v1/updateableresources/id").
with(body: { foo: "bar" }).
to_return(body: make_response({ foo: "bar" }))
to_return(body: JSON.generate({ foo: "bar" }))
resource = UpdateableResource::update("id", { foo: "bar" })
assert_equal('bar', resource.foo)
end
Expand Down
Loading

0 comments on commit 3cf2ba3

Please sign in to comment.