Rails: Nested Namespace'd Controller in Rails 3.2 fails to load (fine in 3.0)

Go To StackoverFlow.com

2

I have a controller named Reports::Accountant::ApprovedTimeOffRequestsController. It's in the proper directory, and the class name is correct in the file its self. Rails console and unicorn load just fine, but rspec can't seem to load the file during testing.

Here's the error.

/Users/mdarby/.rvm/gems/ruby-1.9.3-p125-perf/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:503:in load_missing_constant': Expected /Users/mdarby/Documents/Code/ccw_32/app/controllers/reports/accountant/approved_time_off_requests_controller.rb to define Reports::Accountant::ApprovedTimeOffRequestsController (LoadError) from /Users/mdarby/.rvm/gems/ruby-1.9.3-p125-perf/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:192:in block in const_missing'

This file was find on Rails 3.0 stack, but now that I've upgraded to 3.2/rspec 2.9 this is bombing out.

The definition of the class: class Reports::Accountant::ApprovedTimeOffRequestsController < ApplicationController

EDIT:

If anyone comes across this, I solved it by removing the specs :)

2012-04-05 00:49
by Matt Darby
Which version of RSpec were you using with Rails 3.0? I suspect the upgrade to RSpec 2.9 is what's breaking this - Brandan 2012-04-05 01:07
Did the test parse with the earlier version? Or did the syntax for that test change - Ekampp 2012-04-05 06:57
I'm using RSpec 2.9 (now). This spec loaded just fine (as did the entire Reports::Accountant directory worth of specs.) I've not updated a bit of the test nor structure - Matt Darby 2012-04-05 23:50
This sounds like a bug in RSpec. What happens if you downgrade to RSpec 2.8/Rails 3.2 - Brandan 2012-04-06 02:22
I tried 2.8, all the way down to 2.3. No luck. I formerly used RSpec 2.3 on Rails 3.0 just fine - Matt Darby 2012-04-06 11:46
I've got a similar case - only it runs fine in rails-free (gem) RSpec, but bombs on the second load in rails (e.g. with 3.2 autoloading) Rails has the correct path, is running the file, the constant is being defined, but it's not recognizing it - Justin Love 2012-04-06 16:09


0

I bet you're using Spork. I ran into this exact problem. I removed Spork and I was on my way. Give that a whack and let me know if it fixed it. Might be worth filing an issue on spork if that's the case.

2012-07-26 09:26
by Tony Schneider
In fact, I was. I ended up just deleting the specs (the were rather weak controller specs anyhow) - Matt Darby 2012-07-26 13:11


0

Are you doing anything fancy with your tests? I had a case in the app itself where multiple threads were trying to load the same module. I can only guess that one marks it as loaded before it actually runs it, and then the constant isn't available to the next. In any case, my solution was to add a prepare block outside the threading.

development.rb (you might need this in test.rb)

ActionDispatch::Reloader.to_prepare do
  Reports::Accountant::ApprovedTimeOffRequestsController
end
2012-04-06 16:48
by Justin Love
Unfortunately this didn't do much. I've modified it to include all Report Controllers in the reports/* directories to no avail - Matt Darby 2012-04-10 14:25
Ads