微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails-3 – Rail 3.2.2 / Devise:使用rspec废弃警告

我最近升级一个应用程序到3.2.2的轨.

我正在使用Factory_girl

Factory.sequence :name do |n| “name-#{n}” end

Factory.define :user do |u| u.first_name{ Factory.next(:name) }
u.last_name { |u| ‘last_’ + u.first_name } u.password ‘secret’
u.password_confirmation { |u| u.password } u.sequence(:email) { |i|
“user_#{i}@example.com” }

end

和这个简单的测试

specify { Factory.build(:user).should be_valid }

生成以下警告

DEPRECATION WARNING: You’re trying to create an attribute user_id'.
Writing arbitrary attributes on a model is deprecated. Please just use
attr_writer` etc. (called from block (2 levels) in
at…

我该如何摆脱呢?

解决方法

这可能是因为您没有使用更新的列定义来准备/迁移测试数据库,因此它认为您正在尝试任意设置属性.

运行rake db:test:准备确保更新.

方法Here’s the source code,您可以在其中首先看到Rails检查列或属性,然后警告是否找不到.

原文地址:https://www.jb51.cc/ruby/273431.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