Dan Ott

Today I Learned — January 7, 2016

Today I re-learned about ActionController::TestCase. It’s pretty common to send the request parameters in as the second argument. What I always forget is that the third and fourth parameters represent the session and the flash respectively.

test "something that depends on the session and the flash" do
  post :create, { always: "money" }, { in: "the" }, { banana: "stand" }
  assert_equal params[:always], "money"
  assert_equal session[:in], "the"
  refute_equal flash[:banana], "stand" # because the flash will have been flushed!
end