0

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

1 Answer 1

1

TLDR: Check to see if you're using :null_store for your config.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 the config.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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.