Capybara电子邮件重置会话
我需要在注册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
在开发中,我在点击电子邮件中的确认链接后,在设计确认期间成功地能够redirect_to session [: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
Capybara中的动作可以异步发生。 这意味着如果您没有检查页面上应该显示的内容,一旦您执行的任何操作完成,并调用另一个访问或操作,那么响应该操作所设置的任何cookie可能不会get set,这意味着你实际上没有登录,或者保存了一些重要的数据。 在你的情况下,这意味着(至少) I click "Sign up !"
您需要对成功注册后出现在页面上的文本的期望。
另一件需要检查的事情是,电子邮件中url的主机名(以及可能的端口)与您正常访问时使用的url相匹配。
- Capybara webkit无效响应错误,如何调试?
- 将两个ActiveRecord :: Relation与OR组合,而不是AND,返回一个Relation而不是一个Array,以便稍后能够分页
- 我错过了Solr-Sunspot设置的哪一部分?
- RAILS:如何查询每个关联都具有非null属性的所有对象
- Twitter Bootstrap模式不起作用
- 在Ruby中我可以在initialize方法中以某种方式自动填充实例变量吗?
- Ruby Net :: HTTP :: Get和JSON响应
- gem测试的策略,以确保gem与Rails 3.x和4.0一起使用?
- 未定义的方法`admin?’ 为零:NilClass