定制装置在黄瓜中失败
我已将字段添加到我的设计用户模型(全名和用户名)。这是我的用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :username, :fullname
# attr_accessor :username, :fullname
end
devise 工作正常,我可以在我的视图中访问全名。但黄瓜在以下情况下失败:
Scenario Outline: Creating a new account
Given I am not authenticated
When I go to register # define this path mapping in features/support/paths.rb, usually as '/users/sign_up'
And I fill in "user_email" with "<email>"
And I fill in "user_password" with "<password>"
And I fill in "user_password_confirmation" with "<password>"
And I fill in "user_fullname" with "<fullname>"
And I fill in "user_username" with "<username>"
And I press "Sign up"
Then I should see "Signed in as <fullname>"
Examples:
| email | password | fullname | username |
| [email protected] | secretpass | man net | net |
| [email protected] | fr33z3 | foo bar | foo |
出现此错误:
...
Then I should see "Signed in as <fullname>" # features/step_definitions/web_steps.rb:108
Examples:
| email | password | fullname | username |
| [email protected] | secretpass | man net | net |
undefined method `fullname' for #<User:0x1057a62e0> (ActionView::Template::Error)
/Library/Ruby/Gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
...
在模型中取消注释
attr_accessor :username, :fullname
使黄瓜可以工作,但在我看来,我无法再访问属性全名 - 我做错了什么?
更新:黄瓜不会产生错误,但测试失败,因为全名未插入数据库:
Started POST "/users" for 127.0.0.1 at Tue Feb 01 13:43:17 +0100 2011
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"commit"=>"Sign up", "utf8"=>"✓", "user"=>{"password_confirmation"=>"[FILTERED]", "fullname"=>"foo bar", "username"=>"foo", "password"=>"[FILTERED]", "email"=>"[email protected]"}}
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users"."id" FROM "users" WHERE (LOWER("users"."email") = LOWER('[email protected]')) LIMIT 1[0m
[1m[35mAREL (0.3ms)[0m INSERT INTO "users" ("current_sign_in_ip", "last_sign_in_ip", "created_at", "email", "remember_created_at", "reset_password_token", "password_salt", "last_sign_in_at", "remember_token", "sign_in_count", "current_sign_in_at", "encrypted_password", "updated_at") VALUES (NULL, NULL, '2011-02-01 12:43:18.265015', '[email protected]', NULL, NULL, '$2a$10$DzOCWVM1EHxp7E2asqfw8u', NULL, NULL, 0, NULL, '$2a$10$DzOCWVM1EHxp7E2asqfw8uNDPZifWxbBJA1xbfHh83nF1oOD9RTa6', '2011-02-01 12:43:18.265015')
[1m[36mAREL (0.1ms)[0m [1mUPDATE "users" SET "current_sign_in_ip" = '127.0.0.1', "last_sign_in_ip" = '127.0.0.1', "last_sign_in_at" = '2011-02-01 12:43:18.273337', "sign_in_count" = 1, "current_sign_in_at" = '2011-02-01 12:43:18.273337', "updated_at" = '2011-02-01 12:43:18.273724' WHERE ("users"."id" = 1)[0m
Redirected to http://www.example.com/
Completed 302 Found in 325ms
我使用rails 3.0.3和最新的黄瓜/水豚宝石,
谢谢您的帮助!
I have added to fields to my devise user model (fullname and username). This is my user model:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :username, :fullname
# attr_accessor :username, :fullname
end
devise works fine and I can access fullname in my views. But cucumber fails for following scenario:
Scenario Outline: Creating a new account
Given I am not authenticated
When I go to register # define this path mapping in features/support/paths.rb, usually as '/users/sign_up'
And I fill in "user_email" with "<email>"
And I fill in "user_password" with "<password>"
And I fill in "user_password_confirmation" with "<password>"
And I fill in "user_fullname" with "<fullname>"
And I fill in "user_username" with "<username>"
And I press "Sign up"
Then I should see "Signed in as <fullname>"
Examples:
| email | password | fullname | username |
| [email protected] | secretpass | man net | net |
| [email protected] | fr33z3 | foo bar | foo |
with this error:
...
Then I should see "Signed in as <fullname>" # features/step_definitions/web_steps.rb:108
Examples:
| email | password | fullname | username |
| [email protected] | secretpass | man net | net |
undefined method `fullname' for #<User:0x1057a62e0> (ActionView::Template::Error)
/Library/Ruby/Gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
...
uncommenting
attr_accessor :username, :fullname
in the model makes cucumber work but in my view I cannot access the attribute fullname any longer - what I am doing wrong ?
UPDATE: cucumber does not produce error but the test fails because fullname is not inserted into the database:
Started POST "/users" for 127.0.0.1 at Tue Feb 01 13:43:17 +0100 2011
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"commit"=>"Sign up", "utf8"=>"✓", "user"=>{"password_confirmation"=>"[FILTERED]", "fullname"=>"foo bar", "username"=>"foo", "password"=>"[FILTERED]", "email"=>"[email protected]"}}
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users"."id" FROM "users" WHERE (LOWER("users"."email") = LOWER('[email protected]')) LIMIT 1[0m
[1m[35mAREL (0.3ms)[0m INSERT INTO "users" ("current_sign_in_ip", "last_sign_in_ip", "created_at", "email", "remember_created_at", "reset_password_token", "password_salt", "last_sign_in_at", "remember_token", "sign_in_count", "current_sign_in_at", "encrypted_password", "updated_at") VALUES (NULL, NULL, '2011-02-01 12:43:18.265015', '[email protected]', NULL, NULL, '$2a$10$DzOCWVM1EHxp7E2asqfw8u', NULL, NULL, 0, NULL, '$2a$10$DzOCWVM1EHxp7E2asqfw8uNDPZifWxbBJA1xbfHh83nF1oOD9RTa6', '2011-02-01 12:43:18.265015')
[1m[36mAREL (0.1ms)[0m [1mUPDATE "users" SET "current_sign_in_ip" = '127.0.0.1', "last_sign_in_ip" = '127.0.0.1', "last_sign_in_at" = '2011-02-01 12:43:18.273337', "sign_in_count" = 1, "current_sign_in_at" = '2011-02-01 12:43:18.273337', "updated_at" = '2011-02-01 12:43:18.273724' WHERE ("users"."id" = 1)[0m
Redirected to http://www.example.com/
Completed 302 Found in 325ms
I use rails 3.0.3 and newest cucumber/capybara gems
thank you for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在
attr_accessible
列表中定义fullname
字段,但从表面上看,您的users
表中没有 fullname 字段,它也没有列在任何attr_accessor
调用中,就像您注释掉的调用一样。因此,未定义的方法。
You're defining the
fullname
field in theattr_accessible
list but, by the looks of things, there is no fullname field in yourusers
table, nor is it listed in anyattr_accessor
call, like the one you've got commented out.Thus, undefined method.
好的,谢谢。我想我发现了问题:我使用了黄瓜功能/...,它不适用于我的迁移。
使用耙黄瓜效果很好。现在黄瓜功能/...也起作用了!?
ok and thank you. I think I found the problem: I used cucumber feature/... which did not work with my migrations.
Using rake cucumber works fine. And now also cucumber feature/... works !?