0
庵 - 最令人困惑的驗證錯誤不斷,考慮到我甚至不使用這個詞Friendly
我的角色模型是如何以往任何時候都看起來是這樣的:友好ID,友好的保留
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
這個詞?哦,這就對了,我不是。請幫助。