Search code examples
ruby-on-railsrubytestingvcr

How can I set a VCR global cassette for model geocoding?


I have a user model with a gym association. Gyms use the google api via the geocoder gem for geocoding which is done after_save. In my gym specs, I was able to add use_vcr_cassette to have the request recorded and specs passing.

The issue now is that my user factory creates a gym association, so any spec that uses the user factory is failing because it doesn't know what to do with the geocode request since all external requests have been turned off.

How can I globally apply the previous gym cassette for the request being made by my gym factory?


Solution

  • I think there's a serious problem with your design if your model is making 3rd party API calls. You can read my longer response to a similar question here.