Devise、rspec 和 Mongoid 测试失败
require 'spec_helper'
describe User do
before(:each) do
@attr = {
:username => "User",
:email => "[email protected]",
:password => "foobar",
:password_confirmation => "foobar",
:phone_no => "0808322222"
}
end
it "should create a new instance given a valid attribute" do
User.create!(@attr)
end
end
测试一直失败,不知道为什么
Failures:
1) User should create a new instance given a valid attribute
Failure/Error: User.create!(@attr)
Mongoid::Errors::Validations:
Validation failed - Phone no can't be blank, Username can't be blank.
# ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'
Finished in 0.2505 seconds
2 examples, 1 failure
require 'spec_helper'
describe User do
before(:each) do
@attr = {
:username => "User",
:email => "[email protected]",
:password => "foobar",
:password_confirmation => "foobar",
:phone_no => "0808322222"
}
end
it "should create a new instance given a valid attribute" do
User.create!(@attr)
end
end
The test keep failing, please dont know why
Failures:
1) User should create a new instance given a valid attribute
Failure/Error: User.create!(@attr)
Mongoid::Errors::Validations:
Validation failed - Phone no can't be blank, Username can't be blank.
# ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'
Finished in 0.2505 seconds
2 examples, 1 failure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是您通过 #create 方法定义了一些数据,其中数据不是 attr_accessible 属性。
因此,您可以将此属性添加到 attr_accessible 列表中,这样您就可以通过示例避免使用批量分配:
You problem is you define some data by #create method where data is not is attr_accessible attribute.
So you can add this attribute on your attr_accessible list of you can avoid using the mass-assignement by example :