aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb41
-rw-r--r--railties/test/application/generators_test.rb30
-rw-r--r--railties/test/application/initializer_test.rb26
-rw-r--r--railties/test/application/load_test.rb2
-rw-r--r--railties/test/isolation/abstract_unit.rb8
5 files changed, 46 insertions, 61 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 83e1401993..0f702c7014 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -4,7 +4,16 @@ module ApplicationTests
class InitializerTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
+ def new_app
+ File.expand_path("#{app_path}/../new_app")
+ end
+
+ def copy_app
+ FileUtils.cp_r(app_path, new_app)
+ end
+
def setup
+ FileUtils.rm_rf(new_app) if File.directory?(new_app)
build_app
boot_rails
end
@@ -15,42 +24,36 @@ module ApplicationTests
end
test "the application root can be set" do
- FileUtils.mkdir_p("#{app_path}/hello")
+ copy_app
add_to_config <<-RUBY
- config.frameworks = []
- config.root = '#{app_path}/hello'
+ config.root = '#{new_app}'
RUBY
- require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
- end
- test "the application root is detected as where config.ru is located" do
- add_to_config <<-RUBY
- config.frameworks = []
- RUBY
- FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
+ use_frameworks []
+
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
+ assert_equal Pathname.new(new_app), Rails.application.root
end
test "the application root is Dir.pwd if there is no config.ru" do
File.delete("#{app_path}/config.ru")
- add_to_config <<-RUBY
- config.frameworks = []
- RUBY
- Dir.chdir("#{app_path}/app") do
+ use_frameworks []
+
+ Dir.chdir("#{app_path}") do
require "#{app_path}/config/environment"
- assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
+ assert_equal Pathname.new("#{app_path}"), Rails.application.root
end
end
test "config.active_support.bare does not require all of ActiveSupport" do
- add_to_config "config.frameworks = []; config.active_support.bare = true"
+ add_to_config "config.active_support.bare = true"
+
+ use_frameworks []
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
- assert_raises(NoMethodError) { 1.day }
+ assert_raises(NoMethodError) { [1,2,3].rand }
end
end
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index 2ed49d1057..7b27c780aa 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -7,8 +7,6 @@ module ApplicationTests
def setup
build_app
boot_rails
- require "rails"
- require "rails/generators"
end
def app_const
@@ -16,6 +14,8 @@ module ApplicationTests
end
def with_config
+ require "rails"
+ require "rails/generators"
yield app_const.config
end
@@ -46,14 +46,15 @@ module ApplicationTests
end
test "generators aliases and options on initialization" do
- application = with_config do |c|
- c.frameworks = []
- c.generators.rails :aliases => { :test_framework => "-w" }
- c.generators.orm :datamapper
- c.generators.test_framework :rspec
- end
+ add_to_config <<-RUBY
+ config.generators.rails :aliases => { :test_framework => "-w" }
+ config.generators.orm :datamapper
+ config.generators.test_framework :rspec
+ RUBY
+
+ require "#{app_path}/config/environment"
# Initialize the application
- app_const.initialize!
+ require "rails/generators"
Rails::Generators.configure!
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
@@ -61,12 +62,13 @@ module ApplicationTests
end
test "generators no color on initialization" do
- with_config do |c|
- c.frameworks = []
- c.generators.colorize_logging = false
- end
+ add_to_config <<-RUBY
+ config.generators.colorize_logging = false
+ RUBY
+
# Initialize the application
- app_const.initialize!
+ require "#{app_path}/config/environment"
+ require "rails/generators"
Rails::Generators.configure!
assert_equal Thor::Base.shell, Thor::Shell::Basic
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index b3eff1deb9..8ed8e11c8f 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -19,19 +19,6 @@ module ApplicationTests
assert $:.include?("#{app_path}/app/models")
end
- test "adding an unknown framework raises an error" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.frameworks << :action_foo
- RUBY
-
- require "active_support/core_ext/load_error"
-
- assert_raises MissingSourceFile do
- require "#{app_path}/config/environment"
- end
- end
-
test "eager loading loads parent classes before children" do
app_file "lib/zoo.rb", <<-ZOO
class Zoo ; include ReptileHouse ; end
@@ -180,19 +167,6 @@ module ApplicationTests
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
-
- # Pathview test
- test "load view paths doesn't perform anything when action_view not in frameworks" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.frameworks -= [:action_view]
- RUBY
- require "#{app_path}/config/environment"
-
- assert_equal nil, ActionMailer::Base.template_root
- assert_equal [], ActionController::Base.view_paths
- end
-
test "Rails.root should be a Pathname" do
add_to_config <<-RUBY
config.root = "#{app_path}"
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index e17f1ebdb0..689bc77ecf 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -1,6 +1,4 @@
require "isolation/abstract_unit"
-# require "rails"
-# require 'action_dispatch'
module ApplicationTests
class LoadTest < Test::Unit::TestCase
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index c169c80bea..ee0a812b47 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -153,6 +153,14 @@ module TestHelpers
app_file("app/controllers/#{name}_controller.rb", contents)
end
+ def use_frameworks(arr)
+ to_remove = [:actionmailer,
+ :activemodel,
+ :activerecord,
+ :activeresource] - arr
+ $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
+ end
+
def boot_rails
root = File.expand_path('../../../..', __FILE__)
begin