Class: Authenticate::Testing::IntegrationTestsSignOn
- Inherits:
-
Object
- Object
- Authenticate::Testing::IntegrationTestsSignOn
- Defined in:
- lib/authenticate/testing/integration_tests_sign_on.rb
Overview
Middleware which allows tests to bypass your sign on screen. Typically used by integration and feature tests, etc. Speeds up these tests by eliminating the need to visit and submit the signon form repeatedly.
Sign a test user in by passing as=USER_ID in a query parameter. If ‘User#to_param` is overridden you may pass a block to override the default user lookup behaviour.
Configure your application’s test environment as follows:
# config/environments/test.rb
MyRailsApp::Application.configure do
# ...
config.middleware.use Authenticate::IntegrationTestsSignOn
# ...
end
or if ‘User#to_param` is overridden (to `username` for example):
# config/environments/test.rb
MyRailsApp::Application.configure do
# ...
config.middleware.use Authenticate::IntegrationTestsSignOn do |username|
User.find_by(username: username)
end
# ...
end
After configuring your app, usage in an integration tests is simple:
user = ... # load user
visit dashboard_path(as: user)
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ IntegrationTestsSignOn
constructor
A new instance of IntegrationTestsSignOn.
Constructor Details
#initialize(app, &block) ⇒ IntegrationTestsSignOn
Returns a new instance of IntegrationTestsSignOn.
39 40 41 42 |
# File 'lib/authenticate/testing/integration_tests_sign_on.rb', line 39 def initialize(app, &block) @app = app @block = block end |
Instance Method Details
#call(env) ⇒ Object
44 45 46 47 |
# File 'lib/authenticate/testing/integration_tests_sign_on.rb', line 44 def call(env) do_login(env) @app.call(env) end |