Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Custom Formtastic inputs not loaded from app/inputs #95

Closed
exviva opened this Issue · 6 comments

4 participants

@exviva

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.

@rwjblue

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
@rwjblue

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).

@rwjblue

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

@exviva

@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.

@jonleighton
Collaborator

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

@jonleighton jonleighton reopened this
@samccone

+1 to this issue

happening with zeus running cucumber tests

@jonleighton jonleighton closed this issue from a commit
@jonleighton jonleighton Set config.cache_classes = false
We're setting ActiveSupport::Dependencies.mechanism = :load, so this is
just for consistency.

Fixes #95.
3a9e08c
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.