My Rails app geocodes users' IP when they are created and also when they update their data only if they change their city. The geocoding is slowing down my tests ridiculously.
This seems to me to be a poor way to avoid endless geocoding when running tests but I am unsure of a better way to do this.
if Rails.env == 'production' || Rails.env == 'development'
after_save :geocode, if: ->(user){ user.ip_address.present? and user.ip_address_changed? }
end
Rails.env.test?
is cleaner, 2) but don't do that either! Instead, look into mocking and stubbing. I'd elaborate, but this question may be better for StackOverflow. There's not a lot a code to review, and you already know you're looking for a different solution altogether. – Flambino Jun 21 at 21:37