I have the following test that passes:
test "should create order" do
assert_difference('Order.count') do
post :create, { :message_text => @order.attributes }, { :var_name => 1 }
end
Instead of adding , { :var_name => 1 }
to each HTTP call, how do I add the session to the setup method?
Thanks!
Inside a controller test you can access session
just like you can flash
.
here's a helper I use for setting the program's id
def set_current_program(program=programs(:direct_debit))
@current_program = program
session[:program_id] = @current_program && @current_program.id
end
or in the setup, you could do
def setup
session[:var_name] = 1
end
then just do your test as usual
test "should create order" do
assert_difference('Order.count') do
post :create, :message_text => @order.attributes
end
end
You can even assert the value of session, if the action should have changed it
assert_equal 24, session[:something_changed]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With