aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-13 15:18:45 -0700
committerCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-13 15:18:45 -0700
commit906aebceedb95d8caa6db6314bc90f605bdfaf2b (patch)
tree5abc86bb6709b20df7cb5f4d1750b27c641dca4b /railties/test
parent2036d3ba75da1a0f3061bf5a33c89e2b2eaff420 (diff)
parentc877857d59554d78dbf45f5f9fcaafb8badec4e2 (diff)
downloadrails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.tar.gz
rails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.tar.bz2
rails-906aebceedb95d8caa6db6314bc90f605bdfaf2b.zip
Bring abstract_controller up to date with rails/master
Resolved all the conflicts since 2.3.0 -> HEAD. Following is a list of commits that could not be applied cleanly or are obviated with the abstract_controller refactor. They all need to be revisited to ensure that fixes made in 2.3 do not reappear in 3.0: 2259ecf368e6a6715966f69216e3ee86bf1a82a7 AR not available * This will be reimplemented with ActionORM or equivalent 06182ea02e92afad579998aa80144588e8865ac3 implicitly rendering a js response should not use the default layout [#1844 state:resolved] * This will be handled generically 893e9eb99504705419ad6edac14d00e71cef5f12 Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved] * We will need to reimplement rails-dev-boost on top of the refactor; the changes here are very implementation specific and cannot be cleanly applied. The following commits are implicated: 199e750d46c04970b5e7684998d09405648ecbd4 3942cb406e1d5db0ac00e03153809cc8dc4cc4db f8ea9f85d4f1e3e6f3b5d895bef6b013aa4b0690 e3b166aab37ddc2fbab030b146eb61713b91bf55 ae9f258e03c9fd5088da12c1c6cd216cc89a01f7 44423126c6f6133a1d9cf1d0832b527e8711d40f 0cb020b4d6d838025859bd60fb8151c8e21b8e84 workaround for picking layouts based on wrong view_paths [#1974 state:resolved] * The specifics of this commit no longer apply. Since it is a two-line commit, we will reimplement this change. 8c5cc66a831aadb159f3daaffa4208064c30af0e make action_controller/layouts pick templates from the current instance's view_paths instead of the class view_paths [#1974 state:resolved] * This does not apply at all. It should be trivial to apply the feature to the reimplemented ActionController::Base. 87e8b162463f13bd50d27398f020769460a770e3 fix HTML fallback for explicit templates [#2052 state:resolved] * There were a number of patches related to this that simply compounded each other. Basically none of them apply cleanly, and the underlying issue needs to be revisited. After discussing the underlying problem with Koz, we will defer these fixes for further discussion.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/abstract_unit.rb22
-rw-r--r--railties/test/backtrace_cleaner_test.rb65
-rw-r--r--railties/test/boot_test.rb7
-rw-r--r--railties/test/console_app_test.rb22
-rw-r--r--railties/test/error_page_test.rb40
-rw-r--r--railties/test/fcgi_dispatcher_test.rb69
-rw-r--r--railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb5
-rw-r--r--railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb5
-rw-r--r--railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb5
-rw-r--r--railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb5
-rw-r--r--railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb7
-rw-r--r--railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb7
-rw-r--r--railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb10
-rw-r--r--railties/test/fixtures/plugins/engines/engine/init.rb2
-rw-r--r--railties/test/fixtures/public/foo/bar.html1
-rw-r--r--railties/test/fixtures/public/foo/index.html1
-rw-r--r--railties/test/fixtures/public/index.html1
-rw-r--r--railties/test/gem_dependency_test.rb233
-rw-r--r--railties/test/generators/rails_scaffold_generator_test.rb24
-rw-r--r--railties/test/generators/rails_template_runner_test.rb32
-rw-r--r--railties/test/initializer_test.rb480
-rw-r--r--railties/test/metal_test.rb72
-rw-r--r--railties/test/plugin_loader_test.rb11
-rw-r--r--railties/test/plugin_locator_test.rb107
-rw-r--r--railties/test/plugin_test.rb271
-rw-r--r--railties/test/rack_static_test.rb46
-rw-r--r--railties/test/rails_info_controller_test.rb54
-rw-r--r--railties/test/rails_info_test.rb17
-rw-r--r--railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification2
29 files changed, 940 insertions, 683 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index b6edc03391..0addcb8bf3 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -1,22 +1,30 @@
$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
+$:.unshift File.dirname(__FILE__) + "/../../activerecord/lib"
$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
+$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
$:.unshift File.dirname(__FILE__) + "/../lib"
$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info"
+require 'stringio'
require 'rubygems'
require 'test/unit'
-gem 'mocha', '>= 0.9.3'
+
+gem 'mocha', '>= 0.9.5'
require 'mocha'
-require 'stringio'
+
require 'active_support'
require 'active_support/test_case'
-def uses_mocha(test_name)
- yield
-end
-
if defined?(RAILS_ROOT)
RAILS_ROOT.replace File.dirname(__FILE__)
else
RAILS_ROOT = File.dirname(__FILE__)
-end \ No newline at end of file
+end
+
+def uses_gem(gem_name, test_name, version = '> 0')
+ gem gem_name.to_s, version
+ require gem_name.to_s
+ yield
+rescue LoadError
+ $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
+end
diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb
index 5955fd2856..7a1b361440 100644
--- a/railties/test/backtrace_cleaner_test.rb
+++ b/railties/test/backtrace_cleaner_test.rb
@@ -3,26 +3,59 @@ require 'abstract_unit'
require 'initializer'
require 'rails/backtrace_cleaner'
-class TestWithBacktrace
- include Test::Unit::Util::BacktraceFilter
- include Rails::BacktraceFilterForTestUnit
+if defined? Test::Unit::Util::BacktraceFilter
+ class TestWithBacktrace
+ include Test::Unit::Util::BacktraceFilter
+ include Rails::BacktraceFilterForTestUnit
+ end
+
+ class BacktraceCleanerFilterTest < ActiveSupport::TestCase
+ def setup
+ @test = TestWithBacktrace.new
+ @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ]
+ end
+
+ test "test with backtrace should use the rails backtrace cleaner to clean" do
+ Rails.stubs(:backtrace_cleaner).returns(stub(:clean))
+ Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil)
+ @test.filter_backtrace(@backtrace)
+ end
+
+ test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do
+ assert_nothing_raised do
+ @test.filter_backtrace(@backtrace, '/opt/local/lib')
+ end
+ end
+ end
+else
+ $stderr.puts 'No BacktraceFilter for minitest'
end
-class BacktraceCleanerFilterTest < ActiveSupport::TestCase
+class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
def setup
- @test = TestWithBacktrace.new
- @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ]
+ @cleaner = Rails::BacktraceCleaner.new
end
-
- test "test with backtrace should use the rails backtrace cleaner to clean" do
- Rails.stubs(:backtrace_cleaner).returns(stub(:clean))
- Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil)
- @test.filter_backtrace(@backtrace)
+
+ test "should format installed gems correctly" do
+ @backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ @result = @cleaner.clean(@backtrace)
+ assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
end
-
- test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do
- assert_nothing_raised do
- @test.filter_backtrace(@backtrace, '/opt/local/lib')
+
+ test "should format installed gems not in Gem.default_dir correctly" do
+ @target_dir = Gem.path.detect { |p| p != Gem.default_dir }
+ # skip this test if default_dir is the only directory on Gem.path
+ if @target_dir
+ @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ @result = @cleaner.clean(@backtrace)
+ assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
end
end
-end \ No newline at end of file
+
+ test "should format vendor gems correctly" do
+ @backtrace = [ "#{Rails::GemDependency.unpacked_path}/nosuchgem-1.2.3/lib/foo.rb" ]
+ @result = @cleaner.clean(@backtrace)
+ assert_equal "nosuchgem (1.2.3) [v] lib/foo.rb", @result[0]
+ end
+
+end
diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb
index 7736a8f4c0..08fcc82e6f 100644
--- a/railties/test/boot_test.rb
+++ b/railties/test/boot_test.rb
@@ -2,8 +2,6 @@ require 'abstract_unit'
require 'initializer'
require "#{File.dirname(__FILE__)}/../environments/boot"
-uses_mocha 'boot tests' do
-
class BootTest < Test::Unit::TestCase
def test_boot_returns_if_booted
Rails.expects(:booted?).returns(true)
@@ -64,6 +62,8 @@ class VendorBootTest < Test::Unit::TestCase
def test_load_initializer_requires_from_vendor_rails
boot = VendorBoot.new
boot.expects(:require).with("#{RAILS_ROOT}/vendor/rails/railties/lib/initializer")
+ Rails::Initializer.expects(:run).with(:install_gem_spec_stubs)
+ Rails::GemDependency.expects(:add_frozen_gem_path)
boot.load_initializer
end
end
@@ -121,9 +121,6 @@ class GemBootTest < Test::Unit::TestCase
end
end
-end # uses_mocha
-
-
class ParseGemVersionTest < Test::Unit::TestCase
def test_should_return_nil_if_no_lines_are_passed
assert_equal nil, parse('')
diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb
index f419fe0d8d..f11de087e3 100644
--- a/railties/test/console_app_test.rb
+++ b/railties/test/console_app_test.rb
@@ -11,19 +11,19 @@ require 'dispatcher'
require 'console_app'
# console_app sets Test::Unit.run to work around the at_exit hook in test/unit, which kills IRB
-Test::Unit.run = false
-
-class ConsoleAppTest < Test::Unit::TestCase
- def test_app_method_should_return_integration_session
- assert_nothing_thrown do
- console_session = app
- assert_not_nil console_session
- assert_instance_of ActionController::Integration::Session,
- console_session
+if Test::Unit.respond_to?(:run=)
+ Test::Unit.run = false
+
+ class ConsoleAppTest < Test::Unit::TestCase
+ def test_app_method_should_return_integration_session
+ assert_nothing_thrown do
+ console_session = app
+ assert_not_nil console_session
+ assert_instance_of ActionController::Integration::Session,
+ console_session
+ end
end
- end
- uses_mocha 'console reload test' do
def test_reload_should_fire_preparation_callbacks
a = b = c = nil
diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb
deleted file mode 100644
index c0e8fe1ee0..0000000000
--- a/railties/test/error_page_test.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'abstract_unit'
-require 'action_controller'
-require 'action_controller/testing/test_case'
-
-RAILS_ENV = "test"
-CURRENT_DIR = File.expand_path(File.dirname(__FILE__))
-HTML_DIR = File.expand_path(File.join(CURRENT_DIR, "..", "html"))
-
-module Rails
- def self.public_path
- CURRENT_DIR
- end
-end
-
-class ErrorPageController < ActionController::Base
- def crash
- raise StandardError, "crash!"
- end
-end
-
-ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
-end
-
-class ErrorPageControllerTest < ActionController::TestCase
- def setup
- ActionController::Base.consider_all_requests_local = false
- rescue_action_in_public!
- end
-
- def test_500_error_page_instructs_system_administrator_to_check_log_file
- template = ERB.new(File.read(File.join(HTML_DIR, "500.html")))
- File.open(File.join(CURRENT_DIR, "500.html"), "w") do |f|
- f.write(template.result)
- end
- get :crash
- expected_log_file = "#{RAILS_ENV}.log"
- assert_not_nil @response.body.index(expected_log_file), @response.body
- end
-end
diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb
index c469c5dd01..c7a7f77118 100644
--- a/railties/test/fcgi_dispatcher_test.rb
+++ b/railties/test/fcgi_dispatcher_test.rb
@@ -1,9 +1,12 @@
require 'abstract_unit'
-begin
+uses_gem "fcgi", "0.8.7" do
+
require 'action_controller'
require 'fcgi_handler'
+Dispatcher.middleware.clear
+
class RailsFCGIHandlerTest < Test::Unit::TestCase
def setup
@log = StringIO.new
@@ -11,14 +14,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_restart
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:restart)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!)
@@ -26,14 +29,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_exit
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:exit)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!).never
@@ -41,8 +44,8 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_process_with_system_exit_exception
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once.raises(SystemExit)
@handler.stubs(:dispatcher_log)
@@ -110,9 +113,9 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
end
def test_uninterrupted_processing
- cgi = mock
- FCGI.expects(:each_cgi).yields(cgi)
- @handler.expects(:process_request).with(cgi)
+ request = mock
+ FCGI.expects(:each).yields(request)
+ @handler.expects(:process_request).with(request)
@handler.process!
@@ -138,8 +141,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_HUP_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('HUP')
@handler.expects(:reload!).once
@@ -151,13 +154,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_USR1_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR1')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.process!
@@ -165,13 +168,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_restart_via_USR2_when_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR2')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.expects(:restart!).once
@@ -180,8 +183,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
end
def test_interrupted_via_TERM
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
@handler.expects(:reload!).never
@@ -193,16 +196,16 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
def test_runtime_exception_in_fcgi
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).times(2).raises(error)
+ FCGI.expects(:each).times(2).raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/))
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_runtime_error_in_dispatcher
- cgi = mock
+ request = mock
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
@handler.process!
@@ -210,15 +213,15 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
def test_signal_exception_in_fcgi
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.raises(error)
+ FCGI.expects(:each).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_signal_exception_in_dispatcher
- cgi = mock
+ request = mock
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
@@ -247,9 +250,8 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
@handler = RailsFCGIHandler.new(@log, 10)
assert_equal 10, @handler.gc_request_period
- cgi = mock
- FCGI.expects(:each_cgi).times(10).yields(cgi)
- Dispatcher.expects(:new).times(10)
+ request = mock
+ FCGI.expects(:each).times(10).yields(request)
@handler.expects(:run_gc!).never
9.times { @handler.process! }
@@ -259,7 +261,4 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
assert_nil @handler.when_ready
end
end
-
-rescue LoadError => e
- raise unless e.message =~ /fcgi/
-end
+end # uses_gem "fcgi"
diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
new file mode 100644
index 0000000000..2d373ce422
--- /dev/null
+++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
@@ -0,0 +1,5 @@
+class MetalA < Rails::Rack::Metal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Hi"]]
+ end
+end
diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
new file mode 100644
index 0000000000..a8bbf3fd60
--- /dev/null
+++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
@@ -0,0 +1,5 @@
+class MetalB < Rails::Rack::Metal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Hi"]]
+ end
+end
diff --git a/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb
new file mode 100644
index 0000000000..0cd3737c32
--- /dev/null
+++ b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb
@@ -0,0 +1,5 @@
+class LegacyRoutes < Rails::Rack::Metal
+ def self.call(env)
+ [301, { "Location" => "http://example.com"}, []]
+ end
+end
diff --git a/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
new file mode 100644
index 0000000000..5f5b087592
--- /dev/null
+++ b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
@@ -0,0 +1,5 @@
+class FooMetal < Rails::Rack::Metal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Hi"]]
+ end
+end
diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb
new file mode 100644
index 0000000000..25b3bb0abc
--- /dev/null
+++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb
@@ -0,0 +1,7 @@
+module Folder
+ class MetalA < Rails::Rack::Metal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Hi"]]
+ end
+ end
+end
diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb
new file mode 100644
index 0000000000..7583363f71
--- /dev/null
+++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb
@@ -0,0 +1,7 @@
+module Folder
+ class MetalB < Rails::Rack::Metal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Hi"]]
+ end
+ end
+end
diff --git a/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb b/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb
new file mode 100644
index 0000000000..d67a127ca7
--- /dev/null
+++ b/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb
@@ -0,0 +1,10 @@
+class EngineMetal
+ def self.call(env)
+ if env["PATH_INFO"] =~ /^\/metal/
+ [200, {"Content-Type" => "text/html"}, ["Engine metal"]]
+ else
+ [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+ end
+ end
+end
+
diff --git a/railties/test/fixtures/plugins/engines/engine/init.rb b/railties/test/fixtures/plugins/engines/engine/init.rb
index f4b00c0fa4..64e9ae6c30 100644
--- a/railties/test/fixtures/plugins/engines/engine/init.rb
+++ b/railties/test/fixtures/plugins/engines/engine/init.rb
@@ -1,3 +1,3 @@
# My app/models dir must be in the load path.
require 'engine_model'
-raise 'missing model from my app/models dir' unless defined?(EngineModel)
+raise LoadError, 'missing model from my app/models dir' unless defined?(EngineModel)
diff --git a/railties/test/fixtures/public/foo/bar.html b/railties/test/fixtures/public/foo/bar.html
new file mode 100644
index 0000000000..9a35646205
--- /dev/null
+++ b/railties/test/fixtures/public/foo/bar.html
@@ -0,0 +1 @@
+/foo/bar.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/foo/index.html b/railties/test/fixtures/public/foo/index.html
new file mode 100644
index 0000000000..497a2e898f
--- /dev/null
+++ b/railties/test/fixtures/public/foo/index.html
@@ -0,0 +1 @@
+/foo/index.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/index.html b/railties/test/fixtures/public/index.html
new file mode 100644
index 0000000000..525950ba6b
--- /dev/null
+++ b/railties/test/fixtures/public/index.html
@@ -0,0 +1 @@
+/index.html \ No newline at end of file
diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
index 6c1f0961a1..189ad02b76 100644
--- a/railties/test/gem_dependency_test.rb
+++ b/railties/test/gem_dependency_test.rb
@@ -6,141 +6,142 @@ end
Rails::VendorGemSourceIndex.silence_spec_warnings = true
-uses_mocha "Plugin Tests" do
- class GemDependencyTest < Test::Unit::TestCase
- def setup
- @gem = Rails::GemDependency.new "xhpricotx"
- @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net"
- @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6"
- @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3"
- @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false
- end
+class GemDependencyTest < Test::Unit::TestCase
+ def setup
+ @gem = Rails::GemDependency.new "xhpricotx"
+ @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net"
+ @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6"
+ @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3"
+ @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false
+ end
- def test_configuration_adds_gem_dependency
- config = Rails::Configuration.new
- config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
- assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command)
- end
+ def test_configuration_adds_gem_dependency
+ config = Rails::Configuration.new
+ config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
+ assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command)
+ end
- def test_gem_creates_install_command
- assert_equal %w(install xhpricotx), @gem.install_command
- end
+ def test_gem_creates_install_command
+ assert_equal %w(install xhpricotx), @gem.install_command
+ end
- def test_gem_with_source_creates_install_command
- assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
- end
+ def test_gem_with_source_creates_install_command
+ assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
+ end
- def test_gem_with_version_creates_install_command
- assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
- end
+ def test_gem_with_version_creates_install_command
+ assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
+ end
- def test_gem_creates_unpack_command
- assert_equal %w(unpack xhpricotx), @gem.unpack_command
- end
+ def test_gem_creates_unpack_command
+ assert_equal %w(unpack xhpricotx), @gem.unpack_command
+ end
- def test_gem_with_version_unpack_install_command
- # stub out specification method, or else test will fail if hpricot 0.6 isn't installed
- mock_spec = mock()
- mock_spec.stubs(:version).returns('0.6')
- @gem_with_version.stubs(:specification).returns(mock_spec)
- assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command
- end
+ def test_gem_with_version_unpack_install_command
+ # stub out specification method, or else test will fail if hpricot 0.6 isn't installed
+ mock_spec = mock()
+ mock_spec.stubs(:version).returns('0.6')
+ @gem_with_version.stubs(:specification).returns(mock_spec)
+ assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command
+ end
- def test_gem_adds_load_paths
- @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
- @gem.add_load_paths
- end
+ def test_gem_adds_load_paths
+ @gem.expects(:gem).with(@gem)
+ @gem.add_load_paths
+ end
- def test_gem_with_version_adds_load_paths
- @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s))
- @gem_with_version.add_load_paths
- end
+ def test_gem_with_version_adds_load_paths
+ @gem_with_version.expects(:gem).with(@gem_with_version)
+ @gem_with_version.add_load_paths
+ assert @gem_with_version.load_paths_added?
+ end
- def test_gem_loading
- @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
- @gem.expects(:require).with(@gem.name)
- @gem.add_load_paths
- @gem.load
- end
+ def test_gem_loading
+ @gem.expects(:gem).with(@gem)
+ @gem.expects(:require).with(@gem.name)
+ @gem.add_load_paths
+ @gem.load
+ assert @gem.loaded?
+ end
- def test_gem_with_lib_loading
- @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil))
- @gem_with_lib.expects(:require).with(@gem_with_lib.lib)
- @gem_with_lib.add_load_paths
- @gem_with_lib.load
- end
+ def test_gem_with_lib_loading
+ @gem_with_lib.expects(:gem).with(@gem_with_lib)
+ @gem_with_lib.expects(:require).with(@gem_with_lib.lib)
+ @gem_with_lib.add_load_paths
+ @gem_with_lib.load
+ assert @gem_with_lib.loaded?
+ end
- def test_gem_without_lib_loading
- @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil))
- @gem_without_load.expects(:require).with(@gem_without_load.lib).never
- @gem_without_load.add_load_paths
- @gem_without_load.load
- end
+ def test_gem_without_lib_loading
+ @gem_without_load.expects(:gem).with(@gem_without_load)
+ @gem_without_load.expects(:require).with(@gem_without_load.lib).never
+ @gem_without_load.add_load_paths
+ @gem_without_load.load
+ end
- def test_gem_dependencies_compare_for_uniq
- gem1 = Rails::GemDependency.new "gem1"
- gem1a = Rails::GemDependency.new "gem1"
- gem2 = Rails::GemDependency.new "gem2"
- gem2a = Rails::GemDependency.new "gem2"
- gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem4 = Rails::GemDependency.new "gem3"
- gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
- assert_equal 4, gems.uniq.size
- end
+ def test_gem_dependencies_compare_for_uniq
+ gem1 = Rails::GemDependency.new "gem1"
+ gem1a = Rails::GemDependency.new "gem1"
+ gem2 = Rails::GemDependency.new "gem2"
+ gem2a = Rails::GemDependency.new "gem2"
+ gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
+ gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
+ gem4 = Rails::GemDependency.new "gem3"
+ gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
+ assert_equal 4, gems.uniq.size
+ end
- def test_gem_load_frozen
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_A_VERSION
- end
+ def test_gem_load_frozen
+ dummy_gem = Rails::GemDependency.new "dummy-gem-a"
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_A_VERSION
+ end
- def test_gem_load_frozen_specific_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_B_VERSION
- assert_equal '0.4.0', DUMMY_GEM_B_VERSION
- end
+ def test_gem_load_frozen_specific_version
+ dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_B_VERSION
+ assert_equal '0.4.0', DUMMY_GEM_B_VERSION
+ end
- def test_gem_load_frozen_minimum_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_C_VERSION
- assert_equal '0.6.0', DUMMY_GEM_C_VERSION
- end
+ def test_gem_load_frozen_minimum_version
+ dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_C_VERSION
+ assert_equal '0.6.0', DUMMY_GEM_C_VERSION
+ end
- def test_gem_load_missing_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-d"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_D_VERSION
- assert_equal '1.0.0', DUMMY_GEM_D_VERSION
- assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files
- end
+ def test_gem_load_missing_specification
+ dummy_gem = Rails::GemDependency.new "dummy-gem-d"
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_D_VERSION
+ assert_equal '1.0.0', DUMMY_GEM_D_VERSION
+ assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files
+ end
- def test_gem_load_bad_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_E_VERSION
- assert_equal '1.0.0', DUMMY_GEM_E_VERSION
- end
+ def test_gem_load_bad_specification
+ dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0"
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_E_VERSION
+ assert_equal '1.0.0', DUMMY_GEM_E_VERSION
+ end
- def test_gem_handle_missing_dependencies
- dummy_gem = Rails::GemDependency.new "dummy-gem-g"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert dummy_gem.loaded?
- assert_equal 2, dummy_gem.dependencies.size
- assert_nothing_raised do
- dummy_gem.dependencies.each do |g|
- g.dependencies
- end
+ def test_gem_handle_missing_dependencies
+ dummy_gem = Rails::GemDependency.new "dummy-gem-g"
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_equal 1, dummy_gem.dependencies.size
+ assert_equal 1, dummy_gem.dependencies.first.dependencies.size
+ assert_nothing_raised do
+ dummy_gem.dependencies.each do |g|
+ g.dependencies
end
end
-
end
+
end
diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb
index 926607f55c..70829a77fd 100644
--- a/railties/test/generators/rails_scaffold_generator_test.rb
+++ b/railties/test/generators/rails_scaffold_generator_test.rb
@@ -19,7 +19,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase
assert_generated_controller_for :products do |f|
assert_has_method f, :index do |name, m|
- assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
+ assert_match /@products = Product\.all/, m, "#{name} should query products table"
end
assert_has_method f, :show, :edit, :update, :destroy do |name, m|
@@ -71,7 +71,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase
assert_generated_controller_for :products do |f|
assert_has_method f, :index do |name, m|
- assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
+ assert_match /@products = Product\.all/, m, "#{name} should query products table"
end
assert_has_method f, :show, :edit, :update, :destroy do |name, m|
@@ -107,17 +107,15 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase
assert_added_route_for :products
end
- uses_mocha("scaffold_force_plural_names") do
- def test_scaffolded_plural_names
- Rails::Generator::Base.logger.expects(:warning)
- g = Rails::Generator::Base.instance('scaffold', %w(ProductLines))
- assert_equal "ProductLines", g.controller_name
- assert_equal "ProductLines", g.controller_class_name
- assert_equal "ProductLine", g.controller_singular_name
- assert_equal "product_lines", g.controller_plural_name
- assert_equal "product_lines", g.controller_file_name
- assert_equal "product_lines", g.controller_table_name
- end
+ def test_scaffolded_plural_names
+ Rails::Generator::Base.logger.expects(:warning)
+ g = Rails::Generator::Base.instance('scaffold', %w(ProductLines))
+ assert_equal "ProductLines", g.controller_name
+ assert_equal "ProductLines", g.controller_class_name
+ assert_equal "ProductLine", g.controller_singular_name
+ assert_equal "product_lines", g.controller_plural_name
+ assert_equal "product_lines", g.controller_file_name
+ assert_equal "product_lines", g.controller_table_name
end
def test_scaffold_plural_model_name_without_force_plural_generates_singular_model
diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb
index fcc020603d..2da6bd59b5 100644
--- a/railties/test/generators/rails_template_runner_test.rb
+++ b/railties/test/generators/rails_template_runner_test.rb
@@ -53,12 +53,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_plugin_with_git_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@git_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@git_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :git => @git_plugin_uri)
end
def test_plugin_with_svn_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@svn_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@svn_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :svn => @svn_plugin_uri)
end
@@ -82,6 +82,22 @@ class RailsTemplateRunnerTest < GeneratorTestCase
assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")
end
+ def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment
+ run_template_method(:gem, 'rspec', :env => 'test')
+ assert_generated_file_with_data('config/environments/test.rb', "config.gem 'rspec'", 'test')
+ end
+
+ def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments
+ run_template_method(:gem, 'quietbacktrace', :env => %w[ development test ])
+ assert_generated_file_with_data('config/environments/development.rb', "config.gem 'quietbacktrace'")
+ assert_generated_file_with_data('config/environments/test.rb', "config.gem 'quietbacktrace'")
+ end
+
+ def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly
+ run_template_method(:gem, 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com')
+ assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com'")
+ end
+
def test_environment_should_include_data_in_environment_initializer_block
load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]'
run_template_method(:environment, load_paths)
@@ -127,7 +143,7 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_generate_should_run_script_generate_with_argument_and_options
- expects_run_with_command('script/generate model MyModel')
+ expects_run_ruby_script_with_command('script/generate model MyModel')
run_template_method(:generate, 'model', 'MyModel')
end
@@ -162,6 +178,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
assert_generated_file_with_data 'config/routes.rb', route_command
end
+ def test_run_ruby_script_should_add_ruby_to_command_in_win32_environment
+ ruby_command = RUBY_PLATFORM =~ /win32/ ? 'ruby ' : ''
+ expects_run_with_command("#{ruby_command}script/generate model MyModel")
+ run_template_method(:generate, 'model', 'MyModel')
+ end
+
protected
def run_template_method(method_name, *args, &block)
silence_generator do
@@ -174,6 +196,10 @@ class RailsTemplateRunnerTest < GeneratorTestCase
Rails::TemplateRunner.any_instance.stubs(:run).once.with(command, false)
end
+ def expects_run_ruby_script_with_command(command)
+ Rails::TemplateRunner.any_instance.stubs(:run_ruby_script).once.with(command,false)
+ end
+
def assert_rails_initializer_includes(data, message = nil)
message ||= "Rails::Initializer should include #{data}"
assert_generated_file 'config/environment.rb' do |body|
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index dad9e55e61..d77a045e56 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -1,6 +1,10 @@
require 'abstract_unit'
require 'initializer'
+require 'action_view'
+require 'action_mailer'
+require 'active_record'
+
# Mocks out the configuration
module Rails
def self.configuration
@@ -26,7 +30,6 @@ class Initializer_load_environment_Test < Test::Unit::TestCase
ensure
$initialize_test_set_from_env = nil
end
-
end
class Initializer_eager_loading_Test < Test::Unit::TestCase
@@ -47,268 +50,335 @@ class Initializer_eager_loading_Test < Test::Unit::TestCase
end
end
-uses_mocha 'Initializer after_initialize' do
- class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase
- def setup
- config = ConfigurationMock.new("")
- config.after_initialize do
- $test_after_initialize_block1 = "success"
- end
- config.after_initialize do
- $test_after_initialize_block2 = "congratulations"
- end
- assert_nil $test_after_initialize_block1
- assert_nil $test_after_initialize_block2
-
- Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
- Rails::Initializer.run(:after_initialize, config)
+class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase
+ def setup
+ config = ConfigurationMock.new("")
+ config.after_initialize do
+ $test_after_initialize_block1 = "success"
end
-
- def teardown
- $test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
+ config.after_initialize do
+ $test_after_initialize_block2 = "congratulations"
end
+ assert_nil $test_after_initialize_block1
+ assert_nil $test_after_initialize_block2
- def test_should_have_called_the_first_after_initialize_block
- assert_equal "success", $test_after_initialize_block1
- end
+ Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
+ Rails::Initializer.run(:after_initialize, config)
+ end
- def test_should_have_called_the_second_after_initialize_block
- assert_equal "congratulations", $test_after_initialize_block2
- end
+ def teardown
+ $test_after_initialize_block1 = nil
+ $test_after_initialize_block2 = nil
end
- class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase
- def setup
- config = ConfigurationMock.new("")
- config.after_initialize do
- $test_after_initialize_block1 = "success"
- end
- config.after_initialize # don't pass a block, this is what we're testing!
- config.after_initialize do
- $test_after_initialize_block2 = "congratulations"
- end
- assert_nil $test_after_initialize_block1
+ def test_should_have_called_the_first_after_initialize_block
+ assert_equal "success", $test_after_initialize_block1
+ end
- Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
- Rails::Initializer.run(:after_initialize, config)
- end
+ def test_should_have_called_the_second_after_initialize_block
+ assert_equal "congratulations", $test_after_initialize_block2
+ end
+end
- def teardown
- $test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
+class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase
+ def setup
+ config = ConfigurationMock.new("")
+ config.after_initialize do
+ $test_after_initialize_block1 = "success"
end
-
- def test_should_have_called_the_first_after_initialize_block
- assert_equal "success", $test_after_initialize_block1, "should still get set"
+ config.after_initialize # don't pass a block, this is what we're testing!
+ config.after_initialize do
+ $test_after_initialize_block2 = "congratulations"
end
+ assert_nil $test_after_initialize_block1
- def test_should_have_called_the_second_after_initialize_block
- assert_equal "congratulations", $test_after_initialize_block2
- end
+ Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
+ Rails::Initializer.run(:after_initialize, config)
+ end
+
+ def teardown
+ $test_after_initialize_block1 = nil
+ $test_after_initialize_block2 = nil
+ end
+
+ def test_should_have_called_the_first_after_initialize_block
+ assert_equal "success", $test_after_initialize_block1, "should still get set"
+ end
+
+ def test_should_have_called_the_second_after_initialize_block
+ assert_equal "congratulations", $test_after_initialize_block2
end
end
-uses_mocha 'framework paths' do
- class ConfigurationFrameworkPathsTests < Test::Unit::TestCase
- def setup
- @config = Rails::Configuration.new
- @config.frameworks.clear
+class ConfigurationFrameworkPathsTests < Test::Unit::TestCase
+ def setup
+ @config = Rails::Configuration.new
+ @config.frameworks.clear
- File.stubs(:directory?).returns(true)
- @config.stubs(:framework_root_path).returns('')
- end
+ File.stubs(:directory?).returns(true)
+ @config.stubs(:framework_root_path).returns('')
+ end
- def test_minimal
- expected = %w(
- /railties
- /railties/lib
- /activesupport/lib
- )
- assert_equal expected, @config.framework_paths
- end
+ def test_minimal
+ expected = %w(
+ /railties
+ /railties/lib
+ /activesupport/lib
+ )
+ assert_equal expected, @config.framework_paths
+ end
- def test_actioncontroller_or_actionview_add_actionpack
- @config.frameworks << :action_controller
- assert_framework_path '/actionpack/lib'
+ def test_actioncontroller_or_actionview_add_actionpack
+ @config.frameworks << :action_controller
+ assert_framework_path '/actionpack/lib'
- @config.frameworks = [:action_view]
- assert_framework_path '/actionpack/lib'
- end
+ @config.frameworks = [:action_view]
+ assert_framework_path '/actionpack/lib'
+ end
- def test_paths_for_ar_ares_and_mailer
- [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
- @config.frameworks = [framework]
- assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib"
- end
+ def test_paths_for_ar_ares_and_mailer
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
+ @config.frameworks = [framework]
+ assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib"
end
+ end
- def test_unknown_framework_raises_error
- @config.frameworks << :action_foo
- initializer = Rails::Initializer.new @config
- initializer.expects(:require).raises(LoadError)
+ def test_unknown_framework_raises_error
+ @config.frameworks << :action_foo
+ initializer = Rails::Initializer.new @config
+ initializer.expects(:require).raises(LoadError)
- assert_raise RuntimeError do
- initializer.send :require_frameworks
- end
+ assert_raise RuntimeError do
+ initializer.send :require_frameworks
end
+ end
- def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
- @config.frameworks = [:action_controller]
- initializer = Rails::Initializer.new @config
- initializer.send :require_frameworks
+ def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
+ @config.frameworks = [:action_controller]
+ initializer = Rails::Initializer.new @config
+ initializer.send :require_frameworks
- assert_nothing_raised NameError do
- initializer.send :load_view_paths
- end
+ assert_nothing_raised NameError do
+ initializer.send :load_view_paths
end
+ end
- def test_action_controller_load_paths_set_only_if_action_controller_in_use
- @config.frameworks = []
- initializer = Rails::Initializer.new @config
- initializer.send :require_frameworks
+ def test_action_controller_load_paths_set_only_if_action_controller_in_use
+ @config.frameworks = []
+ initializer = Rails::Initializer.new @config
+ initializer.send :require_frameworks
- assert_nothing_raised NameError do
- initializer.send :load_view_paths
- end
+ assert_nothing_raised NameError do
+ initializer.send :load_view_paths
end
-
- protected
- def assert_framework_path(path)
- assert @config.framework_paths.include?(path),
- "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"
- end
end
+
+ protected
+ def assert_framework_path(path)
+ assert @config.framework_paths.include?(path),
+ "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"
+ end
end
-uses_mocha "Initializer plugin loading tests" do
- require File.dirname(__FILE__) + '/plugin_test_helper'
+require File.dirname(__FILE__) + '/plugin_test_helper'
- class InitializerPluginLoadingTests < Test::Unit::TestCase
- def setup
- @configuration = Rails::Configuration.new
- @configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.new(@configuration)
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
- end
+class InitializerPluginLoadingTests < Test::Unit::TestCase
+ def setup
+ @configuration = Rails::Configuration.new
+ @configuration.frameworks -= [:action_mailer]
+ @configuration.plugin_paths << plugin_fixture_root_path
+ @initializer = Rails::Initializer.new(@configuration)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
- def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
- only_load_the_following_plugins! []
- @initializer.load_plugins
- assert_equal [], @initializer.loaded_plugins
- end
+ def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
+ only_load_the_following_plugins! []
+ @initializer.load_plugins
+ assert_equal [], @initializer.loaded_plugins
+ end
- def test_only_the_specified_plugins_are_located_in_the_order_listed
- plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- assert_plugins plugin_names, @initializer.loaded_plugins
- end
+ def test_only_the_specified_plugins_are_located_in_the_order_listed
+ plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ assert_plugins plugin_names, @initializer.loaded_plugins
+ end
- def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- load_plugins!
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
- end
+ def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ load_plugins!
+ assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
+ end
- def test_all_plugins_loaded_when_all_is_used
- plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
- end
+ def test_all_plugins_loaded_when_all_is_used
+ plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
+ end
- def test_all_plugins_loaded_after_all
- plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip
- end
+ def test_all_plugins_loaded_after_all
+ plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip
+ end
+
+ def test_plugin_names_may_be_strings
+ plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip
+ end
- def test_plugin_names_may_be_strings
- plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- only_load_the_following_plugins! plugin_names
+ def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
+ only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
+ assert_raise(LoadError) do
load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip
end
+ end
- def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
- only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
- assert_raises(LoadError) do
- load_plugins!
+ def test_load_error_messages_mention_missing_plugins_and_no_others
+ valid_plugin_names = [:stubby, :acts_as_chunky_bacon]
+ invalid_plugin_names = [:non_existant_plugin1, :non_existant_plugin2]
+ only_load_the_following_plugins!( valid_plugin_names + invalid_plugin_names )
+ begin
+ load_plugins!
+ flunk "Expected a LoadError but did not get one"
+ rescue LoadError => e
+ failure_tip = "It's likely someone renamed or deleted plugin fixtures without updating this test"
+ assert_plugins valid_plugin_names, @initializer.loaded_plugins, failure_tip
+ invalid_plugin_names.each do |plugin|
+ assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
+ end
+ valid_plugin_names.each do |plugin|
+ assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'")
end
+
end
+ end
- def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
+ def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
- @initializer.add_plugin_load_paths
+ @initializer.add_plugin_load_paths
+
+ assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
+ end
- assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
- assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
+ private
+
+ def load_plugins!
+ @initializer.add_plugin_load_paths
+ @initializer.load_plugins
end
+end
+class InitializerSetupI18nTests < Test::Unit::TestCase
+ def test_no_config_locales_dir_present_should_return_empty_load_path
+ File.stubs(:exist?).returns(false)
+ assert_equal [], Rails::Configuration.new.i18n.load_path
+ end
- private
+ def test_config_locales_dir_present_should_be_added_to_load_path
+ File.stubs(:exist?).returns(true)
+ Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
+ assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path
+ end
- def load_plugins!
- @initializer.add_plugin_load_paths
- @initializer.load_plugins
- end
+ def test_config_defaults_should_be_added_with_config_settings
+ File.stubs(:exist?).returns(true)
+ Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
+
+ config = Rails::Configuration.new
+ config.i18n.load_path << "my/other/locale.yml"
+
+ assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path
+ end
+
+ def test_config_defaults_and_settings_should_be_added_to_i18n_defaults
+ File.stubs(:exist?).returns(true)
+ Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
+
+ config = Rails::Configuration.new
+ config.i18n.load_path << "my/other/locale.yml"
+
+ Rails::Initializer.run(:initialize_i18n, config)
+ assert_equal [
+ File.expand_path(File.dirname(__FILE__) + "/../../activesupport/lib/active_support/locale/en.yml"),
+ File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/locale/en.yml"),
+ File.expand_path(File.dirname(__FILE__) + "/../../activerecord/lib/active_record/locale/en.yml"),
+ "my/test/locale.yml",
+ "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path }
+ end
+
+ def test_setting_another_default_locale
+ config = Rails::Configuration.new
+ config.i18n.default_locale = :de
+ Rails::Initializer.run(:initialize_i18n, config)
+ assert_equal :de, I18n.default_locale
end
end
-uses_mocha 'i18n settings' do
- class InitializerSetupI18nTests < Test::Unit::TestCase
- def test_no_config_locales_dir_present_should_return_empty_load_path
- File.stubs(:exist?).returns(false)
- assert_equal [], Rails::Configuration.new.i18n.load_path
- end
+class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase
+ def setup
+ @config = Rails::Configuration.new
+ @config.frameworks = [:active_record, :action_controller, :action_view]
+ end
- def test_config_locales_dir_present_should_be_added_to_load_path
- File.stubs(:exist?).returns(true)
- Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
- assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path
- end
-
- def test_config_defaults_should_be_added_with_config_settings
- File.stubs(:exist?).returns(true)
- Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
+ def test_initialize_database_middleware_doesnt_perform_anything_when_active_record_not_in_frameworks
+ @config.frameworks.clear
+ @config.expects(:middleware).never
+ Rails::Initializer.run(:initialize_database_middleware, @config)
+ end
- config = Rails::Configuration.new
- config.i18n.load_path << "my/other/locale.yml"
+ def test_database_middleware_initializes_when_session_store_is_active_record
+ store = ActionController::Base.session_store
+ ActionController::Base.session_store = ActiveRecord::SessionStore
- assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path
- end
-
- def test_config_defaults_and_settings_should_be_added_to_i18n_defaults
- File.stubs(:exist?).returns(true)
- Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
-
- config = Rails::Configuration.new
- config.i18n.load_path << "my/other/locale.yml"
-
- # To bring in AV's i18n load path.
- require 'action_view'
-
- Rails::Initializer.run(:initialize_i18n, config)
- assert_equal [
- File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"),
- File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"),
- "my/test/locale.yml",
- "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path }
- end
+ @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement)
+ @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::QueryCache)
+
+ Rails::Initializer.run(:initialize_database_middleware, @config)
+ ensure
+ ActionController::Base.session_store = store
+ end
+
+ def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_record
+ store = ActionController::Base.session_store
+ ActionController::Base.session_store = ActionDispatch::Session::CookieStore
+
+ # Define the class, so we don't have to actually make it load
+ eval("class ActiveRecord::ConnectionAdapters::ConnectionManagement; end")
+
+ @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement)
+ @config.middleware.expects(:use).with(ActiveRecord::QueryCache)
+
+ Rails::Initializer.run(:initialize_database_middleware, @config)
+ ensure
+ ActionController::Base.session_store = store
+ end
+end
+
+class InitializerViewPathsTest < Test::Unit::TestCase
+ def setup
+ @config = Rails::Configuration.new
+ @config.frameworks = [:action_view, :action_controller, :action_mailer]
- def test_setting_another_default_locale
- config = Rails::Configuration.new
- config.i18n.default_locale = :de
- Rails::Initializer.run(:initialize_i18n, config)
- assert_equal :de, I18n.default_locale
- end
+ ActionController::Base.stubs(:view_paths).returns(stub)
+ ActionMailer::Base.stubs(:view_paths).returns(stub)
+ end
+
+ def test_load_view_paths_doesnt_perform_anything_when_action_view_not_in_frameworks
+ @config.frameworks -= [:action_view]
+ ActionController::Base.view_paths.expects(:load!).never
+ ActionMailer::Base.view_paths.expects(:load!).never
+ Rails::Initializer.run(:load_view_paths, @config)
end
end
diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb
new file mode 100644
index 0000000000..d3d231132b
--- /dev/null
+++ b/railties/test/metal_test.rb
@@ -0,0 +1,72 @@
+require 'abstract_unit'
+require 'initializer'
+
+class MetalTest < Test::Unit::TestCase
+ def test_metals_should_return_list_of_found_metal_apps
+ use_appdir("singlemetal") do
+ assert_equal(["FooMetal"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metals_should_respect_class_name_conventions
+ use_appdir("pluralmetal") do
+ assert_equal(["LegacyRoutes"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metals_should_return_alphabetical_list_of_found_metal_apps
+ use_appdir("multiplemetals") do
+ assert_equal(["MetalA", "MetalB"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metals_load_order_should_be_overriden_by_requested_metals
+ use_appdir("multiplemetals") do
+ Rails::Rack::Metal.requested_metals = ["MetalB", "MetalA"]
+ assert_equal(["MetalB", "MetalA"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metals_not_listed_should_not_load
+ use_appdir("multiplemetals") do
+ Rails::Rack::Metal.requested_metals = ["MetalB"]
+ assert_equal(["MetalB"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metal_finding_should_work_with_subfolders
+ use_appdir("subfolders") do
+ assert_equal(["Folder::MetalA", "Folder::MetalB"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metal_finding_with_requested_metals_should_work_with_subfolders
+ use_appdir("subfolders") do
+ Rails::Rack::Metal.requested_metals = ["Folder::MetalB"]
+ assert_equal(["Folder::MetalB"], found_metals_as_string_array)
+ end
+ end
+
+ def test_metal_finding_should_work_with_multiple_metal_paths_in_185_and_below
+ use_appdir("singlemetal") do
+ engine_metal_path = "#{File.dirname(__FILE__)}/fixtures/plugins/engines/engine/app/metal"
+ Rails::Rack::Metal.metal_paths << engine_metal_path
+ $LOAD_PATH << engine_metal_path
+ assert_equal(["FooMetal", "EngineMetal"], found_metals_as_string_array)
+ end
+ end
+
+ private
+
+ def use_appdir(root)
+ dir = "#{File.dirname(__FILE__)}/fixtures/metal/#{root}"
+ Rails::Rack::Metal.metal_paths = ["#{dir}/app/metal"]
+ Rails::Rack::Metal.requested_metals = nil
+ $LOAD_PATH << "#{dir}/app/metal"
+ yield
+ end
+
+ def found_metals_as_string_array
+ Rails::Rack::Metal.metals.map { |m| m.to_s }
+ end
+end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 23b81ddbf6..b270748dd6 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -1,7 +1,9 @@
require 'plugin_test_helper'
$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
+$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
require 'action_controller'
+require 'action_mailer'
# Mocks out the configuration
module Rails
@@ -118,21 +120,22 @@ class TestPluginLoader < Test::Unit::TestCase
@loader.add_plugin_load_paths
- %w( models controllers helpers ).each do |app_part|
+ %w( models controllers metal helpers ).each do |app_part|
assert ActiveSupport::Dependencies.load_paths.include?(
File.join(plugin_fixture_path('engines/engine'), 'app', app_part)
), "Couldn't find #{app_part} in load path"
end
end
- def test_engine_controllers_should_have_their_view_path_set_when_loaded
+ def test_engine_controllers_and_action_mailers_should_have_their_view_path_set_when_loaded
only_load_the_following_plugins!([ :engine ])
@loader.send :add_engine_view_paths
assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths
+ assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths
end
-
+
def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths
only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
@@ -158,4 +161,4 @@ class TestPluginLoader < Test::Unit::TestCase
$LOAD_PATH.clear
ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path }
end
-end \ No newline at end of file
+end
diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb
index 5a8c651e5a..471d9fc7c3 100644
--- a/railties/test/plugin_locator_test.rb
+++ b/railties/test/plugin_locator_test.rb
@@ -1,69 +1,62 @@
require 'plugin_test_helper'
-uses_mocha "Plugin Locator Tests" do
-
- class PluginLocatorTest < Test::Unit::TestCase
-
- def test_should_require_subclasses_to_implement_the_plugins_method
- assert_raises(RuntimeError) do
- Rails::Plugin::Locator.new(nil).plugins
- end
+class PluginLocatorTest < Test::Unit::TestCase
+ def test_should_require_subclasses_to_implement_the_plugins_method
+ assert_raise(RuntimeError) do
+ Rails::Plugin::Locator.new(nil).plugins
end
+ end
+
+ def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each
+ locator = Rails::Plugin::Locator.new(nil)
+ locator.stubs(:plugins).returns([:a, :b, :c])
+ plugin_consumer = mock
+ plugin_consumer.expects(:consume).with(:a)
+ plugin_consumer.expects(:consume).with(:b)
+ plugin_consumer.expects(:consume).with(:c)
- def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each
- locator = Rails::Plugin::Locator.new(nil)
- locator.stubs(:plugins).returns([:a, :b, :c])
- plugin_consumer = mock
- plugin_consumer.expects(:consume).with(:a)
- plugin_consumer.expects(:consume).with(:b)
- plugin_consumer.expects(:consume).with(:c)
-
- locator.each do |plugin|
- plugin_consumer.consume(plugin)
- end
+ locator.each do |plugin|
+ plugin_consumer.consume(plugin)
end
-
end
+end
+class PluginFileSystemLocatorTest < Test::Unit::TestCase
+ def setup
+ @configuration = Rails::Configuration.new
+ # We need to add our testing plugin directory to the plugin paths so
+ # the locator knows where to look for our plugins
+ @configuration.plugin_paths << plugin_fixture_root_path
+ @initializer = Rails::Initializer.new(@configuration)
+ @locator = Rails::Plugin::FileSystemLocator.new(@initializer)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
- class PluginFileSystemLocatorTest < Test::Unit::TestCase
- def setup
- @configuration = Rails::Configuration.new
- # We need to add our testing plugin directory to the plugin paths so
- # the locator knows where to look for our plugins
- @configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.new(@configuration)
- @locator = Rails::Plugin::FileSystemLocator.new(@initializer)
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
- end
+ def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory
+ assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
+ end
- def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory
- assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
- end
-
- def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
- assert_nil @locator.send(:create_plugin, @empty_plugin_path)
- end
-
- def test_should_return_all_plugins_found_under_the_set_plugin_paths
- assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
- end
-
- def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
- @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
- assert_equal ["acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
-
- @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
- assert_equal ["a"], @locator.plugins.map(&:name)
- end
+ def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
+ assert_nil @locator.send(:create_plugin, @empty_plugin_path)
+ end
+
+ def test_should_return_all_plugins_found_under_the_set_plugin_paths
+ assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
+ end
+
+ def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
+ @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
+ assert_equal ["acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
- def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist
- @configuration.plugin_paths = ["some_missing_directory"]
- assert_nothing_raised do
- assert @locator.plugins.empty?
- end
- end
+ @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
+ assert_equal ["a"], @locator.plugins.map(&:name)
end
-end # uses_mocha
+ def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist
+ @configuration.plugin_paths = ["some_missing_directory"]
+ assert_nothing_raised do
+ assert @locator.plugins.empty?
+ end
+ end
+end
diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb
index 50124240a5..a6c390a45a 100644
--- a/railties/test/plugin_test.rb
+++ b/railties/test/plugin_test.rb
@@ -1,167 +1,162 @@
require 'plugin_test_helper'
-uses_mocha "Plugin Tests" do
+class PluginTest < Test::Unit::TestCase
+ def setup
+ @initializer = Rails::Initializer.new(Rails::Configuration.new)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ @gemlike_plugin_path = plugin_fixture_path('default/gemlike')
+ end
- class PluginTest < Test::Unit::TestCase
+ def test_should_determine_plugin_name_from_the_directory_of_the_plugin
+ assert_equal 'stubby', plugin_for(@valid_plugin_path).name
+ assert_equal 'empty', plugin_for(@empty_plugin_path).name
+ end
- def setup
- @initializer = Rails::Initializer.new(Rails::Configuration.new)
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
- @gemlike_plugin_path = plugin_fixture_path('default/gemlike')
- end
+ def test_should_not_be_loaded_when_created
+ assert !plugin_for(@valid_plugin_path).loaded?
+ end
- def test_should_determine_plugin_name_from_the_directory_of_the_plugin
- assert_equal 'stubby', plugin_for(@valid_plugin_path).name
- assert_equal 'empty', plugin_for(@empty_plugin_path).name
+ def test_should_be_marked_as_loaded_when_load_is_called
+ plugin = plugin_for(@valid_plugin_path)
+ assert !plugin.loaded?
+ plugin.stubs(:evaluate_init_rb)
+ assert_nothing_raised do
+ plugin.send(:load, anything)
end
+ assert plugin.loaded?
+ end
- def test_should_not_be_loaded_when_created
- assert !plugin_for(@valid_plugin_path).loaded?
- end
+ def test_should_determine_validity_of_given_path
+ # This is a plugin path, with a lib dir
+ assert plugin_for(@valid_plugin_path).valid?
+ # This just has an init.rb and no lib dir
+ assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid?
+ # This would be a plugin path, but the directory is empty
+ assert !plugin_for(plugin_fixture_path('default/empty')).valid?
+ # This is a non sense path
+ assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid?
+ end
- def test_should_be_marked_as_loaded_when_load_is_called
- plugin = plugin_for(@valid_plugin_path)
- assert !plugin.loaded?
- plugin.stubs(:evaluate_init_rb)
- assert_nothing_raised do
- plugin.send(:load, anything)
- end
- assert plugin.loaded?
- end
-
- def test_should_determine_validity_of_given_path
- # This is a plugin path, with a lib dir
- assert plugin_for(@valid_plugin_path).valid?
- # This just has an init.rb and no lib dir
- assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid?
- # This would be a plugin path, but the directory is empty
- assert !plugin_for(plugin_fixture_path('default/empty')).valid?
- # This is a non sense path
- assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid?
+ def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory
+ assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths
+ end
+
+ def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory
+ expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib')
+ assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin
+ assert_nothing_raised do
+ plugin_for(@valid_plugin_path).load_paths
end
- def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory
- assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths
+ assert_raise(LoadError) do
+ plugin_for(@empty_plugin_path).load_paths
end
- def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory
- expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib')
- assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths
+ assert_raise(LoadError) do
+ plugin_for('this_is_not_a_plugin_directory').load_paths
end
-
- def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin
- assert_nothing_raised do
- plugin_for(@valid_plugin_path).load_paths
- end
-
- assert_raises(LoadError) do
- plugin_for(@empty_plugin_path).load_paths
- end
-
- assert_raises(LoadError) do
- plugin_for('this_is_not_a_plugin_directory').load_paths
- end
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ plugin = plugin_for(@valid_plugin_path)
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
end
-
- def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin
- # This path is fine so nothing is raised
- assert_nothing_raised do
- plugin = plugin_for(@valid_plugin_path)
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
- # This path is fine so nothing is raised
- assert_nothing_raised do
- plugin = plugin_for(@gemlike_plugin_path)
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ plugin = plugin_for(@gemlike_plugin_path)
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
+ end
- # This is an empty path so it raises
- assert_raises(LoadError) do
- plugin = plugin_for(@empty_plugin_path)
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
-
- assert_raises(LoadError) do
- plugin = plugin_for('this_is_not_a_plugin_directory')
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
+ # This is an empty path so it raises
+ assert_raise(LoadError) do
+ plugin = plugin_for(@empty_plugin_path)
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
end
-
- def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin
- # This path is fine so nothing is raised
- assert_nothing_raised do
- plugin_for(@valid_plugin_path).load_paths
- end
-
- # This is an empty path so it raises
- assert_raises(LoadError) do
- plugin_for(@empty_plugin_path).load_paths
- end
-
- assert_raises(LoadError) do
- plugin_for('this_is_not_a_plugin_directory').load_paths
- end
- end
- def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs
- failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already."
- assert !defined?(StubbyMixin), failure_tip
- plugin = plugin_for(@valid_plugin_path)
- plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) }
- # The init.rb of this plugin raises if it doesn't have access to all the things it needs
- assert_nothing_raised do
- plugin.load(@initializer)
- end
- assert defined?(StubbyMixin)
+ assert_raise(LoadError) do
+ plugin = plugin_for('this_is_not_a_plugin_directory')
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
end
-
- def test_should_sort_naturally_by_name
- a = plugin_for("path/a")
- b = plugin_for("path/b")
- z = plugin_for("path/z")
- assert_equal [a, b, z], [b, z, a].sort
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ plugin_for(@valid_plugin_path).load_paths
end
-
- def test_should_only_be_loaded_once
- plugin = plugin_for(@valid_plugin_path)
- assert !plugin.loaded?
- plugin.expects(:evaluate_init_rb)
- assert_nothing_raised do
- plugin.send(:load, @initializer)
- plugin.send(:load, @initializer)
- end
- assert plugin.loaded?
+
+ # This is an empty path so it raises
+ assert_raise(LoadError) do
+ plugin_for(@empty_plugin_path).load_paths
end
-
- def test_should_make_about_yml_available_as_about_method_on_plugin
- plugin = plugin_for(@valid_plugin_path)
- assert_equal "Plugin Author", plugin.about['author']
- assert_equal "1.0.0", plugin.about['version']
+
+ assert_raise(LoadError) do
+ plugin_for('this_is_not_a_plugin_directory').load_paths
end
-
- def test_should_return_empty_hash_for_about_if_about_yml_is_missing
- assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about)
+ end
+
+ def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs
+ failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already."
+ assert !defined?(StubbyMixin), failure_tip
+ plugin = plugin_for(@valid_plugin_path)
+ plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) }
+ # The init.rb of this plugin raises if it doesn't have access to all the things it needs
+ assert_nothing_raised do
+ plugin.load(@initializer)
end
-
- def test_should_return_empty_hash_for_about_if_about_yml_is_malformed
- assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about)
+ assert defined?(StubbyMixin)
+ end
+
+ def test_should_sort_naturally_by_name
+ a = plugin_for("path/a")
+ b = plugin_for("path/b")
+ z = plugin_for("path/z")
+ assert_equal [a, b, z], [b, z, a].sort
+ end
+
+ def test_should_only_be_loaded_once
+ plugin = plugin_for(@valid_plugin_path)
+ assert !plugin.loaded?
+ plugin.expects(:evaluate_init_rb)
+ assert_nothing_raised do
+ plugin.send(:load, @initializer)
+ plugin.send(:load, @initializer)
end
+ assert plugin.loaded?
+ end
- private
+ def test_should_make_about_yml_available_as_about_method_on_plugin
+ plugin = plugin_for(@valid_plugin_path)
+ assert_equal "Plugin Author", plugin.about['author']
+ assert_equal "1.0.0", plugin.about['version']
+ end
- def about_yml_plugin_path(name)
- File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name)
- end
+ def test_should_return_empty_hash_for_about_if_about_yml_is_missing
+ assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about)
+ end
- def plugin_for(path)
- Rails::Plugin.new(path)
- end
+ def test_should_return_empty_hash_for_about_if_about_yml_is_malformed
+ assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about)
end
-end # uses_mocha
+ private
+
+ def about_yml_plugin_path(name)
+ File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name)
+ end
+
+ def plugin_for(path)
+ Rails::Plugin.new(path)
+ end
+end
diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb
new file mode 100644
index 0000000000..ad673f6f19
--- /dev/null
+++ b/railties/test/rack_static_test.rb
@@ -0,0 +1,46 @@
+require 'abstract_unit'
+
+require 'action_controller'
+require 'rails/rack'
+
+class RackStaticTest < ActiveSupport::TestCase
+ def setup
+ FileUtils.cp_r "#{RAILS_ROOT}/fixtures/public", "#{RAILS_ROOT}/public"
+ end
+
+ def teardown
+ FileUtils.rm_rf "#{RAILS_ROOT}/public"
+ end
+
+ DummyApp = lambda { |env|
+ [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
+ }
+ App = Rails::Rack::Static.new(DummyApp)
+
+ test "serves dynamic content" do
+ assert_equal "Hello, World!", get("/nofile")
+ end
+
+ test "serves static index at root" do
+ assert_equal "/index.html", get("/index.html")
+ assert_equal "/index.html", get("/index")
+ assert_equal "/index.html", get("/")
+ end
+
+ test "serves static file in directory" do
+ assert_equal "/foo/bar.html", get("/foo/bar.html")
+ assert_equal "/foo/bar.html", get("/foo/bar/")
+ assert_equal "/foo/bar.html", get("/foo/bar")
+ end
+
+ test "serves static index file in directory" do
+ assert_equal "/foo/index.html", get("/foo/index.html")
+ assert_equal "/foo/index.html", get("/foo/")
+ assert_equal "/foo/index.html", get("/foo")
+ end
+
+ private
+ def get(path)
+ Rack::MockRequest.new(App).request("GET", path).body
+ end
+end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index b63cd00ba5..ab31f3a487 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -2,51 +2,45 @@ require 'abstract_unit'
require 'action_controller'
require 'action_controller/testing/process'
-module Rails; end
require 'rails/info'
require 'rails/info_controller'
-class Rails::InfoController < ActionController::Base
- @local_request = false
- class << self
- cattr_accessor :local_request
- end
-
- # Re-raise errors caught by the controller.
- def rescue_action(e) raise e end;
-
-protected
- def local_request?
- self.class.local_request
- end
-end
-
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
-class Rails::InfoControllerTest < ActionController::TestCase
+class InfoControllerTest < ActionController::TestCase
+ tests Rails::InfoController
+
def setup
- @controller = Rails::InfoController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
+ @controller.stubs(:consider_all_requests_local => false, :local_request? => true)
+ end
+
+ test "info controller does not allow remote requests" do
+ @controller.stubs(:consider_all_requests_local => false, :local_request? => false)
+ get :properties
+ assert_response :forbidden
+ end
- ActionController::Base.consider_all_requests_local = true
+ test "info controller renders an error message when request was forbidden" do
+ @controller.stubs(:consider_all_requests_local => false, :local_request? => false)
+ get :properties
+ assert_select 'p'
+ end
+
+ test "info controller allows requests when all requests are considered local" do
+ @controller.stubs(:consider_all_requests_local => true, :local_request? => false)
+ get :properties
+ assert_response :success
end
- def test_rails_info_properties_table_rendered_for_local_request
- Rails::InfoController.local_request = true
+ test "info controller allows local requests" do
get :properties
- assert_tag :tag => 'table'
assert_response :success
end
-
- def test_rails_info_properties_error_rendered_for_non_local_request
- Rails::InfoController.local_request = false
- ActionController::Base.consider_all_requests_local = false
+ test "info controller renders a table with properties" do
get :properties
- assert_tag :tag => 'p'
- assert_response 500
+ assert_select 'table'
end
end
diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb
index 9befd44a58..971cba89d0 100644
--- a/railties/test/rails_info_test.rb
+++ b/railties/test/rails_info_test.rb
@@ -1,9 +1,12 @@
$:.unshift File.dirname(__FILE__) + "/../lib"
$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info"
$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
+$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
require 'test/unit'
require 'active_support'
+require 'active_support/test_case'
+require 'action_controller'
unless defined?(Rails) && defined?(Rails::Info)
module Rails
@@ -11,7 +14,7 @@ unless defined?(Rails) && defined?(Rails::Info)
end
end
-class InfoTest < Test::Unit::TestCase
+class InfoTest < ActiveSupport::TestCase
def setup
Rails.send :remove_const, :Info
silence_warnings { load 'rails/info.rb' }
@@ -72,6 +75,18 @@ EOS
end
end
+ def test_middleware_property
+ assert property_defined?('Middleware')
+ end
+
+ def test_html_includes_middleware
+ html = Rails::Info.to_html
+ assert html.include?('<tr><td class="name">Middleware</td>')
+ properties.value_for('Middleware').each do |value|
+ assert html.include?("<li>#{CGI.escapeHTML(value)}</li>")
+ end
+ end
+
protected
def svn_info=(info)
Rails::Info.module_eval do
diff --git a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification
index 5483048c1c..27e29912a6 100644
--- a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification
+++ b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification
@@ -9,7 +9,7 @@ date: 2008-10-03 00:00:00 -04:00
dependencies:
- !ruby/object:Gem::Dependency
name: dummy-gem-f
- type: :development
+ type: :runtime
version_requirement:
version_requirements: !ruby/object:Gem::Requirement
requirements: