Uninitialised Constant constant Mime::JSON Error
I upgraded to rails 5 (which is a bit of a pain) but I got through more or less unscathed. Good think I invested significant time in tests and they are fairly robust - for the API at least. But the UI tests are weak. I prefer not to do them test first because they change all the time and very quickly.
Failure/Error:
def api_response_format(format = Mime::JSON)
request.headers['Accept'] = "#{request.headers['Accept']}, #{format}"
## etc
end
NameError:
uninitialized constant Mime::JSON
# ./spec/support/request_helpers.rb:14:in `api_response_format'
What does this mean and why is it happening?
It’s because there has been a depcrecation in rails 5. This is when it is very handy to have calls to external APIs isolated in your classes. That way, if something changes, then you won’t have to change it in a million different places.
Accessing mime types via constants is deprecated. Please change: Mime::JSON to: Mime::Type[:JSON]
Just make the change and it should work:
Mime[:json]
Written on February 1, 2018