I expected the second request to have session[:user_id] == 2.
That's not the case. Functional tests in Rails are designed to make only one request per test and thus the second assignment doesn't change the session data.
To make it work as expected, split it into multiple tests: