嗯 - 有史以来最令人困惑的验证错误,考虑到我什至没有使用这个词Friendly
,我的角色模型看起来像这样:
class Role < ActiveRecord::Base
validates :role, presence: true
extend FriendlyId
friendly_id :role, use: [:slugged, :history]
end
(是的,我有适当的迁移......让我们也看看那些......)
class AddSlugToRoles < ActiveRecord::Migration
def change
add_column :roles, :slug, :string
add_index :roles, :slug
end
end
现在让我们创建一个工厂女孩
FactoryGirl.define do
factory :adminRole, :class => 'Role' do
role "Admin"
end
factory :userRole, :class => 'Role' do
role "User"
end
end
最后让我们编写一个规范并确保我们可以创建角色:
context "Validation checks" do
it "validates a role object" do
FactoryGirl.build(:adminRole).should be_valid
end
end
然后我们收到一条失败消息:
1) Role Validation checks validates a role object
Failure/Error: FactoryGirl.build(:adminRole).should be_valid
expected #<Role id: nil, role: "Admin", created_at: nil, updated_at: nil, slug: "admin"> to be valid, but got errors: Friendly is reserved
# ./spec/models/role_spec.rb:14:in `block (3 levels) in <top (required)>'
对不起什么?我在哪里使用这个词Friendly
?哦,对了,我不是。请帮忙。