我需要在注册后在水豚中测试智能重定向的特定流程。假设我在我的网站有几个interesting_pages
,我想给用户的最后访问有趣的重定向页面注册确认后Capybara电子邮件重置会话
小场景:
When I visit the interesting page "42"
And I visit a couple uninteresting pages
# Note during the visit to other pages, session[:interesting_page] is correctly set to the url of page "42"
When I sign up and I confirm via the link in the email
# At this point I have lost the session[:interesting_page]
Then I should be confirmed and redirected to the last visited interesting page "42"
对于实际执行中,我决定选择controller.session[]=
作为suggested in this answer。在此呈现page "42"
控制器我设置会话session[:interesting_page] = request.original_url
在发展中,我能够成功地redirect_to的会话[:interesting_page]点击确认链接的电子邮件
然而,当我尝试后色器件确认时测试这个使用黄瓜,水豚的电子邮件似乎重置会话邮件点击链接时,所以session[:interesting_page]
当我点击电子邮件中的重新连接的链接获取删除...
编辑When I sign up and I confirm via the link in the email
一步基本上经过一个设计注册控制器,我使用Capybara :: Email来点击配置文件rmation email
# Nested steps for "When I sign up and I confirm via the link in the email"
I fill in "email" with ...
...
I click "Sign up !"
Then I should see "Please confirm your account via the link !"
# At this stage session[:interesting_page] still exists and points to page "42"
And an email should have been sent to "#{user.email}"
And in the current mail I click "Je finalise mon inscription"
# The RegistrationController code I use is similar to devise and returns a pending_confirmation page
# respond_with resource, location: pending_confirmation_path
# Associated step implementations
Then(/an email should have been sent to "([^"]*)"/) do |address|
open_email(address)
expect(current_email).to be
end
When(/in the current mail I click "([^"]*)"$/) do |link|
current_email.click_link link
end
显示您的'当我注册并通过电子邮件中的链接确认'步骤 –
另外,当我访问有趣的页面时,步骤是重要的 - 这些步骤最终有望达到确保页面实际上已加载。如果这些期望不存在,那么会话cookie可能永远不会在浏览器中设置。 –
@ThomasWalpole我刚刚添加了步骤代码。此外,我通过尝试加载其他页面之前通过电子邮件和会议确实设置黄瓜检查。 –