stripe 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 390fa649e902fb6c709e2d803c92ffbf136a2384
4
- data.tar.gz: 837bf7e6916a55a1feeaffcd41c4e713eb5ce92f
3
+ metadata.gz: 79dc89b3485d9c9077874530b9483ba3a048b1d8
4
+ data.tar.gz: a73e14de59f52f2282196f1a30537a7d6c353497
5
5
  SHA512:
6
- metadata.gz: 635ac7d16f11b9ab531faf3f26f1d35e68947e18b92e5680656ce0963f99c910f5d8383f784895ae205a060740ac1540ab5b932da6ad2dc46cd99f8cb8c53163
7
- data.tar.gz: 47eb2e2fcaf5cb7637456663229c7a28349eac275518d3749967d33c3025ac9a4f4df1e8eea570e7808b1def4ce89045b941e3a910ab64813128483b7677a4ef
6
+ metadata.gz: 59133df8f5c29d44597f9a8145c77f0becf8705fe1b507b4612fb57930eb0b09afa2ef05e1ebe10c52e0749484bbcc957dbf998a2eb50df3d3d9879a9bcb2004
7
+ data.tar.gz: e5b4737ca902571ed0866df6b1401c5c3a2823d70e8a8da224dc5f2266b50cb454cffade965b5746098ce07e8ce0dd6eeedfe6c0b8c444a275d935eb9e008a42
@@ -1,3 +1,8 @@
1
+ === 3.0.1 2017-07-11
2
+
3
+ * Properties set with an API resource will now serialize that resource's ID if possible
4
+ * API resources will throw an ArgumentError on save if a property has been with an API resource that cannot be serialized
5
+
1
6
  === 3.0.0 2017-06-27
2
7
 
3
8
  * `#pay` on invoice now takes params as well as opts
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.1
@@ -176,7 +176,7 @@ module Stripe
176
176
  unsaved = @unsaved_values.include?(k)
177
177
  if options[:force] || unsaved || v.is_a?(StripeObject)
178
178
  update_hash[k.to_sym] =
179
- serialize_params_value(@values[k], @original_values[k], unsaved, options[:force])
179
+ serialize_params_value(@values[k], @original_values[k], unsaved, options[:force], key: k)
180
180
  end
181
181
  end
182
182
 
@@ -337,7 +337,7 @@ module Stripe
337
337
  self
338
338
  end
339
339
 
340
- def serialize_params_value(value, original, unsaved, force)
340
+ def serialize_params_value(value, original, unsaved, force, key: nil)
341
341
  case true
342
342
  when value == nil
343
343
  ''
@@ -348,13 +348,32 @@ module Stripe
348
348
  # be updated from their proper endpoints, and therefore they are not
349
349
  # included when serializing even if they've been modified.
350
350
  #
351
- # There are _some_ known exceptions though. For example, to save on API
352
- # calls it's sometimes desirable to update a customer's default source by
353
- # setting a new card (or other) object with `#source=` and then saving
354
- # the customer. The `#save_with_parent` flag to override the default
355
- # behavior allows us to handle these exceptions.
351
+ # There are _some_ known exceptions though.
352
+ #
353
+ # For example, if the value is unsaved (meaning the user has set it), and
354
+ # it looks like the API resource is persisted with an ID, then we include
355
+ # the object so that parameters are serialized with a reference to its
356
+ # ID.
357
+ #
358
+ # Another example is that on save API calls it's sometimes desirable to
359
+ # update a customer's default source by setting a new card (or other)
360
+ # object with `#source=` and then saving the customer. The
361
+ # `#save_with_parent` flag to override the default behavior allows us to
362
+ # handle these exceptions.
363
+ #
364
+ # We throw an error if a property was set explicitly but we can't do
365
+ # anything with it because the integration is probably not working as the
366
+ # user intended it to.
356
367
  when value.is_a?(APIResource) && !value.save_with_parent
357
- nil
368
+ if !unsaved
369
+ nil
370
+ elsif value.respond_to?(:id) && value.id != nil
371
+ value
372
+ else
373
+ raise ArgumentError, "Cannot save property `#{key}` containing " \
374
+ "an API resource. It doesn't appear to be persisted and is " \
375
+ "not marked as `save_with_parent`."
376
+ end
358
377
 
359
378
  when value.is_a?(Array)
360
379
  update = value.map { |v| serialize_params_value(v, nil, true, force) }
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -266,16 +266,29 @@ module Stripe
266
266
  assert_equal([{ :foo => "bar" }], serialized[:metadata])
267
267
  end
268
268
 
269
- should "#serialize_params and remove embedded APIResources" do
269
+ should "#serialize_params and embed an API resource that's been set and has an ID" do
270
+ customer = Customer.construct_from({ :id => "cus_123" })
271
+ obj = Stripe::StripeObject.construct_from({})
272
+
273
+ # the key here is that the property is set explicitly (and therefore
274
+ # marked as unsaved), which is why it gets included below
275
+ obj.customer = customer
276
+
277
+ serialized = obj.serialize_params
278
+ assert_equal({ :customer => customer }, serialized)
279
+ end
280
+
281
+ should "#serialize_params and not include API resources that have not been set" do
282
+ customer = Customer.construct_from({ :id => "cus_123" })
270
283
  obj = Stripe::StripeObject.construct_from({
271
- :customer => Customer.construct_from({})
284
+ :customer => customer
272
285
  })
273
286
 
274
287
  serialized = obj.serialize_params
275
288
  assert_equal({}, serialized)
276
289
  end
277
290
 
278
- should "#serialize_params and remove embedded APIResources unless flagged with save_with_parent" do
291
+ should "#serialize_params serializes API resources flagged with save_with_parent" do
279
292
  c = Customer.construct_from({})
280
293
  c.save_with_parent = true
281
294
 
@@ -287,6 +300,23 @@ module Stripe
287
300
  assert_equal({ :customer => {} }, serialized)
288
301
  end
289
302
 
303
+ should "#serialize_params should raise an error on other embedded API resources" do
304
+ # This customer doesn't have an ID and therefore the library doesn't know
305
+ # what to do with it and throws an ArgumentError because it's probably
306
+ # not what the user expected to happen.
307
+ customer = Customer.construct_from({})
308
+
309
+ obj = Stripe::StripeObject.construct_from({})
310
+ obj.customer = customer
311
+
312
+ e = assert_raises(ArgumentError) do
313
+ obj.serialize_params
314
+ end
315
+ assert_equal "Cannot save property `customer` containing " \
316
+ "an API resource. It doesn't appear to be persisted and is " \
317
+ "not marked as `save_with_parent`.", e.message
318
+ end
319
+
290
320
  should "#serialize_params takes a force option" do
291
321
  obj = Stripe::StripeObject.construct_from({
292
322
  :id => 'id',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -233,3 +233,4 @@ test_files:
233
233
  - test/stripe_test.rb
234
234
  - test/test_data.rb
235
235
  - test/test_helper.rb
236
+ has_rdoc: