Compare commits

..

No commits in common. "f9318226b2ec5150a88a48f89482c4504cbdb26f" and "7c9627d5e0a0388ed00a2695edfa030f482d78a7" have entirely different histories.

View File

@ -323,7 +323,7 @@ module Stripe
c.save c.save
end end
should "updating an object should issue a POST request with the specified properties" do should "updating an object should issue a POST request with only the changed properties" do
stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123") stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
.with(body: { "description" => "another_mn" }) .with(body: { "description" => "another_mn" })
.to_return(body: JSON.generate(customer_fixture)) .to_return(body: JSON.generate(customer_fixture))
@ -348,7 +348,7 @@ module Stripe
end end
end end
should "updating should fail if api_key is nil" do should "updating should fail if api_key is overwritten with nil" do
Stripe::Customer.new("cus_123") Stripe::Customer.new("cus_123")
assert_raises TypeError do assert_raises TypeError do
Stripe::Customer.update("cus_123", {}, { api_key: nil }) Stripe::Customer.update("cus_123", {}, { api_key: nil })
@ -408,6 +408,18 @@ module Stripe
c.save c.save
end end
should "passing in a stripe_account header should pass it through on update" do
stub_request(:get, "#{Stripe.api_base}/v1/customers/cus_123")
.with(headers: { "Stripe-Account" => "acct_123" })
.to_return(body: JSON.generate(customer_fixture))
Stripe::Customer.retrieve("cus_123", stripe_account: "acct_123")
stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
.with(headers: { "Stripe-Account" => "acct_123" })
.to_return(body: JSON.generate(customer_fixture))
Stripe::Customer.update("cus_123", { description: "FOO" })
end
should "add key to nested objects on save" do should "add key to nested objects on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: { legal_entity: {
@ -424,7 +436,13 @@ module Stripe
acct.save acct.save
end end
should "update with a nested object" do should "add key to nested objects on update" do
Stripe::Account.construct_from(id: "myid",
business_profile: {
url: "example.com",
support_email: "test@example.com",
})
stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid") stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid")
.with(body: { business_profile: { name: "Bob" } }) .with(body: { business_profile: { name: "Bob" } })
.to_return(body: JSON.generate("id" => "myid")) .to_return(body: JSON.generate("id" => "myid"))
@ -445,6 +463,19 @@ module Stripe
acct.save acct.save
end end
should "update nothing if nothing changes" do
Stripe::Account.construct_from(id: "acct_id",
metadata: {
key: "value",
})
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_id")
.with(body: {})
.to_return(body: JSON.generate("id" => "acct_id"))
Stripe::Account.update("acct_id")
end
should "not save nested API resources" do should "not save nested API resources" do
ch = Stripe::Charge.construct_from(id: "ch_id", ch = Stripe::Charge.construct_from(id: "ch_id",
customer: { customer: {
@ -460,6 +491,20 @@ module Stripe
ch.save ch.save
end end
should "not update nested API resources" do
Stripe::Charge.construct_from(id: "ch_id",
customer: {
object: "customer",
id: "customer_id",
})
stub_request(:post, "#{Stripe.api_base}/v1/charges/ch_id")
.with(body: {})
.to_return(body: JSON.generate("id" => "ch_id"))
Stripe::Charge.update("ch_id", { customer: { description: "Bob" } })
end
should "correctly handle replaced nested objects on save" do should "correctly handle replaced nested objects on save" do
acct = Stripe::Account.construct_from( acct = Stripe::Account.construct_from(
id: "acct_123", id: "acct_123",
@ -480,6 +525,25 @@ module Stripe
acct.save acct.save
end end
should "correctly handle replaced nested objects on update" do
Stripe::Account.construct_from(
id: "acct_123",
company: {
name: "company_name",
address: {
line1: "test",
city: "San Francisco",
},
}
)
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_123")
.with(body: { company: { address: { line1: "Test2", city: "" } } })
.to_return(body: JSON.generate("id" => "my_id"))
Stripe::Account.update("acct_123", { company: { address: { line1: "Test2" } } })
end
should "correctly handle array setting on save" do should "correctly handle array setting on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: {}) legal_entity: {})
@ -492,6 +556,16 @@ module Stripe
acct.save acct.save
end end
should "correctly handle array setting on update" do
Stripe::Subscription.construct_from(id: "myid")
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/myid")
.with(body: { items: [{ plan: "foo", quantity: 2 }] })
.to_return(body: JSON.generate("id" => "myid"))
Stripe::Subscription.update("myid", { items: [{ plan: "foo", quantity: 2 }] })
end
should "correctly handle array insertion on save" do should "correctly handle array insertion on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: { legal_entity: {
@ -509,6 +583,19 @@ module Stripe
acct.save acct.save
end end
should "correctly handle array insertion on update" do
Stripe::Subscription.construct_from(id: "myid", items: [])
# Note that this isn't a perfect check because we're using webmock's
# data decoding, which isn't aware of the Stripe array encoding that we
# use here.
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/myid")
.with(body: { items: [{ plan: "foo", quantity: 2 }] })
.to_return(body: JSON.generate("id" => "myid"))
Stripe::Subscription.update("myid", { items: [{ plan: "foo", quantity: 2 }] })
end
should "correctly handle array updates on save" do should "correctly handle array updates on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: { legal_entity: {
@ -526,6 +613,23 @@ module Stripe
acct.save acct.save
end end
should "correctly handle array updates on update" do
Stripe::Subscription.construct_from(id: "myid",
items: [
{ plan: "foo", quantity: 2 },
{ plan: "bar", quantity: 2 },
])
# Note that this isn't a perfect check because we're using webmock's
# data decoding, which isn't aware of the Stripe array encoding that we
# use here.
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/myid")
.with(body: { items: [{ plan: "foos", quantity: 3 }, { plan: "bar", quantity: 3 }] })
.to_return(body: JSON.generate("id" => "myid"))
Stripe::Subscription.update("myid", { items: [{ plan: "foos", quantity: 3 }, { plan: "bar", quantity: 3 }] })
end
should "correctly handle array noops on save" do should "correctly handle array noops on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: { legal_entity: {
@ -540,6 +644,16 @@ module Stripe
acct.save acct.save
end end
should "correctly handle array noops on update" do
Stripe::Subscription.construct_from(id: "myid", items: [{ plan: "foo", quantity: 2 }])
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/myid")
.with(body: {})
.to_return(body: JSON.generate("id" => "myid"))
Stripe::Subscription.update("myid", {})
end
should "correctly handle hash noops on save" do should "correctly handle hash noops on save" do
acct = Stripe::Account.construct_from(id: "myid", acct = Stripe::Account.construct_from(id: "myid",
legal_entity: { legal_entity: {
@ -553,6 +667,19 @@ module Stripe
acct.save acct.save
end end
should "correctly handle hash noops on update" do
Stripe::Account.construct_from(id: "myid",
legal_entity: {
address: { line1: "1 Two Three" },
})
stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid")
.with(body: {})
.to_return(body: JSON.generate("id" => "myid"))
Stripe::Account.update("myid", {})
end
should "should create a new resource when an object without an id is saved" do should "should create a new resource when an object without an id is saved" do
account = Stripe::Account.construct_from(id: nil, account = Stripe::Account.construct_from(id: nil,
display_name: nil) display_name: nil)