我正在为我的模型添加单元测试,并且在对gem 'devise'
. 这是我的测试代码:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "should not save user without name" do
user = User.new
user.email = "david@test.com"
user.password = "david123"
assert !user.save, "Saved user without name"
end
end
运行测试时ruby -Itest test/unit/user_test.rb
出现以下错误:
1) Error:
test_should_not_save_user_without_email(UserTest):
ActiveRecord::StatementInvalid: PG::Error: ERROR: column "password" of relation "users" does not exist
LINE 1: INSERT INTO "users" ("name", "email", "password", "created_a...
^
: INSERT INTO "users" ("name", "email", "password", "created_at", "updated_at", "id") VALUES ('David', 'david@test.com', 'david123', '2012-11-25 17:43:02', '2012-11-25 17:43:02', 127326141)
显然devise提供的password方法没有被调用。运行此测试的正确方法是什么?