模型:
class Contact < ActiveRecord::Base
validates :gender, :inclusion => { :in => ['male', 'female'] }
end
移民:
class CreateContacts < ActiveRecord::Migration
def change
create_table "contacts", :force => true do |t|
t.string "gender", :limit => 6, :default => 'male'
end
end
end
RSpec 测试:
describe Contact do
it { should validate_inclusion_of(:gender).in(['male', 'female']) }
end
结果:
Expected Contact to be valid when gender is set to ["male", "female"]
有人知道为什么这个规范没有通过吗?或者任何人都可以重建和(in)验证它吗?谢谢你。