Challenge - 5 Problems
Rails Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Rails integration test?
Consider this integration test that simulates a user logging in and visiting the dashboard page. What will the test assert about the response?
Ruby on Rails
require "test_helper" class UserFlowsTest < ActionDispatch::IntegrationTest test "login and visit dashboard" do post login_path, params: { session: { email: "user@example.com", password: "password" } } follow_redirect! get dashboard_path assert_response :success assert_select "h1", "Dashboard" end end
Attempts:
2 left
💡 Hint
Remember that follow_redirect! follows the redirect after login, and assert_select works in integration tests.
✗ Incorrect
The test simulates a login by posting credentials, follows the redirect to the logged-in page, then requests the dashboard page. It asserts the response is successful and that the page contains an
with 'Dashboard'. This is valid and will pass if the app behaves correctly.
❓ state_output
intermediate2:00remaining
What is the value of session[:user_id] after this integration test runs?
In this integration test, a user logs in. What will be the value of session[:user_id] after the post request?
Ruby on Rails
post login_path, params: { session: { email: "user@example.com", password: "password" } }
# What is session[:user_id] now?Attempts:
2 left
💡 Hint
Think about how integration tests simulate requests and what is accessible.
✗ Incorrect
In Rails integration tests, the session hash is not directly accessible after requests. You cannot read session[:user_id] directly in the test. Instead, you verify behavior through responses or database state.
🔧 Debug
advanced2:00remaining
Why does this integration test fail with a 'No route matches' error?
This integration test tries to visit a profile page but fails with a routing error. What is the cause?
Ruby on Rails
get profile_path(user_id: 1)
assert_response :successAttempts:
2 left
💡 Hint
Check your config/routes.rb for the profile_path definition.
✗ Incorrect
The error indicates no route matches the given path. This usually means the route is not defined in routes.rb. Passing parameters incorrectly or login state issues cause different errors.
📝 Syntax
advanced2:00remaining
Which option correctly writes an integration test to check a redirect after logout?
You want to test that after logout, the user is redirected to the home page. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Remember logout is usually a DELETE request and you must follow redirects to check final page content.
✗ Incorrect
Option A correctly sends a DELETE request to logout_path, follows the redirect, checks the response is success, and verifies the home page heading. Other options use wrong HTTP verbs or miss following redirects.
🧠 Conceptual
expert3:00remaining
What is the main difference between Rails integration tests and controller tests regarding session and cookies?
Choose the statement that best describes how session and cookies behave differently in Rails integration tests compared to controller tests.
Attempts:
2 left
💡 Hint
Think about the scope and purpose of integration vs controller tests.
✗ Incorrect
Integration tests simulate user behavior across multiple requests and do not expose session or cookies directly to tests. Controller tests focus on single controller actions and allow direct access to session and cookies for easier unit testing.