stripe 3.3.2 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +20 -0
- data/.rubocop_todo.yml +62 -0
- data/.travis.yml +1 -1
- data/Gemfile +19 -12
- data/History.txt +10 -0
- data/README.md +5 -1
- data/Rakefile +8 -5
- data/VERSION +1 -1
- data/bin/stripe-console +2 -2
- data/lib/stripe.rb +72 -74
- data/lib/stripe/account.rb +15 -17
- data/lib/stripe/alipay_account.rb +10 -7
- data/lib/stripe/api_operations/create.rb +1 -1
- data/lib/stripe/api_operations/delete.rb +1 -1
- data/lib/stripe/api_operations/list.rb +2 -2
- data/lib/stripe/api_operations/request.rb +5 -12
- data/lib/stripe/api_operations/save.rb +6 -6
- data/lib/stripe/api_resource.rb +7 -9
- data/lib/stripe/apple_pay_domain.rb +2 -2
- data/lib/stripe/application_fee.rb +5 -5
- data/lib/stripe/application_fee_refund.rb +5 -5
- data/lib/stripe/balance.rb +1 -1
- data/lib/stripe/balance_transaction.rb +2 -2
- data/lib/stripe/bank_account.rb +7 -7
- data/lib/stripe/bitcoin_receiver.rb +4 -2
- data/lib/stripe/bitcoin_transaction.rb +3 -1
- data/lib/stripe/card.rb +5 -5
- data/lib/stripe/charge.rb +18 -18
- data/lib/stripe/country_spec.rb +2 -2
- data/lib/stripe/coupon.rb +1 -1
- data/lib/stripe/customer.rb +23 -23
- data/lib/stripe/dispute.rb +3 -3
- data/lib/stripe/ephemeral_key.rb +4 -4
- data/lib/stripe/errors.rb +4 -4
- data/lib/stripe/event.rb +1 -1
- data/lib/stripe/file_upload.rb +5 -5
- data/lib/stripe/invoice.rb +7 -7
- data/lib/stripe/invoice_item.rb +1 -1
- data/lib/stripe/invoice_line_item.rb +1 -1
- data/lib/stripe/list_object.rb +14 -18
- data/lib/stripe/login_link.rb +3 -3
- data/lib/stripe/oauth.rb +15 -13
- data/lib/stripe/order.rb +5 -5
- data/lib/stripe/order_return.rb +1 -1
- data/lib/stripe/payout.rb +3 -3
- data/lib/stripe/plan.rb +1 -1
- data/lib/stripe/product.rb +1 -1
- data/lib/stripe/recipient.rb +3 -2
- data/lib/stripe/recipient_transfer.rb +1 -2
- data/lib/stripe/refund.rb +1 -1
- data/lib/stripe/reversal.rb +5 -5
- data/lib/stripe/singleton_api_resource.rb +3 -3
- data/lib/stripe/sku.rb +1 -1
- data/lib/stripe/source.rb +13 -10
- data/lib/stripe/stripe_client.rb +149 -169
- data/lib/stripe/stripe_object.rb +77 -76
- data/lib/stripe/subscription.rb +5 -5
- data/lib/stripe/subscription_item.rb +2 -2
- data/lib/stripe/three_d_secure.rb +1 -1
- data/lib/stripe/token.rb +1 -1
- data/lib/stripe/transfer.rb +3 -3
- data/lib/stripe/util.rb +77 -62
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe/webhook.rb +14 -10
- data/stripe.gemspec +14 -14
- data/test/stripe/account_test.rb +69 -81
- data/test/stripe/alipay_account_test.rb +19 -1
- data/test/stripe/api_operations_test.rb +7 -7
- data/test/stripe/api_resource_test.rb +224 -260
- data/test/stripe/apple_pay_domain_test.rb +8 -8
- data/test/stripe/application_fee_refund_test.rb +8 -8
- data/test/stripe/application_fee_test.rb +3 -3
- data/test/stripe/balance_test.rb +2 -2
- data/test/stripe/bank_account_test.rb +9 -11
- data/test/stripe/charge_test.rb +11 -11
- data/test/stripe/country_spec_test.rb +4 -4
- data/test/stripe/coupon_test.rb +10 -10
- data/test/stripe/customer_card_test.rb +11 -15
- data/test/stripe/customer_test.rb +26 -27
- data/test/stripe/dispute_test.rb +8 -8
- data/test/stripe/ephemeral_key_test.rb +14 -14
- data/test/stripe/errors_test.rb +2 -2
- data/test/stripe/file_upload_test.rb +26 -28
- data/test/stripe/invoice_item_test.rb +14 -14
- data/test/stripe/invoice_line_item_test.rb +1 -1
- data/test/stripe/invoice_test.rb +37 -37
- data/test/stripe/list_object_test.rb +60 -76
- data/test/stripe/login_link_test.rb +14 -14
- data/test/stripe/oauth_test.rb +42 -50
- data/test/stripe/order_return_test.rb +5 -5
- data/test/stripe/order_test.rb +12 -12
- data/test/stripe/payout_test.rb +9 -9
- data/test/stripe/plan_test.rb +9 -9
- data/test/stripe/product_test.rb +8 -8
- data/test/stripe/recipient_test.rb +9 -10
- data/test/stripe/refund_test.rb +9 -9
- data/test/stripe/reversal_test.rb +10 -10
- data/test/stripe/sku_test.rb +8 -8
- data/test/stripe/source_test.rb +14 -16
- data/test/stripe/stripe_client_test.rb +235 -266
- data/test/stripe/stripe_object_test.rb +163 -147
- data/test/stripe/stripe_response_test.rb +4 -3
- data/test/stripe/subscription_item_test.rb +11 -11
- data/test/stripe/subscription_test.rb +14 -14
- data/test/stripe/three_d_secure_test.rb +2 -2
- data/test/stripe/transfer_test.rb +8 -8
- data/test/stripe/util_test.rb +59 -57
- data/test/stripe/webhook_test.rb +18 -16
- data/test/stripe_test.rb +4 -4
- data/test/test_data.rb +26 -26
- data/test/test_helper.rb +29 -25
- metadata +6 -10
- data/test/stripe/bitcoin_receiver_test.rb +0 -67
- data/test/stripe/bitcoin_transaction_test.rb +0 -19
- data/test/stripe/recipient_card_test.rb +0 -44
@@ -1,11 +1,11 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class StripeObjectTest < Test::Unit::TestCase
|
5
5
|
should "implement #==" do
|
6
|
-
obj1 = Stripe::StripeObject.construct_from(
|
7
|
-
obj2 = Stripe::StripeObject.construct_from(
|
8
|
-
obj3 = Stripe::StripeObject.construct_from(
|
6
|
+
obj1 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
7
|
+
obj2 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
8
|
+
obj3 = Stripe::StripeObject.construct_from(id: 1, foo: "rab")
|
9
9
|
|
10
10
|
assert obj1 == obj2
|
11
11
|
refute obj1 == obj3
|
@@ -15,66 +15,118 @@ module Stripe
|
|
15
15
|
obj = Stripe::StripeObject.construct_from({})
|
16
16
|
refute obj.deleted?
|
17
17
|
|
18
|
-
obj = Stripe::StripeObject.construct_from(
|
18
|
+
obj = Stripe::StripeObject.construct_from(deleted: false)
|
19
19
|
refute obj.deleted?
|
20
20
|
|
21
|
-
obj = Stripe::StripeObject.construct_from(
|
21
|
+
obj = Stripe::StripeObject.construct_from(deleted: true)
|
22
22
|
assert obj.deleted?
|
23
23
|
end
|
24
24
|
|
25
25
|
should "implement #respond_to" do
|
26
|
-
obj = Stripe::StripeObject.construct_from(
|
26
|
+
obj = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
27
27
|
assert obj.respond_to?(:id)
|
28
28
|
assert obj.respond_to?(:foo)
|
29
29
|
assert !obj.respond_to?(:baz)
|
30
30
|
end
|
31
31
|
|
32
32
|
should "marshal be insensitive to strings vs. symbols when constructin" do
|
33
|
-
obj = Stripe::StripeObject.construct_from(
|
33
|
+
obj = Stripe::StripeObject.construct_from(:id => 1, "name" => "Stripe")
|
34
34
|
assert_equal 1, obj[:id]
|
35
|
-
assert_equal
|
35
|
+
assert_equal "Stripe", obj[:name]
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
:
|
43
|
-
# StripeClient is not serializable and is expected to be removed
|
44
|
-
# when marshalling StripeObjects
|
45
|
-
:client => StripeClient.active_client,
|
38
|
+
context "#deep_copy" do
|
39
|
+
should "produce a deep copy" do
|
40
|
+
opts = {
|
41
|
+
api_base: Stripe.api_base,
|
42
|
+
api_key: "apikey",
|
46
43
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
values = {
|
45
|
+
id: 1,
|
46
|
+
name: "Stripe",
|
47
|
+
arr: [
|
48
|
+
StripeObject.construct_from({ id: "index0" }, opts),
|
49
|
+
"index1",
|
50
|
+
2,
|
51
|
+
],
|
52
|
+
map: {
|
53
|
+
:"0" => StripeObject.construct_from({ id: "index0" }, opts),
|
54
|
+
:"1" => "index1",
|
55
|
+
:"2" => 2,
|
56
|
+
},
|
57
|
+
}
|
58
|
+
|
59
|
+
# it's not good to test methods with `#send` like this, but I've done
|
60
|
+
# it in the interest of trying to keep `.deep_copy` as internal as
|
61
|
+
# possible
|
62
|
+
copy_values = Stripe::StripeObject.send(:deep_copy, values)
|
63
|
+
|
64
|
+
# we can't compare the hashes directly because they have embedded
|
65
|
+
# objects which are different from each other
|
66
|
+
assert_equal values[:id], copy_values[:id]
|
67
|
+
assert_equal values[:name], copy_values[:name]
|
68
|
+
|
69
|
+
assert_equal values[:arr].length, copy_values[:arr].length
|
70
|
+
|
71
|
+
# internal values of the copied StripeObject should be the same
|
72
|
+
# (including opts), but the object itself should be new (hence the
|
73
|
+
# refutation of equality on #object_id)
|
74
|
+
assert_equal values[:arr][0][:id], copy_values[:arr][0][:id]
|
75
|
+
refute_equal values[:arr][0].object_id, copy_values[:arr][0].object_id
|
76
|
+
assert_equal values[:arr][0].instance_variable_get(:@opts),
|
77
|
+
copy_values[:arr][0].instance_variable_get(:@opts)
|
78
|
+
|
79
|
+
# scalars however, can be compared
|
80
|
+
assert_equal values[:arr][1], copy_values[:arr][1]
|
81
|
+
assert_equal values[:arr][2], copy_values[:arr][2]
|
82
|
+
|
83
|
+
# and a similar story with the hash
|
84
|
+
assert_equal values[:map].keys, copy_values[:map].keys
|
85
|
+
assert_equal values[:map][:"0"][:id], copy_values[:map][:"0"][:id]
|
86
|
+
refute_equal values[:map][:"0"].object_id, copy_values[:map][:"0"].object_id
|
87
|
+
assert_equal values[:map][:"0"].instance_variable_get(:@opts),
|
88
|
+
copy_values[:map][:"0"].instance_variable_get(:@opts)
|
89
|
+
assert_equal values[:map][:"1"], copy_values[:map][:"1"]
|
90
|
+
assert_equal values[:map][:"2"], copy_values[:map][:"2"]
|
91
|
+
end
|
92
|
+
|
93
|
+
should "not copy a client" do
|
94
|
+
opts = {
|
95
|
+
api_key: "apikey",
|
96
|
+
client: StripeClient.active_client,
|
97
|
+
}
|
98
|
+
values = { id: 1, name: "Stripe" }
|
99
|
+
|
100
|
+
obj = Stripe::StripeObject.construct_from(values, opts)
|
101
|
+
copy_obj = Stripe::StripeObject.send(:deep_copy, obj)
|
102
|
+
|
103
|
+
assert_equal values, copy_obj.instance_variable_get(:@values)
|
104
|
+
assert_equal opts.reject { |k, _v| k == :client },
|
105
|
+
copy_obj.instance_variable_get(:@opts)
|
106
|
+
end
|
53
107
|
end
|
54
108
|
|
55
109
|
should "recursively call to_hash on its values" do
|
56
110
|
# deep nested hash (when contained in an array) or StripeObject
|
57
|
-
nested_hash = { :
|
111
|
+
nested_hash = { id: 7, foo: "bar" }
|
58
112
|
nested = Stripe::StripeObject.construct_from(nested_hash)
|
59
113
|
|
60
|
-
obj = Stripe::StripeObject.construct_from(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
:list => [nested]
|
66
|
-
})
|
114
|
+
obj = Stripe::StripeObject.construct_from(id: 1,
|
115
|
+
# simple hash that contains a StripeObject to help us test deep
|
116
|
+
# recursion
|
117
|
+
nested: { object: "list", data: [nested] },
|
118
|
+
list: [nested])
|
67
119
|
|
68
120
|
expected_hash = {
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
121
|
+
id: 1,
|
122
|
+
nested: { object: "list", data: [nested_hash] },
|
123
|
+
list: [nested_hash],
|
72
124
|
}
|
73
125
|
assert_equal expected_hash, obj.to_hash
|
74
126
|
end
|
75
127
|
|
76
128
|
should "assign question mark accessors for booleans" do
|
77
|
-
obj = Stripe::StripeObject.construct_from(
|
129
|
+
obj = Stripe::StripeObject.construct_from(id: 1, bool: true, not_bool: "bar")
|
78
130
|
assert obj.respond_to?(:bool?)
|
79
131
|
assert obj.bool?
|
80
132
|
refute obj.respond_to?(:not_bool?)
|
@@ -88,27 +140,27 @@ module Stripe
|
|
88
140
|
end
|
89
141
|
|
90
142
|
should "mass assign values with #update_attributes" do
|
91
|
-
obj = Stripe::StripeObject.construct_from(
|
92
|
-
obj.update_attributes(:
|
143
|
+
obj = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
144
|
+
obj.update_attributes(name: "STRIPE")
|
93
145
|
assert_equal "STRIPE", obj.name
|
94
146
|
|
95
147
|
# unfortunately, we even assign unknown properties to duplicate the
|
96
148
|
# behavior that we currently have via magic accessors with
|
97
149
|
# method_missing
|
98
|
-
obj.update_attributes(:
|
150
|
+
obj.update_attributes(unknown: "foo")
|
99
151
|
assert_equal "foo", obj.unknown
|
100
152
|
end
|
101
153
|
|
102
154
|
should "#update_attributes with a hash" do
|
103
155
|
obj = Stripe::StripeObject.construct_from({})
|
104
|
-
obj.update_attributes(:
|
156
|
+
obj.update_attributes(metadata: { foo: "bar" })
|
105
157
|
assert_equal Stripe::StripeObject, obj.metadata.class
|
106
158
|
end
|
107
159
|
|
108
160
|
should "create accessors when #update_attributes is called" do
|
109
161
|
obj = Stripe::StripeObject.construct_from({})
|
110
162
|
assert_equal false, obj.send(:metaclass).method_defined?(:foo)
|
111
|
-
obj.update_attributes(:
|
163
|
+
obj.update_attributes(foo: "bar")
|
112
164
|
assert_equal true, obj.send(:metaclass).method_defined?(:foo)
|
113
165
|
end
|
114
166
|
|
@@ -118,8 +170,8 @@ module Stripe
|
|
118
170
|
begin
|
119
171
|
obj = Stripe::StripeObject.construct_from({})
|
120
172
|
obj.refresh_from({}, {})
|
121
|
-
message = "NOTE: Stripe::StripeObject#refresh_from is "
|
122
|
-
|
173
|
+
message = "NOTE: Stripe::StripeObject#refresh_from is " \
|
174
|
+
"deprecated; use #update_attributes instead"
|
123
175
|
assert_match Regexp.new(message), $stderr.string
|
124
176
|
ensure
|
125
177
|
$stderr = old_stderr
|
@@ -127,14 +179,14 @@ module Stripe
|
|
127
179
|
end
|
128
180
|
|
129
181
|
should "pass opts down to children when initializing" do
|
130
|
-
opts = { :
|
182
|
+
opts = { custom: "opts" }
|
131
183
|
|
132
184
|
# customer comes with a `sources` list that makes a convenient object to
|
133
185
|
# perform tests on
|
134
186
|
obj = Stripe::StripeObject.construct_from({
|
135
187
|
sources: [
|
136
|
-
{}
|
137
|
-
]
|
188
|
+
{},
|
189
|
+
],
|
138
190
|
}, opts)
|
139
191
|
|
140
192
|
source = obj.sources.first
|
@@ -152,79 +204,63 @@ module Stripe
|
|
152
204
|
|
153
205
|
should "#serialize_params on a new object with a subobject" do
|
154
206
|
obj = Stripe::StripeObject.new
|
155
|
-
obj.metadata = { :
|
156
|
-
assert_equal({ :
|
157
|
-
|
207
|
+
obj.metadata = { foo: "bar" }
|
208
|
+
assert_equal({ metadata: { foo: "bar" } },
|
209
|
+
obj.serialize_params)
|
158
210
|
end
|
159
211
|
|
160
212
|
should "#serialize_params on a basic object" do
|
161
|
-
obj = Stripe::StripeObject.construct_from(
|
162
|
-
obj.update_attributes(:
|
163
|
-
assert_equal({ :
|
213
|
+
obj = Stripe::StripeObject.construct_from(foo: nil)
|
214
|
+
obj.update_attributes(foo: "bar")
|
215
|
+
assert_equal({ foo: "bar" }, obj.serialize_params)
|
164
216
|
end
|
165
217
|
|
166
218
|
should "#serialize_params on a more complex object" do
|
167
|
-
obj = Stripe::StripeObject.construct_from(
|
168
|
-
|
169
|
-
:bar => nil,
|
170
|
-
:baz => nil,
|
171
|
-
}),
|
172
|
-
})
|
219
|
+
obj = Stripe::StripeObject.construct_from(foo: Stripe::StripeObject.construct_from(bar: nil,
|
220
|
+
baz: nil))
|
173
221
|
obj.foo.bar = "newbar"
|
174
|
-
assert_equal({ :
|
175
|
-
|
222
|
+
assert_equal({ foo: { bar: "newbar" } },
|
223
|
+
obj.serialize_params)
|
176
224
|
end
|
177
225
|
|
178
226
|
should "#serialize_params on an array" do
|
179
|
-
obj = Stripe::StripeObject.construct_from(
|
180
|
-
:foo => nil,
|
181
|
-
})
|
227
|
+
obj = Stripe::StripeObject.construct_from(foo: nil)
|
182
228
|
obj.foo = ["new-value"]
|
183
|
-
assert_equal({ :
|
184
|
-
|
229
|
+
assert_equal({ foo: ["new-value"] },
|
230
|
+
obj.serialize_params)
|
185
231
|
end
|
186
232
|
|
187
233
|
should "#serialize_params on an array that shortens" do
|
188
|
-
obj = Stripe::StripeObject.construct_from(
|
189
|
-
:foo => ["0-index", "1-index", "2-index"],
|
190
|
-
})
|
234
|
+
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
191
235
|
obj.foo = ["new-value"]
|
192
|
-
assert_equal({ :
|
193
|
-
|
236
|
+
assert_equal({ foo: ["new-value"] },
|
237
|
+
obj.serialize_params)
|
194
238
|
end
|
195
239
|
|
196
240
|
should "#serialize_params on an array that lengthens" do
|
197
|
-
obj = Stripe::StripeObject.construct_from(
|
198
|
-
:foo => ["0-index", "1-index", "2-index"],
|
199
|
-
})
|
241
|
+
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
200
242
|
obj.foo = ["new-value"] * 4
|
201
|
-
assert_equal({ :
|
202
|
-
|
243
|
+
assert_equal({ foo: ["new-value"] * 4 },
|
244
|
+
obj.serialize_params)
|
203
245
|
end
|
204
246
|
|
205
247
|
should "#serialize_params on an array of hashes" do
|
206
|
-
obj = Stripe::StripeObject.construct_from(
|
207
|
-
:foo => nil,
|
208
|
-
})
|
248
|
+
obj = Stripe::StripeObject.construct_from(foo: nil)
|
209
249
|
obj.foo = [
|
210
|
-
Stripe::StripeObject.construct_from(
|
211
|
-
:bar => nil
|
212
|
-
})
|
250
|
+
Stripe::StripeObject.construct_from(bar: nil),
|
213
251
|
]
|
214
252
|
obj.foo[0].bar = "baz"
|
215
|
-
assert_equal({ :
|
216
|
-
|
253
|
+
assert_equal({ foo: [{ bar: "baz" }] },
|
254
|
+
obj.serialize_params)
|
217
255
|
end
|
218
256
|
|
219
257
|
should "#serialize_params doesn't include unchanged values" do
|
220
|
-
obj = Stripe::StripeObject.construct_from(
|
258
|
+
obj = Stripe::StripeObject.construct_from(foo: nil)
|
221
259
|
assert_equal({}, obj.serialize_params)
|
222
260
|
end
|
223
261
|
|
224
262
|
should "#serialize_params on an array that is unchanged" do
|
225
|
-
obj = Stripe::StripeObject.construct_from(
|
226
|
-
:foo => ["0-index", "1-index", "2-index"],
|
227
|
-
})
|
263
|
+
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
228
264
|
obj.foo = ["0-index", "1-index", "2-index"]
|
229
265
|
assert_equal({}, obj.serialize_params)
|
230
266
|
end
|
@@ -235,39 +271,37 @@ module Stripe
|
|
235
271
|
# using an #update_attributes will end up converting a Hash into a
|
236
272
|
# StripeObject
|
237
273
|
obj.metadata =
|
238
|
-
Stripe::StripeObject.construct_from(
|
274
|
+
Stripe::StripeObject.construct_from(foo: "bar")
|
239
275
|
|
240
276
|
serialized = obj.serialize_params
|
241
|
-
assert_equal({ :
|
277
|
+
assert_equal({ foo: "bar" }, serialized[:metadata])
|
242
278
|
end
|
243
279
|
|
244
280
|
should "#serialize_params with a StripeObject that's been replaced" do
|
245
|
-
obj = Stripe::StripeObject.construct_from(
|
246
|
-
:metadata => Stripe::StripeObject.construct_from({ :bar => 'foo' })
|
247
|
-
})
|
281
|
+
obj = Stripe::StripeObject.construct_from(metadata: Stripe::StripeObject.construct_from(bar: "foo"))
|
248
282
|
|
249
283
|
# Here we replace the object wholesale which means that the client must
|
250
284
|
# be able to blank out the values that were in the old object, but which
|
251
285
|
# are no longer present in the new one.
|
252
286
|
obj.metadata =
|
253
|
-
Stripe::StripeObject.construct_from(
|
287
|
+
Stripe::StripeObject.construct_from(baz: "foo")
|
254
288
|
|
255
289
|
serialized = obj.serialize_params
|
256
|
-
assert_equal({ :
|
290
|
+
assert_equal({ bar: "", baz: "foo" }, serialized[:metadata])
|
257
291
|
end
|
258
292
|
|
259
293
|
should "#serialize_params with an array of StripeObjects" do
|
260
294
|
obj = Stripe::StripeObject.construct_from({})
|
261
295
|
obj.metadata = [
|
262
|
-
Stripe::StripeObject.construct_from(
|
296
|
+
Stripe::StripeObject.construct_from(foo: "bar"),
|
263
297
|
]
|
264
298
|
|
265
299
|
serialized = obj.serialize_params
|
266
|
-
assert_equal([{ :
|
300
|
+
assert_equal([{ foo: "bar" }], serialized[:metadata])
|
267
301
|
end
|
268
302
|
|
269
303
|
should "#serialize_params and embed an API resource that's been set and has an ID" do
|
270
|
-
customer = Customer.construct_from(
|
304
|
+
customer = Customer.construct_from(id: "cus_123")
|
271
305
|
obj = Stripe::StripeObject.construct_from({})
|
272
306
|
|
273
307
|
# the key here is that the property is set explicitly (and therefore
|
@@ -275,14 +309,12 @@ module Stripe
|
|
275
309
|
obj.customer = customer
|
276
310
|
|
277
311
|
serialized = obj.serialize_params
|
278
|
-
assert_equal({ :
|
312
|
+
assert_equal({ customer: customer }, serialized)
|
279
313
|
end
|
280
314
|
|
281
315
|
should "#serialize_params and not include API resources that have not been set" do
|
282
|
-
customer = Customer.construct_from(
|
283
|
-
obj = Stripe::StripeObject.construct_from(
|
284
|
-
:customer => customer
|
285
|
-
})
|
316
|
+
customer = Customer.construct_from(id: "cus_123")
|
317
|
+
obj = Stripe::StripeObject.construct_from(customer: customer)
|
286
318
|
|
287
319
|
serialized = obj.serialize_params
|
288
320
|
assert_equal({}, serialized)
|
@@ -292,12 +324,10 @@ module Stripe
|
|
292
324
|
c = Customer.construct_from({})
|
293
325
|
c.save_with_parent = true
|
294
326
|
|
295
|
-
obj = Stripe::StripeObject.construct_from(
|
296
|
-
:customer => c,
|
297
|
-
})
|
327
|
+
obj = Stripe::StripeObject.construct_from(customer: c)
|
298
328
|
|
299
329
|
serialized = obj.serialize_params
|
300
|
-
assert_equal({ :
|
330
|
+
assert_equal({ customer: {} }, serialized)
|
301
331
|
end
|
302
332
|
|
303
333
|
should "#serialize_params should raise an error on other embedded API resources" do
|
@@ -318,57 +348,43 @@ module Stripe
|
|
318
348
|
end
|
319
349
|
|
320
350
|
should "#serialize_params takes a force option" do
|
321
|
-
obj = Stripe::StripeObject.construct_from(
|
322
|
-
|
323
|
-
:metadata => Stripe::StripeObject.construct_from({ :foo => 'bar' })
|
324
|
-
})
|
351
|
+
obj = Stripe::StripeObject.construct_from(id: "id",
|
352
|
+
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
325
353
|
|
326
|
-
serialized = obj.serialize_params(:
|
327
|
-
assert_equal({ :
|
354
|
+
serialized = obj.serialize_params(force: true)
|
355
|
+
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
328
356
|
end
|
329
357
|
|
330
358
|
should "#dirty! forces an object and its subobjects to be saved" do
|
331
|
-
obj = Stripe::StripeObject.construct_from(
|
332
|
-
|
333
|
-
:metadata => Stripe::StripeObject.construct_from({ :foo => 'bar' })
|
334
|
-
})
|
359
|
+
obj = Stripe::StripeObject.construct_from(id: "id",
|
360
|
+
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
335
361
|
|
336
362
|
# note that `force` and `dirty!` are for different things, but are
|
337
363
|
# functionally equivalent
|
338
364
|
obj.dirty!
|
339
365
|
|
340
366
|
serialized = obj.serialize_params
|
341
|
-
assert_equal({ :
|
367
|
+
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
342
368
|
end
|
343
369
|
|
344
370
|
should "#to_s will call to_s for all embedded stripe objects" do
|
345
|
-
obj = Stripe::StripeObject.construct_from(
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
})
|
363
|
-
expected = JSON.pretty_generate({
|
364
|
-
id: 'id',
|
365
|
-
refunds: {
|
366
|
-
data: [
|
367
|
-
{id: 'id', metadata: {foo: 'bar'}}
|
368
|
-
]
|
369
|
-
},
|
370
|
-
metadata: { foo: 'bar' }
|
371
|
-
})
|
371
|
+
obj = Stripe::StripeObject.construct_from(id: "id",
|
372
|
+
# embeded list object
|
373
|
+
refunds: Stripe::ListObject.construct_from(data: [
|
374
|
+
# embedded object in list
|
375
|
+
Stripe::StripeObject.construct_from(id: "id",
|
376
|
+
# embedded object in an object in a list object
|
377
|
+
metadata: Stripe::StripeObject.construct_from(foo: "bar")),
|
378
|
+
]),
|
379
|
+
# embeded stripe object
|
380
|
+
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
381
|
+
expected = JSON.pretty_generate(id: "id",
|
382
|
+
refunds: {
|
383
|
+
data: [
|
384
|
+
{ id: "id", metadata: { foo: "bar" } },
|
385
|
+
],
|
386
|
+
},
|
387
|
+
metadata: { foo: "bar" })
|
372
388
|
|
373
389
|
assert_equal(expected, obj.to_s)
|
374
390
|
end
|
@@ -379,8 +395,8 @@ module Stripe
|
|
379
395
|
begin
|
380
396
|
obj = Stripe::StripeObject.construct_from({})
|
381
397
|
Stripe::StripeObject.serialize_params(obj)
|
382
|
-
message = "NOTE: Stripe::StripeObject.serialize_params is "
|
383
|
-
|
398
|
+
message = "NOTE: Stripe::StripeObject.serialize_params is " \
|
399
|
+
"deprecated; use #serialize_params instead"
|
384
400
|
assert_match Regexp.new(message), $stderr.string
|
385
401
|
ensure
|
386
402
|
$stderr = old_stderr
|
@@ -388,11 +404,11 @@ module Stripe
|
|
388
404
|
end
|
389
405
|
|
390
406
|
should "error on setting a property to an empty string" do
|
391
|
-
obj = Stripe::StripeObject.construct_from(
|
407
|
+
obj = Stripe::StripeObject.construct_from(foo: "bar")
|
392
408
|
e = assert_raises ArgumentError do
|
393
409
|
obj.foo = ""
|
394
410
|
end
|
395
|
-
assert_match
|
411
|
+
assert_match(/\(object\).foo = nil/, e.message)
|
396
412
|
end
|
397
413
|
end
|
398
414
|
end
|