FactoryGirl breaks FriendlyId.defaults #269

romansklenar opened this Issue Apr 22, 2012 · 2 comments


None yet
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"

xymbol commented Dec 9, 2012


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 closed this Dec 9, 2012

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