In order to protect us from rendering a resource simply converted to
json, without processing it with API data class, this commit changes
JSON responder behavior to render 404 if we can't find associated data
class. The only exception to that rule is when resource is already a
Hash, meaning that it was processed before - we sometimes return for
example simple Hash responses like { result: true }.
The Hash exception could allow to accidentally pass resource.as_json to
responder, but in travis-ci/travis-support@124b8b6 I disabled default
as_json method on AR::Base classes, so the risk of such mistake is
lowered.
We can do it, because we use :transaction strategy with DatabaseCleaner,
which starts transaction before each test and rollbacks after it. That
way data before each test is consistent.
The big advantage of such approach is that tests are fast now - we need
to only load Scenario data once.
One of the drawbacks, on the other hand, is that we need to always load
this data, even if no integration tests need running.
We can try to be smart about it and check if any integration tests are
loaded.
If there is an error somewhere along the line (like in DB connection
management), it should not interfere with returning proper result for
OPTIONS request. Otherwise it's hard to guess why the actual request in
the browser was not properly sent.