class User < ActiveRecord::Base
attr_accessible :username, :password
attr_accessor :username, :password
validates :username, :presence => true, :uniqueness => true
validates :password, :presence => true
end
测试:
it "prevents username duplication" do
FactoryGirl.create(:user, username: 'ted').should be_valid
FactoryGirl.build(:user, username: 'ted').should_not be_valid
end
我已确认User.count()
是2.我对唯一性约束缺少什么?
答案 0 :(得分:0)
attr_accessor打破了模型。摆脱那条线。