如何处理用户“确认”与瓦提尔/黄瓜?
我是 Watir 的新手,在测试中登录时遇到了一些问题。我使用 authlogic 作为我选择的身份验证方法。当用户注册时,他们会收到一封带有确认链接的电子邮件。单击此链接会确认他们的帐户,然后他们就可以登录。
我遇到的问题是使用 Watir 时如何确认用户?
到目前为止我已经:
Given /I sign up/ do
BROWSER.goto("http://localhost:3000/register")
BROWSER.text_field(:id, "user_email").set("[email protected]")
BROWSER.text_field(:id, "user_name").set("Foo Bar)
BROWSER.text_field(:id, "user_password").set("foo bar")
BROWSER.text_field(:id, "user_password_confirmation").set("foo bar")
BROWSER.button(:id, "user_submit").click
end
Given /I am logged in via Watir/ do
BROWSER.goto("http://localhost:3000/login")
BROWSER.text_field(:id, "user_session_email").set("[email protected])
BROWSER.text_field(:id, "user_session_password").set("foo bar")
BROWSER.button(:id, "user_session_submit").click
end
这正确地填充了字段并且用户被保存。现在我尝试像这样确认用户:
Given /I am confirmed/ do
User.last.confirmed!
end
不幸的是,这不起作用。我缺少什么?
I'm new to Watir and I've having a little trouble getting logged in in my tests. I use authlogic as my authentication method of choice. When a User registers, they are sent an email with a confirmation link. Clicking this link confirms their account and they can then login.
The issue I'm having is how do I confirm the User when using Watir?
I have so far:
Given /I sign up/ do
BROWSER.goto("http://localhost:3000/register")
BROWSER.text_field(:id, "user_email").set("[email protected]")
BROWSER.text_field(:id, "user_name").set("Foo Bar)
BROWSER.text_field(:id, "user_password").set("foo bar")
BROWSER.text_field(:id, "user_password_confirmation").set("foo bar")
BROWSER.button(:id, "user_submit").click
end
Given /I am logged in via Watir/ do
BROWSER.goto("http://localhost:3000/login")
BROWSER.text_field(:id, "user_session_email").set("[email protected])
BROWSER.text_field(:id, "user_session_password").set("foo bar")
BROWSER.button(:id, "user_session_submit").click
end
This correctly populates the fields and the User is saved. Now I try to confirm the User like so:
Given /I am confirmed/ do
User.last.confirmed!
end
Unfortunately this doesn't work. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉 waitir,但我想给出以下步骤:
您可以跟踪您期望他们点击的链接,并实际测试点击该链接以验证控制器然后将用户设置为已确认:
这些步骤将执行注册和确认码。我想,如果您愿意,您可以使用这些来组成“假设我已使用已确认的帐户登录”步骤作为其他测试的先决条件,或者只是使用相同的步骤来返回固定帐户。
不确定这是否真的回答了您原来的问题,但正如前面提到的,您还没有真正说出实际出了什么问题。我会假设 User.last.confirmed!未保存,或未保存您期望的记录。
I'm not familiar with waitir but I imagine given following steps:
You could either keep track of the link you're expecting them to hit and actually test hitting that link to verify that the controller then sets the user as confirmed:
These steps would exercise the signup and confirmation code. I think if you wanted you'd either use these to compose a "Given I am logged in with a confirmed account" step as a precondition for other tests, or just use that same step to return a canned account.
Not sure that answers your original question really but as mentioned you haven't really said what's actually going wrong. I would assume that User.last.confirmed! isn't saving, or isn't saving the record you expect.