Rail 3.2.2/Devise:使用rspec弃用警告 [英] Rail 3.2.2/Devise: deprecation warning with rspec

查看:58
本文介绍了Rail 3.2.2/Devise:使用rspec弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一个应用程序升级到Rails 3.2.2.

I recently upgraded an app to rails 3.2.2.

我正在使用Factory_girl

I'm using Factory_girl

Factory.sequence:name做| n | 名称-#{n}"结尾

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

Factory.define:user做| 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"}

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" }

结束

和这个简单的测试

指定{Factory.build(:user).应该是有效的

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

产生以下警告

DEPRECATION警告:您正在尝试创建属性user_id'. Writing arbitrary attributes on a model is deprecated. Please just use attr_writer`等. 在...

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...

我如何摆脱它?

推荐答案

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

It's probably because you haven't prepared/migrated your test database with updated column definitions, thus it thinks you're trying to arbitrarily set the attribute.

运行rake db:test:prepare以确保已更新.

这是该方法的源代码,其中您可以先查看Rails对列或属性的检查,然后在未找到它们时发出警告.

Here's the source code of that method, where you can see Rails checks for the column or attribute first, then warns if they're not found.

这篇关于Rail 3.2.2/Devise:使用rspec弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