I have a model that has a before_save callback. In that, I want to call a API to calculate something and save it. When the API is unavailable and throws an error, it then should just save 'not available' (which is totally fine, it's just a small project I do for myself). It should look like this:
class User < ApplicationRecord
before_save :calc
private
def calc
self.calculated_something = API_call
rescue StandardError
self.calculated_something = 'not available'
end
end
I know how to test the calculated_something case (with VCR), but how do I mock the failing API call? I don't want to use an empty VCR cassette btw. Is this even the correct way to save the calculated_something?
I hope my question is clear, thanks.