我最近升级了一个应用程序到3.2.2的轨.
我正在使用Factory_girl
Factory.sequence :name do |n| “name-#{n}” end
Factory.define :user do |u| u.first_name{ Factory.next(:name) }@H_502_8@ u.last_name { |u| ‘last_’ + u.first_name } u.password ‘secret’@H_502_8@ u.password_confirmation { |u| u.password } u.sequence(:email) { |i|@H_502_8@ “user_#{i}@example.com” }
end
和这个简单的测试
specify { Factory.build(:user).should be_valid }
生成以下警告
DEPRECATION WARNING: You’re trying to create an attribute
user_id'.@H_502_8@ Writing arbitrary attributes on a model is deprecated. Please just use@H_502_8@
attr_writer` etc. (called from block (2 levels) in@H_502_8@ at…
我该如何摆脱呢?
解决方法
这可能是因为您没有使用更新的列定义来准备/迁移测试数据库,因此它认为您正在尝试任意设置属性.
运行rake db:test:准备确保更新.
该方法的Here’s the source code,您可以在其中首先看到Rails检查列或属性,然后警告是否找不到.