Custom inputs no longer automatically found in Spork environment #851

rmm5t opened this Issue May 24, 2012 · 6 comments


None yet
7 participants

rmm5t commented May 24, 2012

After upgrading from Formtastic 2.0.x to 2.2.0, my custom inputs were no longer automatically found during my controller tests ("functional" tests). Upon further review, I think this is because of the new behavior surrounding the cache_classes config while searching for input classes and because I use Spork in my test environment.

My current workaround is to require all the classes in app/inputs inside Spork's prefork block:

Spork.prefork do
  # ...

  # Load all files under app/inputs. Neccesary to get Formtastic's custom inputs
  # to work in a Spork environment while config.cache_classes is set to true
  Dir["app/inputs/*_input.rb"].each { |f| require File.basename(f) }

I'm opening this up here in hopes of feedback, a more elegant fix, and/or helping someone else with a similar problem. If this warrants a README update, I'd be happy to write the addition. If not, feel free to close.

Thanks rmm5t, we've run into the same problem with our project and your patch works great here too.

+1, had the same problem and the workaround works ;-)

Thanks rmm5t, +1 from me too. Definitely worth adding a note to the README.

The wiki on the spork github project also has a bunch of spec_helper example snippets showing how to avoid problems with common gems (devise, factory_girl etc.). Formtastic is clearly worth adding to that list too.

rwjblue commented Mar 6, 2013

This is also an issue in spring.

Spring is setting the loading mechanism to :load which essentially overrides the functionality of Rails.application.config.cache_classes (but not really).

This patch solves the issue for Spring (and it appears to have the same general effect as the current code):

+1, we had the same problem with our project. We're using the surveyor gem which relies on formtastic.

Thanks rmm5t, your workaround worked for us too, after modifying it to work on the surveyor gem's app/inputs folder:

  surveyor_path = Gem.loaded_specs['surveyor'].full_gem_path
  Dir["#{surveyor_path}/app/inputs/*_input.rb"].each { |f| require File.basename(f) }

justinfrench commented Jul 4, 2013

Closing, as the work-around is documented and there's been a lack of activity here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment