I have an odd problem. I got controllers in a namespace and
controllers outside of the namespace. For example, I have a
PagesController and a Admin::PagesController.
When I run rspec from the top, tests pass and I get the following
warning:
spec/controllers/admin/pages_controller_spec.rb:4: warning: toplevel
constant PagesController referenced by Admin::PagesController
This makes no sense. I do have a PagesController and an
Admin::PagesController and specs for both that are declared properly.
This makes no sense. I do have a PagesController and an
Admin::PagesController and specs for both that are declared properly.
I would guess it’s Ruby trying to warn you that the use of the
constant PagesController in Admin::PagesController references the
top-level PagesController, not Admin::PagesController. It can’t know
which one you mean.
To make the warning go away, you can use ::PagesController where you
mean the top-level PagesController.
These are identical, unless I’m blind The only thing different is
timestamps - it looks like in the case where things work the Admin
spec is loaded after the non-admin spec.
describe Admin::PagesController do
include Devise::TestHelpers
before(:each) do
controller.stub!(:app_initialization).and_return(true)
log_in_test_user(Admin)
end
(changing PagesController to ::PagesController does nothing)
the following is lifted from the ‘Gotchas’ section of my own internal
wiki, i hope it help’s someone else some day.
Can’t load namespaced controllers
Errors:
warning: toplevel constant Finance referenced by Member::Finance
OR
uninitialized constant Finance
Cause:
a namespaced controller / helper which is listed BEFORE it’s dependency.
e.g. ll member/finance/ bank_batches_controller.rb base_controller.rb
Fix:
make this the first line of the dependent require_dependency
“#{RAILS_ROOT}/app/controllers/member/finance/base_controller”.
requiring the dependent file before attempting to load the class. Yes,
this goes before class …
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.