2010-01-26 07:57:11 -05:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class LoadPathTest < ActiveSupport::TestCase
|
2010-01-26 07:57:11 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
FileUtils.rm_rf "#{app_path}/config/environments"
|
|
|
|
end
|
|
|
|
|
2011-06-05 13:27:52 -04:00
|
|
|
def teardown
|
2011-06-06 08:54:05 -04:00
|
|
|
teardown_app
|
2011-06-05 13:27:52 -04:00
|
|
|
end
|
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
test "initializing an application adds the application paths to the load path" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.root = "#{app_path}"
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
assert $:.include?("#{app_path}/app/models")
|
|
|
|
end
|
|
|
|
|
2013-03-24 09:35:41 -04:00
|
|
|
test "initializing an application allows to load code on lib path inside application class definition" do
|
2010-06-01 18:42:20 -04:00
|
|
|
app_file "lib/foo.rb", <<-RUBY
|
|
|
|
module Foo; end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
require "foo"
|
|
|
|
raise "Expected Foo to be defined" unless defined?(Foo)
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert $:.include?("#{app_path}/lib")
|
|
|
|
end
|
|
|
|
|
2010-01-27 15:20:32 -05:00
|
|
|
test "initializing an application eager load any path under app" do
|
|
|
|
app_file "app/anything/foo.rb", <<-RUBY
|
|
|
|
module Foo; end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.root = "#{app_path}"
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
assert Foo
|
|
|
|
end
|
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
test "eager loading loads parent classes before children" do
|
|
|
|
app_file "lib/zoo.rb", <<-ZOO
|
|
|
|
class Zoo ; include ReptileHouse ; end
|
|
|
|
ZOO
|
2010-01-27 15:20:32 -05:00
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
app_file "lib/zoo/reptile_house.rb", <<-ZOO
|
|
|
|
module Zoo::ReptileHouse ; end
|
|
|
|
ZOO
|
|
|
|
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.root = "#{app_path}"
|
2013-02-19 02:22:37 -05:00
|
|
|
config.eager_load_paths << "#{app_path}/lib"
|
2010-01-26 07:57:11 -05:00
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
assert Zoo
|
|
|
|
end
|
|
|
|
|
2013-10-29 18:58:52 -04:00
|
|
|
test "eager loading accepts Pathnames" do
|
|
|
|
app_file "lib/foo.rb", <<-RUBY
|
|
|
|
module Foo; end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.eager_load = true
|
|
|
|
config.eager_load_paths << Pathname.new("#{app_path}/lib")
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
assert Foo
|
|
|
|
end
|
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
test "load environment with global" do
|
2013-04-11 08:44:12 -04:00
|
|
|
$initialize_test_set_from_env = nil
|
2010-01-26 07:57:11 -05:00
|
|
|
app_file "config/environments/development.rb", <<-RUBY
|
|
|
|
$initialize_test_set_from_env = 'success'
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.configure do
|
2010-01-26 07:57:11 -05:00
|
|
|
config.cache_classes = true
|
|
|
|
config.time_zone = "Brasilia"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
assert_nil $initialize_test_set_from_env
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.root = "#{app_path}"
|
|
|
|
config.time_zone = "UTC"
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
assert_equal "success", $initialize_test_set_from_env
|
2013-06-09 22:47:07 -04:00
|
|
|
assert Rails.application.config.cache_classes
|
|
|
|
assert_equal "Brasilia", Rails.application.config.time_zone
|
2010-01-26 07:57:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|