ruby on rails - How to set the referrer in an _integration_ test -


rspec can't access http referrer.

my user_sessions#create action contains: redirect_to :back, rails can execute reading http referrer.

stackoverflow contains plenty of posts how set/mock/whatever referrer in controller spec. general vibe request.env["http_referer"] = etc etc.

but need redirect_to :back work in integration test looks this:

click_link "login" page.current_path.should == "/login" fill_in "user_session_email", :with => @user.email fill_in "user_session_password", :with => @user.password click_on "submit_user_session" page.current_path.should == new_order_path click_on "submit_order" 

how can this?

bonus points if solution tells spec store referral every url visits (so test robust) , has no impact on other specs (for speed).

capybara.current_session.driver.header 'referer', 'http://example.com' 

it looks you're using capybara, can use capybara explicitly set referer. have update whenever wanted change, , if needed remove set nil.

maybe bit cleaner:

referer = 'http://example.com' capybara.current_session.driver.header 'referer', referer 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -