aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb47
-rw-r--r--railties/test/application/generators_test.rb30
-rw-r--r--railties/test/application/initializer_test.rb60
-rw-r--r--railties/test/application/load_test.rb8
-rw-r--r--railties/test/application/routing_test.rb7
-rw-r--r--railties/test/initializable_test.rb10
-rw-r--r--railties/test/isolation/abstract_unit.rb8
-rw-r--r--railties/test/plugins/framework_extension_test.rb18
8 files changed, 105 insertions, 83 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index d60e0b904c..4d9da525d7 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,42 @@ 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 "if there's no config.active_support.bare, all of ActiveSupport is required" do
+ use_frameworks []
+ require "#{app_path}/config/environment"
+ assert_nothing_raised { [1,2,3].rand }
+ 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..2ecc3e9e2d 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
@@ -148,21 +135,9 @@ module ApplicationTests
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
- test "database middleware doesn't initialize when activerecord is not in frameworks" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.frameworks = []
- RUBY
- require "#{app_path}/config/environment"
-
- assert_equal [], Rails.application.config.middleware
- end
-
test "database middleware initializes when session store is active record" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- config.action_controller.session_store = :active_record_store
- RUBY
+ add_to_config "config.action_controller.session_store = :active_record_store"
+
require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
@@ -170,35 +145,28 @@ module ApplicationTests
assert_equal expects, middleware & expects
end
- test "ensure database middleware doesn't use action_controller on initializing" do
+ test "Rails.root should be a Pathname" do
add_to_config <<-RUBY
config.root = "#{app_path}"
- config.frameworks -= [:action_controller]
- config.action_controller.session_store = :active_record_store
RUBY
require "#{app_path}/config/environment"
-
- assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
+ assert_instance_of Pathname, Rails.root
end
+ 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"
+ class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
- assert_equal nil, ActionMailer::Base.template_root
- assert_equal [], ActionController::Base.view_paths
+ def setup
+ build_app
+ boot_rails
end
- test "Rails.root should be a Pathname" do
- add_to_config <<-RUBY
- config.root = "#{app_path}"
- RUBY
+ test "database middleware doesn't initialize when activerecord is not in frameworks" do
+ use_frameworks []
require "#{app_path}/config/environment"
- assert_instance_of Pathname, Rails.root
+
+ assert !defined?(ActiveRecord)
end
end
end \ No newline at end of file
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index e17f1ebdb0..1c5811b07a 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
@@ -22,8 +20,10 @@ module ApplicationTests
end
test "config.ru can be racked up" do
- @app = rackup
- assert_welcome get("/")
+ Dir.chdir app_path do
+ @app = rackup
+ assert_welcome get("/")
+ end
end
test "Rails.application is available after config.ru has been racked up" do
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index ece9b13f8a..725dd06929 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -19,6 +19,11 @@ module ApplicationTests
end
end
+ test "rails/info/properties" do
+ get "/rails/info/properties"
+ assert_equal 200, last_response.status
+ end
+
test "simple controller" do
controller :foo, <<-RUBY
class FooController < ActionController::Base
@@ -166,6 +171,8 @@ module ApplicationTests
end
RUBY
+ sleep 0.1
+
get '/foo'
assert_equal 'baz', last_response.body
end
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index a9e60680ac..e308cbcb0e 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -150,6 +150,16 @@ module InitializableTests
Word.run_initializers
assert_equal "bird", $word
end
+
+ test "creating initializer without a block raises an error" do
+ assert_raise(ArgumentError) do
+ Class.new do
+ include Rails::Initializable
+
+ initializer :foo
+ end
+ end
+ end
end
class BeforeAfter < ActiveSupport::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
diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb
new file mode 100644
index 0000000000..87e19cadce
--- /dev/null
+++ b/railties/test/plugins/framework_extension_test.rb
@@ -0,0 +1,18 @@
+require "isolation/abstract_unit"
+
+module PluginsTest
+ class FrameworkExtensionTest < Test::Unit::TestCase
+ def setup
+ build_app
+ boot_rails
+ end
+
+ test "active_record extensions are applied to ActiveRecord" do
+ add_to_config "config.active_record.table_name_prefix = 'tbl_'"
+
+ require "#{app_path}/config/environment"
+
+ assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix
+ end
+ end
+end \ No newline at end of file