Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom inputs no longer automatically found in Spork environment #851

Closed
rmm5t opened this issue May 24, 2012 · 6 comments
Closed

Custom inputs no longer automatically found in Spork environment #851

rmm5t opened this issue May 24, 2012 · 6 comments

Comments

@rmm5t
Copy link
Contributor

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) }
end

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.

@gravitystorm
Copy link

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

@axelerator
Copy link

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

@sprotheroe
Copy link

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
Copy link

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): https://gist.github.com/rjackson/5096208.

@rrschmidt
Copy link

+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
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants