I'm trying to visit '/requests/new
. Now in the controller code, I've written it so that if a session doesn't exist, the user is redirected back to the home page. like so:
def new
@pagetitle = "What would you like to borrow?"
if session[:signup_email].nil?
flash[:danger] = "Please enter your email to get started"
redirect_to root_path
else
@signup_parent = Signup.find_by_email(session[:signup_email].downcase)
if @signup_parent.tos != true || @signup_parent.streetone.blank? || @signup_parent.streettwo.blank? || @signup_parent.zipcode.blank?
flash[:danger] = "Almost there! We just need a little more info"
redirect_to edit_signup_path
else
@requestrecord = @signup_parent.requests.build
end
end
end
But the problem is that now in testing, I can't simulate a session. I tried to write:
before do
session[:signup_email] = Signup.find_by_id(@signup_ana.id)
visit '/requests/new'
save_and_open_page
fill_in '#borrow__1', :with => 1
click_button
end
But that threw an error: undefined local variable or method
session' for #`
Yet if I don't try to simulate it, the save_and_open_page
shows me that I just get re-routed back to home. How should I do this? Is there a way to stub/ mock this out??