Repository navigation
Commit 89d8fa5
committed
Resolve Issue with Class Level Memoization
Memoizing the api client is causing issues when the client_id and
client_secret are changed from one test to another.
You can reproduce the issue by running this command against commit
5cbe9a9
```
bundle exec rspec './spec/intelligent_foods/resources/order_spec.rb[1:1:5:2]' './spec/intelligent_foods_spec.rb[1:5:1]' --seed 34813 --format d
```
This will produce the following error:
```
IntelligentFoods#client returns an instance of the api client
```
When the api client is set up to fail authentication in a test (i.e.
setting the client_id and client_secret to nil), that client was being
memoized at the class level to the IntelligentFoods class.
When the test for IntelligentFoods#clients was run, it was pulling the
existing client held in memory, rather than the new client that was set
up for the test. The new client was not being set on the class due to
the existing memoization.
Removing the memoization solves the issue and I don't believe it will
introduce any significant overhead at this time. If, in the future, we
want to bring back the memoization, we'll need to have some way of
clearing the client any time the client_id or client_secret is changed.
Separately, this may speak to there being a larger structural issue in
the code, but that would require significantly move investigation and is
not really worth the effort for a pre-v1 release of the gem.
This change addresses the need by:
* Removing the memoization of the api client on the class level .client
method for the IntelligentFoods class1 parent 5cbe9a9 commit 89d8fa5
2 files changed
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
0 commit comments