331 Commits

Author SHA1 Message Date
Brandur
159335078c For completeness, add a test case with an empty string 2015-11-03 13:38:59 -08:00
Michael Bianco
7cd161dd03 Tests for BankAccount#verify 2015-10-29 15:01:53 -04:00
Brandur
ae4bb64c5a Call serialization of a changed array of hashes undefined for now 2015-10-27 11:53:36 -07:00
Brandur
431ef3b1f2 Special case the serialization of account's additional_owners
We attempt to do a special encoding trick when serializing
`additional_owners` under an account: when updating a value, we actually
send the update parameters up as an integer-indexed hash rather than an
array. So instead of this:

    field[]=item1&field[]=item2&field[]=item3

We send this:

    field[0]=item1&field[1]=item2&field[2]=item3

The trouble is that this had previously been built into the core library
as the default handling for all arrays. Because of this, it was
impossible to resize a non-`additional_owners` array as described in
more detail in #340.

This patch special cases `additional_owners` and brings sane behavior
back to normal arrays along with a test suite so that we try to build
some better guarantees around both the general and non-general cases.
2015-10-27 09:07:41 -07:00
Brandur
216218aeb0 Order hack to make 1.8.7 tests happy
It turns out that the tests had been working ... but mostly by virtue of
luck only. This should stabilize them more permanently.
2015-10-20 12:15:36 -07:00
Brandur
7dabbd444a Revert "Tweak faulty test logic"
This reverts commit eac89a1af140600904b8e723b20b9755545b6a6e.
2015-10-20 12:15:20 -07:00
Brandur
eac89a1af1 Tweak faulty test logic 2015-10-20 12:11:28 -07:00
Brandur
a014d505bc Correct internal usage of #update_attributes
Unfortunately usage of `#update_attributes` had rolled over from a time
where `#update_attributes_with_options` was still in use and `opts` were
being passed in as an optional argument which had the result of further
nesting the hash internally (i.e. `:opts => { :opts => ... } }`).

This patch fixes that problem, adds a regression test to prevent it from
reappearing, and banishes the unused `#update_attributes_with_options`.

Fixes #334.
2015-10-12 12:08:44 -07:00
Brandur
77b1972a72 Use alternate testing approach to satisfy 1.8.7 2015-10-10 12:40:17 -07:00
Brandur
ca8b49e5fd Use array as input instead of hash (for 1.8.7 tests) 2015-10-10 12:12:57 -07:00
Brandur
395d16b8c1 Remove sorting hack from parameter encoding
I added this for a regression suite so that 1.8.7 could pass its tests,
but unfortunately this caused a regression in the way that parameters
are encoded for arrays of hashes. This patch reverts the change and adds
tests to detect a future regression.

(And 1.8.7 is expected to fail on this initial commit.)
2015-10-10 12:12:57 -07:00
Brandur
daf2789ad7 Pass through all paging filters to descendent pages
When additional filters were provided for pagination like an expansion
or a predicate, they would not propagate to any call after the first.
This patch addresses that issue by storing all filters and moving them
to any new page objects being created.

Fixes #331.
2015-10-09 13:58:23 -07:00
Brandur
900fa4b5dc Add StripeObject#deleted?
Adds a special helper to `StripeObject` that helps a developer to
determine whether or not an object is deleted.

As described originally in #257, this is a bit of a special case because
a non-deleted object does not respond with `deleted` as part of its
representation, so while a deleted object would have this accessor
available automatically, non-deleted objects would not. This made use of
the SDK awkward because the presence of the method was not guaranteed.

Fixes #257 (again, heh).
2015-10-09 10:16:59 -07:00
Brandur
b3912c1712 Merge branch 'brandur-deprecate-refresh-from'
Conflicts:
	lib/stripe/stripe_object.rb
2015-10-08 17:49:27 -07:00
Brandur
d09093fca1 Add some tests just to make sure everything is working as we expect 2015-10-08 17:43:20 -07:00
Brandur
1a96d7cf8e Use Gem:: deprecation method instead of a custom one 2015-10-08 17:24:59 -07:00
Brandur
11dd870900 Have StripeObject#update_attributes reflect behavior of accessors
This dials down the safety of `StripeObject`'s `#update_attributes`
method so that it allows properties to be assigned that it doesn't yet
know about. We're doing this for a few reasons:

1. To reflect the current behavior of accessors (i.e. `obj.name = ...`)
   through `method_missing`.
2. To allow `#update_attributes` to assign properties on new projects
   that don't yet know their schema from an API call.

Fixes #324.
2015-10-08 14:04:11 -07:00
Brandur
3468698ce9 Make 1.8 happy 2015-10-08 10:03:18 -07:00
Brandur
8b255c7005 Deprecate StripeObject#refresh_from
As discussed in #325, this deprecates the public visibility of
`#refresh_from` (by renaming it). It also adds some deprecation
infrastructure to produce warnings when it's used.
2015-10-08 09:57:16 -07:00
Brandur
eb8787754c Replace deprecated URI.escape with a customized CGI.escape
Replaces my original attempt in #319 in a way that doesn't depend on
`URI.encode_www_form` which doesn't exist in 1.8.7. This should
hopefully get us the best of all worlds.

Caveats around use of `+` instead of `%20` as detailed in #319 still
apply.

Fixes #286.
2015-10-06 14:46:58 -07:00
Brandur
5853fd47dd Add one more set of tests for #url_encode 2015-10-06 14:38:14 -07:00
Brandur
91262c9042 Sort encoded parameters for stability in 1.8.7 tests 2015-10-06 14:17:51 -07:00
Brandur
a48fd12c70 Add regression suite for testing parameter encoding
Pulls the test suite out of #319 so that we can get some coverage around
parameter encoding. This should prevent any recurrence of #318.

Also includes a little bit of refactoring.
2015-10-06 14:04:02 -07:00
Brandur
42ea34b969 Pagination
Usage on a top-level collection:

```
Stripe::Customer.list.auto_paging_each do |customer|
  puts customer
end
```

Usage on a subcollection:

``` ruby
customer.invoices.auto_paging_each do |invoice|
  puts invoice
end
```

We've also renamed `#all` to `#list` to prevent confusion ("all" implies
that all resources are being returned, and in Stripe's paginated API
this was not the case). An alias has been provided for backward API
compatibility.

Fixes #167.

Replaces #211 and #248.
2015-10-05 12:15:09 -07:00
Kyle Conroy
8287904c00 Merge pull request #316 from stripe/apt-file-uploads-retrieve-url
Use correct URL for file upload retrieval
2015-10-05 11:36:30 -07:00
Jieren Chen
7d28eaab64 Merge pull request #310 from stripe/drj/t5176-legal-entity-override
Disallow directly overriding legal_entity
2015-10-02 12:12:09 -07:00
Andrew Thorp
841a34385a Use correct URL for file upload retrieval 2015-10-01 17:36:51 -07:00
Brandur
b57cd5aca4 Support Ruby 1.8.7 2015-10-01 16:59:56 -07:00
Brandur
e23b57628f Add attribute mass assignment and use it in #save
As detailed in issue #119, we've somewhat unfortunately been allowing
object attributes to be passed in during a #save because we mix any
arguments directly into the serialized hash (it seems that this was
originally intended to be used more for meta parameters that go to the
request).

As also noted in #119, this use causes problems when certain types of
parameters (like subobjects) are used. We're now left in the somewhat
awkward position of either:

1. Removing this functionality on #save and breaking what may be
   behavior that people depend on.
2. Fully support this mass assignment.

This patch takes the second path by extracting a new #update_attributes
method and using it from #save. It's still far from a perfect approach
because keys that have the same name as certain options (e.g. `req_url`)
are not going to work, but it should capture the behavior that most
people want.

