Custom Formtastic inputs not loaded from app/inputs #95

Closed
exviva opened this Issue Mar 5, 2013 · 6 comments

Comments

Projects
None yet
4 participants
Contributor

exviva commented Mar 5, 2013

When running the specs in my app with spring rspec spec/features/administrator/manage_stores.feature, I'm getting the following error: ActionView::Template::Error: Unable to find input class HtmlEditorInput

Of course, when runnning the spec with rspec spec/features/administrator/manage_stores.feature everything is fine.

I'm using Formtastic's custom inputs (actually, provided by another gem).

Note that the same is happening for inputs from my app's app/inputs directory.

Any ideas what may be going on? I'd like to provide a patch, but I don't even know where to start.

Contributor

rwjblue commented Mar 6, 2013

Looks like the issue is with Formatistic keying off of the value of Rails.application.config.cache_classes here. Basically, cache_classes is set to true (by default in test), but we are clearing the loaded classes via ActionDispatch::Reloader.prepare! (and Formtastic doesn't reload them for us).

This patch fixes Formtastic to work with spring, but I am not 100% that it is the 'right' way to handle this.

Another solution is to add the following to your config/spring.rb:

Spring.after_fork do
  Dir["app/inputs/*_input.rb"].each { |f| require File.basename(f) }
end
Contributor

rwjblue commented Mar 6, 2013

You could also change config/environments/test.rb to have cache_classes set to false (again, I am not sure what the 'right' solution is here).

Contributor

rwjblue commented Mar 6, 2013

As an aside, I updated a sample repo that demonstrates the error: rjackson/factory_girl_spring_test.

Contributor

exviva commented Mar 7, 2013

@rjackson thanks a lot for your remarks. Do you think checking ActiveSupport::Dependencies.mechanism should be the "blessed" way to solve this? It looks like formtastic is making wrong assumptions about the cache_classes option, so I'd submit a PR to formtastic.

Member

jonleighton commented Jun 21, 2013

I can't remember exactly why I used ActiveSupport::Dependencies.mechanism rather than setting cache_classes. I should revisit that.

jonleighton reopened this Jun 21, 2013

+1 to this issue

happening with zeus running cucumber tests

@zdavis zdavis added a commit to ManifoldScholar/manifold that referenced this issue Mar 4, 2016

@zdavis zdavis [B] Solve unitialized constant when running tests
In the test environment, config.cache_classes had the effect of
triggering an uninitialized constant exception if a model class was
changed between test runs. In theory, spring is setting cache_classes
to false automatically, but we found that it had to be set explicitly
to avoid errors.

See the following issues for context:
rails/spring#384
rails/spring#95
bc87112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment