When testing a rails 7 controller everything works splendidly until I get a redirect and then execute a follow_redirect!
. At this point the session mysteriously disappears and my tests can no longer continue...very limiting.
Very dumbed down, hypothetical example:
post some_url, params { yada: 'foo' }
assert_not_nil session[:yada]
assert_redirect some_redirect_url
follow_redirect!
assert_not_nil session[:yada] # This assertion fails, the session is gone
TLDR: Check to see if you're using
:null_store
for yourconfig.cache_store
setting in tests. If so switch the config line to:config.cache_store = :memory_store
After MUCH debugging and consternation, I was finally able to track down the issue. In the
test.rb
rails configuration file theconfig.cache_store
setting was set to:null_store
. Swapping this out for:memory_store
fixed the issue and all was well again. Worked like a charm...but took several hours to finally track down.