1153 Commits

Author SHA1 Message Date
Brandur
1f18f24991
Merge pull request #650 from stripe/brandur-fix-tests
Fix some parameters being sent in tests
2018-05-16 10:14:41 -07:00
Brandur
02200e4c96 Add missing magic comment 2018-05-16 16:52:58 +02:00
Brandur
ed2a0f066d Fix some parameters being sent in tests
I found a bug recently in stripe-mock which causes it not to actually be
validating that parameters not in the spec are not being sent (the
actual Stripe API does check for this).

After applying a fix, I found that stripe-ruby's test suite no longer
passes against it, and the reason is that there are some subtle mistakes
throughout. This patch corrects them to be in line with what the API
actually expects.
2018-05-16 15:10:00 +02:00
Brandur
e8b272653e Bump version to 3.15.0 v3.15.0 2018-05-10 15:42:50 -07:00
Brandur
ec66c3f0f4
Merge pull request #649 from stripe/brandur-frozen-strings
Add `frozen_string_literal` to every file and enforce Rubocop rule
2018-05-10 15:41:46 -07:00
Brandur
863da48398 Add frozen_string_literal to every file and enforce Rubocop rule
Adds the magic `frozen_string_literal: true` comment to every file and
enables a Rubocop rule to make sure that it's always going to be there
going forward as well.

See here for more background [1], but the basic idea is that unlike many
other languages, static strings in code are mutable by default. This has
since been acknowledged as not a particularly good idea, and the
intention is to rectify the mistake when Ruby 3 comes out, where all
string literals will be frozen. The `frozen_string_literal` magic
comment was introduced in Ruby 2.3 as a way of easing the transition,
and allows libraries and projects to freeze their literals in advance.

I don't think this is breaking in any way: it's possible that users
might've been pulling out one of are literals somehow and mutating it,
but that would probably not have been useful for anything and would
certainly not be recommended, so I'm quite comfortable pushing this
change through as a minor version.

As discussed in #641.

