elia / paths_spec.rb secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View paths_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
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
View paths_spec.rb
1 2
$:.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.