0

Um - Most confusing validation error ever, considering I am not even using the word Friendly how ever my model for roles looks like this:

class Role < ActiveRecord::Base
  validates :role, presence: true

  extend FriendlyId
  friendly_id :role, use: [:slugged, :history]
end

(Yes I have the proper migration .. Lets look at those too ... )

class AddSlugToRoles < ActiveRecord::Migration
  def change
    add_column :roles, :slug, :string
    add_index :roles, :slug
  end
end

Now lets create a factory girl

FactoryGirl.define do
  factory :adminRole, :class => 'Role' do
    role "Admin"
  end

  factory :userRole, :class => 'Role' do
    role "User"
  end  
end

Finally lets write a spec and make sure we can create roles:

  context "Validation checks" do
    it "validates a role object" do
      FactoryGirl.build(:adminRole).should be_valid
    end
  end

We then get a failing message of:

  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)>'

I'm sorry what? Where am I using the word Friendly? Oh thats right, I'm not. Help please.

Adam
  • 609
  • 2
  • 8
  • 15

1 Answers1

1

Turns of the use of the word admin is considered reserved. theres also a ton of other words like

config.reserved_words = %w(new edit index session login logout users admin stylesheets assets javascripts images)

that are also reserved.

Adam
  • 609
  • 2
  • 8
  • 15