Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


FactoryGirl breaks FriendlyId.defaults #269

romansklenar opened this Issue · 2 comments

2 participants


I have placed FactoryGirl.find_definitions into factory_girl.rb initializer because I'm using FactoryGirl in seeds.rb and some rake tasks and I've noticed this weird behaviour: call of FactoryGirl.find_definitions in initializers/factory_girl.rb breaks evaluating of FriendlyId.defaults in initializers/friendly_id.rb. Application runs normally without any problem but everything what is inside of block FriendlyId.defaults is not evaluated.

# initializers/factory_girl.rb
# initializers/friendly_id.rb
FriendlyId.defaults do |config|
  config.base = :name
  config.use :slugged
  config.use :history
  config.use :reserved
  config.reserved_words = %w(new edit)

  FriendlyId::Slug.table_name = "slugs"


This should be related to the order in with initializers are being evaluated. I'm not 100% sure but, from a trivial check, initializers are evaluated in a stable, sort order. If that is the case, factory_girl.rb will always be evaluated before friendly_id.rb. If FactoryGirl runs first, then it wouldn't be able to see your FriendlyId defaults.

You could try either renaming your friendly_id.rb or moving that code somewhere else making sure FriendyId defaults are run first.

That said, I would strongly recommend against loading your FactoryGirl definitions all the time. They'll be available in your tests. If you need them in seeds.rb or rake tasks, load them as required. There no reason to do that in production, for example.

@xymbol xymbol closed this

Sure, you're right - there's no need to load definitions all the time. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.