[英]Capybara email resets the session
在Capybara中注册后,我需要测试智能重定向的特定流程。 假设我的网站中有几个interesting_pages
页面,我想在确认注册后将用户重定向到上次访问的趣味页面
小场景:
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[]=
。 在呈现page "42"
的控制器中,我将会话设置为session[:interesting_page] = request.original_url
在开发中,单击电子邮件中的确认链接后,在设计确认过程中,我能够成功重定向到会话[:interesting_page]
但是,当我尝试使用Cucumber进行测试时,在单击电子邮件链接时,Capybara-email似乎会重置会话,因此当我单击电子邮件中的链接以重新连接时, session[:interesting_page]
会被删除...
编辑When I sign up and I confirm via the link in the email
步骤中When I sign up and I confirm via the link in the email
基本上会经过设备注册控制器,然后我使用Capybara :: 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都可能不会设置,这意味着您实际上并未登录,或者保存了一些重要数据。 对于您而言,这意味着(至少)之后, I click "Sign up !"
您需要一个成功注册后出现在页面上的文本的期望值。
要检查的另一件事是电子邮件中URL的主机名(可能是端口)是否与您正常访问所使用的主机名匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.