如何处理用户“确认”与瓦提尔/黄瓜?

发布于 2024-08-25 18:18:00 字数 1189 浏览 3 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨轻弹 2024-09-01 18:18:00

我不熟悉 waitir,但我想给出以下步骤:

Given I have signed up
When I confirm my account
Then my account should be confirmed

您可以跟踪您期望他们点击的链接,并实际测试点击该链接以验证控制器然后将用户设置为已确认:

When /I confirm my account / do
  BROWSER.goto("the_url_from_the_email")
  # note that if you need to visit this link and click a button
  # or something you will need to code that part as well
end

这些步骤将执行注册和确认码。我想,如果您愿意,您可以使用这些来组成“假设我已使用已确认的帐户登录”步骤作为其他测试的先决条件,或者只是使用相同的步骤来返回固定帐户。

不确定这是否真的回答了您原来的问题,但正如前面提到的,您还没有真正说出实际出了什么问题。我会假设 User.last.confirmed!未保存,或未保存您期望的记录。

I'm not familiar with waitir but I imagine given following steps:

Given I have signed up
When I confirm my account
Then my account should be confirmed

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:

When /I confirm my account / do
  BROWSER.goto("the_url_from_the_email")
  # note that if you need to visit this link and click a button
  # or something you will need to code that part as well
end

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文