DEV: Raise special check_xhr exception in tests (PR #9992)

Solves a papercut in tests when you forget .json on an endpoint by raising a special exception.

GitHub

Instead of doing this check at runtime, we can defined the error as a constant so that the check is only done.

Do you mean switching out the method body based on Rails.env.test?

I was thinking something like

ERROR_CLASS = Rails.env.test? ? ApplicationController::CheckXhrForTest : ApplicationController::RenderEmpty

def check_xhr
    ....
    raise ERROR_CLASS.new
end

Still failing a few tests that are dependent on the old behavior.

I think the cost of the check is so cheap and it only happens anyway in exceptional cases (which is key). Code is somewhat simpler this way, I say we just keep it.

@riking I would like to close this off, can you merge this when you start your day?

I am just too mixed on all of this, I guess we just do this in rubocop and can catch it on save at lint time?