[1] https://stackoverflow.com/a/37799399
2018-05-10 14:56:14 -07:00
Brandur
40e4883ddc Bump version to 3.14.0 v3.14.0 2018-05-09 14:56:01 -07:00
Fay Wu
6ce45193d2 Add support for v1/issuer_fraud_records endpoints (#645) 2018-05-09 14:55:10 -07:00
Fay Wu
d07d1d37d6
Merge pull request #648 from stripe/fay/update-version
Upgrade `stripe-mock` to v0.16.0
2018-05-09 09:16:16 -07:00
Fay Wu
188fef5b6e Update minimum version of stripe-mock 2018-05-09 09:10:58 -07:00
Brandur
a44259b8f7 Bump version to 3.13.1 v3.13.1 2018-05-07 15:11:56 -07:00
Brandur
357ec528a2
Merge pull request #647 from stripe/brandur-merge-query-params
Merge query parameters coming from path with `params` argument
2018-05-07 15:11:09 -07:00
Brandur
3a2724bfcc Merge query parameters coming from path with params argument
If specifying both query parameters in a path/URL down to Faraday (e.g.,
`/v1/invoices/upcoming?coupon=25OFF`) _and_ query parameters in a hash
(e.g., `{ customer: "cus_123" }`), it will silently overwrite the ones
in the path with the ones in the hash. This can cause problems where
some critical parameters are discarded and causes an error, as seen in
issue #646.

This patch modifies `#execute_request` so that before going out to
Faraday we check whether the incoming path has query parameters. If it
does, we decode them and add them to our `query_params` hash so that
all parameters from either place are preserved.

Fixes #646.
2018-05-07 14:51:25 -07:00
Brandur
b3b0f78c91
Merge pull request #644 from stripe/brandur-stripe-mock-0-15
Move file upload tests over to be handled by `stripe-mock`
2018-05-07 06:52:37 -07:00
Brandur
4518050527
Merge pull request #643 from stripe/brandur-configuring-version
Add a README section for globally configuration an API version
2018-05-04 15:59:55 -07:00
Brandur
76e6383727 Add a README section for globally configuration an API version
I don't remember why I wrote this originally, but found it sitting
locally uncommitted. It seems like a useful example to have in the
README, so add it in.
2018-05-04 14:25:34 -07:00
Brandur
b9a3971df8 Move file upload tests over to be handled by stripe-mock
`stripe-mock` can now respond accurately for file API endpoints thanks
to a few improvements in how it handles `multipart/form-data` payloads
and the OpenAPI spec.

Here we upgrade `stripe-mock` to 0.15.0 and remove the manual stubbing
that we had previously.
2018-05-04 11:31:11 -07:00
Brandur
21b0514d1e Bump version to 3.13.0 v3.13.0 2018-04-11 13:51:35 -07:00
Brandur
9594875bbd
Merge pull request #634 from stripe/alexander/flexible-billing
Flexible/Metered Billing API support
2018-04-11 13:50:13 -07:00
Alexander Thiemann
c066c9c5f8 flexible billing primitives and tests 2018-04-11 13:29:24 -07:00
Brandur
0b54bf7ba2
Merge pull request #638 from stripe/brandur-stripe-mock-v0.12.0
Upgrade `stripe-mock` to v0.12.0
2018-04-10 13:38:44 -07:00
Brandur
93503dceb5 Fix one test that was incorrectly expecting a non-deleted object back 2018-04-10 13:03:14 -07:00
Brandur
31ac109b21 Upgrade stripe-mock to v0.12.0
The most important changes here are that deleted objects are now
represented more accurately, and that IDs used in URLs are "reflected"
back into responses so that test suites can treat return objects a
little more realistically than they could before.

This should resolve incompatibilities between `stripe-ruby` and newer
versions of `stripe-mock`.
2018-04-10 12:52:55 -07:00
Brandur
f6e542e6ab Bump version to 3.12.1 v3.12.1 2018-04-05 16:18:02 -07:00
Brandur
676670c022
Merge pull request #636 from stripe/brandur-initialize-instance-var
Initialize instance variable on the getter too
2018-04-05 16:12:09 -07:00
Brandur
776d45f116 Initialize instance variable on the getter too
The test suite is currently throwing a bunch of warnings from some
recent changes I made -- although we initialize `@additive_params` when
setting one with `self.additive_object_param`, we don't when we check
one with `self.additive_object_param?`. This often isn't a problem
because every API resource sets `metadata`, but it is from the test
suite and probably for vanilla `StripeObject`s too.
2018-04-05 15:42:46 -07:00
Brandur
2f322cadb4 Bump version to 3.12.0 v3.12.0 2018-04-05 07:17:58 -07:00
Brandur
c63081e3c5
Merge pull request #632 from stripe/brandur-only-empty-metadata
Fix replacement of non-`metadata` embedded `StripeObjects`
2018-04-05 07:16:22 -07:00
Brandur
39b80e518b Now that most hashes are non-additive, remove hack on subscription items
See the discussion here: https://github.com/stripe/stripe-ruby/pull/632
2018-04-05 07:10:15 -07:00
Brandur
5cfdf35d20 Introduce additive_object_param for use with metadata 2018-04-05 07:02:36 -07:00
Brandur
256556efa0 Fix replacement of non-metadata embedded StripeObjects
So we have a bit of a problem right now when it comes to replacing a
`StripeObject` that's embedded in an API resource.

Most of the time when someone does this, they want to _replace_ an
object embedded in another object. Take setting a source on a
subscription for example:

``` ruby
subscription.source = {
  object: 'card',
  number: 123,
}
subscription.save
```

In the case above, the serialized parameters should come out as:

```
source[object]=card&source[number]=123
```

That should apply even if the previous source had something else set on
it which we're not going to set this time -- say an optional parameter
like `source[address_state]`. Those should not be present at all in the
final serialized parameters.

(Another example is setting a `payout_schedule` as seen in #631 which is
PR is intended to address.)

There is an exception to this rule in the form of metadata though.
Metadata is a bit of a strange case in that the API will treat it as
additive, so if we send `metadata[foo]`, that will set the `foo` key,
but it won't overwrite any other keys that were already present.

This is a problem because when a user fully sets `metadata` to a new
object in Ruby, what they're probably trying to do is _replace_ it
rather than add to it. For example:

``` ruby
subscription.metadata
=> { old: 'bar' }

subscription.metadata = {
  new: 'baz'
}
subscription.save
```

To accomplish what the user is probably trying to do, we actually need
to send `metadata[old]=&metadata[new]=baz` so that we empty the value of
`old` while simultaneously setting `new` to `baz`.

In summary, metadata behaves different from other embedded objects in a
fairly fundamental way, and because the code is currently only set up to
handle the metadata case, it's not behaving correctly when other types
of objects are being set. A lot of the time emptying values like we do
for `metadata` is benign, but as we've seen in #631, sometimes it's not.

In this patch, I modify serialization to only empty out object values
when we see that parameter is `metadata`.

I'm really not crazy about the implementation here _at all_, but I'm
having trouble thinking of a better way to do it. One possibility is to
introduce a new class annotation like `empty_embedded_object :metadata`,
but that will have to go everywhere and might be error-prone in case
someone forgets it on a new resource type. If anyone has a suggestion
for an alternative (or can let me know if I'm missing something), I'd
love to hear it.

This PR is an alternate to #631.
2018-04-03 16:52:14 -07:00
Olivier Bellone
3bc4256e25
Bump version to 3.11.0 v3.11.0 2018-02-26 13:30:29 +01:00
Olivier Bellone
4d965ac5d7
Merge pull request #628 from stripe/ob-error-code
Add support for code attribute on all Stripe exceptions
2018-02-26 13:29:23 +01:00
Olivier Bellone
3805968741
Add support for code attribute on all Stripe exceptions 2018-02-23 19:02:26 +01:00
Brandur
a7ea9cf1e9 Bump version to 3.10.0 v3.10.0 2018-02-21 11:36:26 -08:00
Brandur
529b9ec417
Merge pull request #627 from stripe/jkakar/topup-client
Add support for /v1/topups endpoints
2018-02-21 11:35:16 -08:00
Jamu Kakar
0be22683a3 Add support for /v1/topups endpoints. 2018-02-16 15:03:46 -08:00
Jamu Kakar
16704d9563
Merge pull request #626 from stripe/jkakar/fix-product-issues
Upgrade to stripe-mock 0.8.0.
2018-02-15 16:44:29 -08:00
Jamu Kakar
74dfbe57d6 Apply review feedback from @ob-stripe. 2018-02-15 16:10:10 -08:00
Jamu Kakar
0b6a45af2e Fix broken test. 2018-02-15 16:05:02 -08:00
Olivier Bellone
fafd449c5f
Bump version to 3.9.2 v3.9.2 2018-02-12 11:32:24 -08:00
Olivier Bellone
1abb8a574b
Merge pull request #625 from stripe/ob-skip-to-hash-for-nil
Skip calling to_hash for nil
2018-02-12 11:31:06 -08:00
Olivier Bellone
5f1ddf2a96
Skip calling to_hash for nil 2018-02-12 11:20:19 -08:00
Brandur
f6484e3240 Bump version to 3.9.1 v3.9.1 2017-12-15 00:47:53 -08:00
Brandur
659025c7e7
Merge pull request #616 from stripe/ob-file-duck-typing
Use duck typing to detect File-like objects
2017-12-14 12:11:31 -08:00
Olivier Bellone
b83a0e5583
Use duck typing to detect File-like objects 2017-12-14 19:54:47 +01:00
Brandur
be8e4ff5f4
Merge pull request #614 from stripe/ob-coveralls
Add support for coveralls.io
2017-12-11 17:55:17 -08:00
Olivier Bellone
56430ad405
Add support for coveralls.io 2017-12-08 17:48:40 -08:00
Brandur
bfbc4b7862 Bump version to 3.9.0 v3.9.0 2017-12-08 10:48:47 -08:00
Brandur
cf810019d6
Merge pull request #613 from stripe/brandur-idempotency-error
Introduce new `IdempotencyError` type
2017-12-08 10:47:51 -08:00