Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to blacklist directory loading in Rails?

I want to disable ActiveAdmin when running the tests.

So I add require: false to the Gemfile and checking if defined?(ActiveAdmin) in routes and initializer.

But Rails still loads the models form app/admin thus I am getting error similar to /app/admin/admin_user.rb:1:in': uninitialized constant ActiveAdmin (NameError)`

What is the best way to "blacklist" the app/admin directory from being loaded?

like image 339
Dmytrii Nagirniak Avatar asked Dec 07 '12 04:12

Dmytrii Nagirniak


1 Answers

# config/environments/test.rb

path_rejector = lambda { |s| s.include?("app/admin") }

# Remove the path from being loaded when Rails starts:
config.eager_load_paths = config.eager_load_paths.reject(&path_rejector)

# Remove the path from being lazily loaded
ActiveSupport::Dependencies.autoload_paths.reject!(&path_rejector)
like image 83
Dmytrii Nagirniak Avatar answered Nov 05 '22 03:11

Dmytrii Nagirniak