Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'spec_helper'
require 'rails/paths'
require 'pathname'
def Rails.env
'test'
end unless Rails.respond_to? :env
describe Rails::Paths::Root do
let(:app_path) { Pathname.new RAILS_ROOT }
let(:paths) { described_class.new app_path }
before do
# rails/engine/configuration.rb
paths.add "app", :eager_load => true, :glob => "*"
paths.add "app/assets", :glob => "*"
paths.add "app/controllers", :eager_load => true
paths.add "app/helpers", :eager_load => true
paths.add "app/models", :eager_load => true
paths.add "app/mailers", :eager_load => true
paths.add "app/views"
paths.add "lib", :load_path => true
paths.add "lib/assets", :glob => "*"
paths.add "lib/tasks", :glob => "**/*.rake"
paths.add "config"
paths.add "config/environments", :glob => "#{Rails.env}.rb"
paths.add "config/initializers", :glob => "**/*.rb"
paths.add "config/locales", :glob => "*.{rb,yml}"
paths.add "config/routes", :with => "config/routes.rb"
paths.add "db"
paths.add "db/migrate"
paths.add "db/seeds", :with => "db/seeds.rb"
paths.add "vendor", :load_path => true
paths.add "vendor/assets", :glob => "*"
paths.add "vendor/plugins"
# rails/application/configuration.rb
paths.add "config/database", :with => "config/database.yml"
paths.add "config/environment", :with => "config/environment.rb"
paths.add "lib/templates"
paths.add "log", :with => "log/#{Rails.env}.log"
paths.add "public"
paths.add "public/javascripts"
paths.add "public/stylesheets"
paths.add "tmp"
end
describe 'eager_load' do
let(:eager_load) { paths.eager_load }
it "respect children's will" do
eager_load.should include(root("app/controllers"))
eager_load.should include(root("app/helpers"))
eager_load.should include(root("app/models"))
eager_load.should_not include(root("app/views"))
eager_load.should_not include(root("app/assets"))
end
end
it "booting up Rails yields a valid paths object" do
paths["app/models" ].expanded.should eq([root("app/models")])
paths["app/helpers" ].expanded.should eq([root("app/helpers")])
paths["app/views" ].expanded.should eq([root("app/views")])
paths["lib" ].expanded.should eq([root("lib")])
paths["vendor" ].expanded.should eq([root("vendor")])
paths["vendor/plugins" ].expanded.should eq([root("vendor/plugins")])
paths["tmp" ].expanded.should eq([root("tmp")])
paths["config" ].expanded.should eq([root("config")])
paths["config/locales" ].expanded.should eq([root("config/locales/en.yml")])
paths["config/environment" ].expanded.should eq([root("config/environment.rb")])
paths["config/environments"].expanded.should eq([root("config/environments/#{Rails.env}.rb")])
paths["app/controllers"].expanded.first.should eq(root("app", "controllers"))
end
it "environments has a glob equal to the current environment" do
paths["config/environments"].glob.should eq("#{Rails.env}.rb")
end
it "load path includes each of the paths in config.paths as long as the directories exist" do
load_paths = (paths.load_paths + paths.autoload_paths + paths.eager_load).map {|p| root(p)}
load_paths.should include(root("app/controllers"))
load_paths.should include(root("app/models"))
load_paths.should include(root("app/helpers"))
load_paths.should include(root("lib"))
load_paths.should include(root("vendor"))
load_paths.should_not include(root("app", "views"))
load_paths.should_not include(root("app", "assets"))
load_paths.should_not include(root("config"))
load_paths.should_not include(root("config", "locales"))
load_paths.should_not include(root("config", "environments"))
load_paths.should_not include(root("tmp"))
load_paths.should_not include(root("tmp", "cache"))
end
def root *paths
File.expand_path File.join(app_path, *paths)
end
end
$:.unshift File.expand_path('../../lib', __FILE__)
RAILS_ROOT = File.expand_path('../../tmp/app_template', __FILE__)
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.