2009-10-09 01:12:28 +00:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class InitializerTest < Test::Unit::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
2009-12-23 01:03:23 +00:00
|
|
|
def new_app
|
|
|
|
File.expand_path("#{app_path}/../new_app")
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_app
|
|
|
|
FileUtils.cp_r(app_path, new_app)
|
|
|
|
end
|
|
|
|
|
2009-10-09 01:12:28 +00:00
|
|
|
def setup
|
2009-12-23 01:03:23 +00:00
|
|
|
FileUtils.rm_rf(new_app) if File.directory?(new_app)
|
2009-10-09 01:12:28 +00:00
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
|
|
|
test "the application root is set correctly" do
|
2009-10-14 23:13:45 +00:00
|
|
|
require "#{app_path}/config/environment"
|
2009-10-16 19:49:39 +00:00
|
|
|
assert_equal Pathname.new(app_path), Rails.application.root
|
2009-10-14 23:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "the application root can be set" do
|
2009-12-23 01:03:23 +00:00
|
|
|
copy_app
|
2009-10-14 23:13:45 +00:00
|
|
|
add_to_config <<-RUBY
|
2009-12-23 01:03:23 +00:00
|
|
|
config.root = '#{new_app}'
|
2009-10-14 23:13:45 +00:00
|
|
|
RUBY
|
|
|
|
|
2009-12-23 01:03:23 +00:00
|
|
|
use_frameworks []
|
|
|
|
|
2009-10-14 23:13:45 +00:00
|
|
|
require "#{app_path}/config/environment"
|
2009-12-23 01:03:23 +00:00
|
|
|
assert_equal Pathname.new(new_app), Rails.application.root
|
2009-10-14 23:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "the application root is Dir.pwd if there is no config.ru" do
|
|
|
|
File.delete("#{app_path}/config.ru")
|
|
|
|
|
2009-12-23 01:03:23 +00:00
|
|
|
use_frameworks []
|
|
|
|
|
|
|
|
Dir.chdir("#{app_path}") do
|
2009-10-14 23:13:45 +00:00
|
|
|
require "#{app_path}/config/environment"
|
2009-12-23 01:03:23 +00:00
|
|
|
assert_equal Pathname.new("#{app_path}"), Rails.application.root
|
2009-10-14 23:13:45 +00:00
|
|
|
end
|
2009-10-09 01:12:28 +00:00
|
|
|
end
|
2009-12-02 18:14:02 +00:00
|
|
|
|
|
|
|
test "config.active_support.bare does not require all of ActiveSupport" do
|
2009-12-23 01:03:23 +00:00
|
|
|
add_to_config "config.active_support.bare = true"
|
|
|
|
|
|
|
|
use_frameworks []
|
2009-12-02 18:14:02 +00:00
|
|
|
|
|
|
|
Dir.chdir("#{app_path}/app") do
|
|
|
|
require "#{app_path}/config/environment"
|
2009-12-23 01:03:23 +00:00
|
|
|
assert_raises(NoMethodError) { [1,2,3].rand }
|
2009-12-02 18:14:02 +00:00
|
|
|
end
|
|
|
|
end
|
2009-12-16 06:07:12 +00:00
|
|
|
|
|
|
|
test "marking the application as threadsafe sets the correct config variables" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.threadsafe!
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/application"
|
2009-12-22 00:57:23 +00:00
|
|
|
assert AppTemplate::Application.configuration.action_controller.allow_concurrency
|
2009-12-16 06:07:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "the application can be marked as threadsafe when there are no frameworks" do
|
|
|
|
FileUtils.rm_rf("#{app_path}/config/environments")
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.frameworks = []
|
|
|
|
config.threadsafe!
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
require "#{app_path}/config/application"
|
|
|
|
end
|
|
|
|
end
|
2009-10-09 01:12:28 +00:00
|
|
|
end
|
2009-12-07 01:23:43 +00:00
|
|
|
end
|