The Token model is used to store access tokens and had field names which may have caused confusion for developers using them. Therefore, the field previously called name: now has the correct identifier token: (as it stores the actual token value), and the field previously called label: is now called name: for better consistency with other models.
Originally, the `authenticated_as` spec helper
made it impossible to persist session state in request specs.
This made it impossible to test external_credentials#callback
or any other controller actions that rely on session state.
This commit fixes that.
=== How exactly was `authenticated_as` broken?
`authenticated_as` passes user credentials via request headers.
In practice, this auth method is for API requests by machine clients,
since they don't have cookies or store session state.
Because machine clients don't use cookies or session state anyway,
Zammad disables them for this auth method:
# app/controllers/application_controller/authenticates.rb
1 module ApplicationController::Authenticates
42 def authentication_check_only(auth_param = {})
57 request.session_options[:skip] = true
As a result, in tests using `authenticated_as`,
session data is discarded between every single request.
Some controller actions will not work without session data,
so this limitation made testing these actions impossible.
=== Why couldn't we just set the session values directly in test setup?
This is possible in controller tests,
but the Rails & RSpec team soft-deprecated controller tests
in favor of integration tests (request specs) a long time ago.
For more details, consider the following comments:
> The session is an internal structure for the controller.
> Integration test is more black box than controller tests were.
> I don't think we should be testing internals of the controller like this.
> I would rework the test to test something visible in the UI instead.
>
> --@dhh via https://github.com/rails/rails/issues/23386
> Integration tests doesn't allow you to set session.
>
> --@rafaelfranca via https://github.com/rails/rails/issues/25394
=== Solution
This commit adds a `via: :browser` option to the spec helper
which simply prepends a valid sign-in request to the spec example.