Fixes #119.
2015-10-01 16:21:34 -07:00
Jieren Chen
e451e3d3e2 Fix test 2015-10-01 13:51:55 -07:00
Jieren Chen
797478786d Disallow directly overriding legal_entity 2015-10-01 13:39:11 -07:00
Brandur
df2e36287d Merge pull request #309 from stripe/brandur-boolean-accessors
Add question mark helpers (e.g. #paid?) for boolean object values
2015-09-30 14:36:23 -07:00
Brandur
a88b062beb Merge pull request #300 from stripe/brandur-upsert
Create if #save is called on a new object
2015-09-30 13:54:20 -07:00
Brandur
c301c6c0f6 Add question mark helpers (e.g. #paid?) for boolean object values
This patch adds question marks helpers (e.g. #paid?) for any values in a
StripeObject that are a boolean. This is fairly idiomatic Ruby in that
it behaves similarly to other libraries like ActiveRecord.

Note that a caveat here is that nullable booleans will not get a helper
added for them if their current value is null. For this reason, we
should eventually prefer to derive these methods from some sort of
programmatic API manifest.

Replaces #257 and #274.
2015-09-30 13:48:59 -07:00
Brandur
af72a57c9d Add #empty? helper on ListObject
This makes ListObject behave a little more like an Array in that it gets
an #empty? helper. This should fit pretty well with the Enumerable
methods that it already has.

Replaces #193.
2015-09-30 13:13:41 -07:00
Brandur
5515824fe2 Mix Enumerable into ListObject
This pulls the `Enumerable` mixin into `ListObject`. There is some
question in pulls like #167 as to the future of `ListObject` and how it
might change when pagination is introduced, but because we're unlikely
to make any backward incompatible changes to the API, it's likely that
`ListObject` will continue to represent a page of data that's been
extracted from the API. Given that assumption, pulling `Enumerable` in
should be relatively safe.

Fixes #227.
2015-09-29 22:26:00 -07:00
Brandur
f31eaa6b1e Perform deep name symbolization from .construct_from
When constructing an object using .construct_from treat keys that are
strings the same as keys which are symbols by calling Util's
symbolize_names on an input hash. This makes guarantees around
consistency a little better.

Fixes #151.
2015-09-29 17:52:16 -07:00
Brandur
ac7d050ecf Create if #save is called on a new object
Modifies the behavior of an update so that it can create an object if it
was new. This allows an "upsert"-like functionality where the SDK will
tend to do the right/expected thing.

This is a tad janky in that it checks for the existence of a class-level
`.create` method which is expected to come from a different module, but
most modules in the project are already fairly deeply intertwined and
co-dependent.

Fixes #165.
2015-09-29 17:39:43 -07:00
Brandur
fef7f8c641 Add a make_account to test data + charge_enabled -> charges_enabled 2015-09-29 15:46:43 -07:00
Brandur
30688422c4 Merge pull request #251 from godfat/to_hash-with-array
to_hash should also walk into arrays to make recursive call.
2015-09-28 15:31:54 -07:00
Brandur
be8108143b Assert on entire test URL for a slightly better guarantee 2015-09-23 12:04:12 -07:00
Brandur
1a49af7f94 Correct list + retrieval of Bitcoin transactions
Corrects the paths at which the client looks for Bitcoin transactions
and adds a small test suite to check these results.

Fixes stripe/stripe-ruby#236.
2015-09-22 18:23:57 -07:00
Rasmus Rygaard
333613fca2 Fix hash literal for compatibility. 2015-09-19 17:10:54 -07:00
Russell Davis
7a0ead3fac Merge pull request #291 from stripe/handle-non-hash-error-responses
Handle error responses that are not hashes more gracefully
2015-09-14 21:34:37 -07:00
Rasmus Rygaard
51b0bff8e9 Merge pull request #292 from stripe/rasmus-orders_bindings
Add Relay bindings
2015-09-14 16:36:37 -07:00
Russell Davis
70ae271c9e Handle error responses that are not hashes more gracefully 2015-09-14 15:13:30 -07:00
Rasmus Rygaard
6e14ca9b2a Add SKU metadata tests. 2015-09-13 21:12:48 -07:00
Rasmus Rygaard
747dac6ea0 Add Orders. 2015-09-13 20:43:36 -07:00
Rasmus Rygaard
690fd18cb3 Add SKUs, Products 2015-09-13 18:10:47 -07:00
Jacqueline Xu
a705799a2c add 429 rate limit error 2015-09-10 15:31:51 -07:00