aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG7
-rw-r--r--railties/Rakefile22
-rw-r--r--railties/guides/source/2_3_release_notes.textile2
-rw-r--r--railties/guides/source/testing.textile2
-rw-r--r--railties/lib/commands/plugin.rb4
-rw-r--r--railties/lib/console_app.rb1
-rw-r--r--railties/lib/initializer.rb24
-rw-r--r--railties/lib/rails/backtrace_cleaner.rb23
-rw-r--r--railties/lib/rails/gem_dependency.rb11
-rw-r--r--railties/lib/rails/plugin.rb8
-rw-r--r--railties/lib/rails/plugin/loader.rb7
-rw-r--r--railties/lib/rails/rack/metal.rb27
-rw-r--r--railties/lib/rails/version.rb2
-rw-r--r--railties/lib/rails_generator/commands.rb8
-rw-r--r--railties/lib/rails_generator/generators/applications/app/template_runner.rb30
-rw-r--r--railties/lib/tasks/gems.rake7
-rw-r--r--railties/lib/tasks/testing.rake2
-rw-r--r--railties/test/abstract_unit.rb2
-rw-r--r--railties/test/backtrace_cleaner_test.rb65
-rw-r--r--railties/test/console_app_test.rb42
-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/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/gem_dependency_test.rb2
-rw-r--r--railties/test/generators/rails_template_runner_test.rb11
-rw-r--r--railties/test/initializer_test.rb83
-rw-r--r--railties/test/metal_test.rb66
-rw-r--r--railties/test/plugin_loader_test.rb4
-rw-r--r--railties/test/plugin_locator_test.rb2
-rw-r--r--railties/test/plugin_test.rb12
34 files changed, 416 insertions, 101 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 38c6f808e6..de506dfbbb 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,12 @@
+*2.3.1 [RC2] (March 5, 2009)*
+
+* Allow metal to live in plugins #2045 [Matthew Rudy]
+
+
*2.3.0 [RC1] (February 1st, 2009)*
+* Added metal [Josh Peek]
+
* Remove script/performance/request in favour of the performance integration tests. [Pratik Naik]
To continue using script/performance/request, install the request_profiler plugin :
diff --git a/railties/Rakefile b/railties/Rakefile
index 05f767dc3b..4b524f1c6f 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -28,7 +28,8 @@ task :default => :test
## we can see the failures
task :test do
Dir['test/**/*_test.rb'].all? do |file|
- system("ruby -Itest #{file}")
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ system(ruby, '-Itest', file)
end or raise "Failures"
end
@@ -310,11 +311,11 @@ spec = Gem::Specification.new do |s|
EOF
s.add_dependency('rake', '>= 0.8.3')
- s.add_dependency('activesupport', '= 2.3.0' + PKG_BUILD)
- s.add_dependency('activerecord', '= 2.3.0' + PKG_BUILD)
- s.add_dependency('actionpack', '= 2.3.0' + PKG_BUILD)
- s.add_dependency('actionmailer', '= 2.3.0' + PKG_BUILD)
- s.add_dependency('activeresource', '= 2.3.0' + PKG_BUILD)
+ s.add_dependency('activesupport', '= 2.3.1' + PKG_BUILD)
+ s.add_dependency('activerecord', '= 2.3.1' + PKG_BUILD)
+ s.add_dependency('actionpack', '= 2.3.1' + PKG_BUILD)
+ s.add_dependency('actionmailer', '= 2.3.1' + PKG_BUILD)
+ s.add_dependency('activeresource', '= 2.3.1' + PKG_BUILD)
s.rdoc_options << '--exclude' << '.'
s.has_rdoc = false
@@ -343,9 +344,12 @@ task :pgem => [:gem] do
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
end
-desc "Publish the API documentation"
-task :pdoc => :rdoc do
- # railties API isn't separately published
+desc "Publish the guides"
+task :pguides => :guides do
+ mkdir_p 'pkg'
+ `tar -czf pkg/guides.gz guides/output`
+ Rake::SshFilePublisher.new("web.rubyonrails.org", "/u/sites/guides.rubyonrails.org/public", "pkg", "guides.gz").upload
+ `ssh web.rubyonrails.org 'cd /u/sites/guides.rubyonrails.org/public/ && tar -xvzf guides.gz && mv guides/output/* . && rm -rf guides*'`
end
desc "Publish the release files to RubyForge."
diff --git a/railties/guides/source/2_3_release_notes.textile b/railties/guides/source/2_3_release_notes.textile
index de1d75eba9..549b6abf86 100644
--- a/railties/guides/source/2_3_release_notes.textile
+++ b/railties/guides/source/2_3_release_notes.textile
@@ -1,5 +1,7 @@
h2. Ruby on Rails 2.3 Release Notes
+NOTE: These release notes refer to RC2 of Rails 2.3. This is a release candidate, and not the final version of Rails 2.3. It's intended to be a stable testing release, and we urge you to test your own applications and report any issues to the "Rails Lighthouse":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview.
+
Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the "list of commits":http://github.com/rails/rails/commits/master in the main Rails repository on GitHub or review the +CHANGELOG+ files for the individual Rails components.
endprologue.
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index 9b764806a8..9897fbab6f 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -396,7 +396,7 @@ There are a bunch of different types of assertions you can use. Here's the compl
|+assert_no_match( regexp, string, [msg] )+ |Ensures that a string doesn't matches the regular expression.|
|+assert_in_delta( expecting, actual, delta, [msg] )+ |Ensures that the numbers +expecting+ and +actual+ are within +delta+ of each other.|
|+assert_throws( symbol, [msg] ) { block }+ |Ensures that the given block throws the symbol.|
-|+assert_raises( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.|
+|+assert_raise( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.|
|+assert_nothing_raised( exception1, exception2, ... ) { block }+ |Ensures that the given block doesn't raise one of the given exceptions.|
|+assert_instance_of( class, obj, [msg] )+ |Ensures that +obj+ is of the +class+ type.|
|+assert_kind_of( class, obj, [msg] )+ |Ensures that +obj+ is or descends from +class+.|
diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb
index 9ff4739562..a67c2ab447 100644
--- a/railties/lib/commands/plugin.rb
+++ b/railties/lib/commands/plugin.rb
@@ -278,8 +278,8 @@ class Plugin
base_cmd += " #{options[:revision]}" if options[:revision]
puts base_cmd if $verbose
if system(base_cmd)
- puts "removing: .git" if $verbose
- rm_rf ".git"
+ puts "removing: .git .gitignore" if $verbose
+ rm_rf %w(.git .gitignore)
else
rm_rf install_path
end
diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb
index d7cd57564f..d7d01d703f 100644
--- a/railties/lib/console_app.rb
+++ b/railties/lib/console_app.rb
@@ -24,6 +24,7 @@ end
#reloads the environment
def reload!
puts "Reloading..."
+ Dispatcher.cleanup_application
Dispatcher.reload_application
true
end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index a31ae9422e..edea4e513a 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -176,6 +176,9 @@ module Rails
# the framework is now fully initialized
after_initialize
+ # Setup database middleware after initializers have run
+ initialize_database_middleware
+
# Prepare dispatcher callbacks and run 'prepare' callbacks
prepare_dispatcher
@@ -410,7 +413,18 @@ Run `rake gems:install` to install the missing gems.
if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.configurations = configuration.database_configuration
ActiveRecord::Base.establish_connection
- configuration.middleware.use ActiveRecord::QueryCache
+ end
+ end
+
+ def initialize_database_middleware
+ if configuration.frameworks.include?(:active_record)
+ if ActionController::Base.session_store == ActiveRecord::SessionStore
+ configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
+ configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
+ else
+ configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
+ configuration.middleware.use ActiveRecord::QueryCache
+ end
end
end
@@ -545,6 +559,9 @@ Run `rake gems:install` to install the missing gems.
end
def initialize_metal
+ Rails::Rack::Metal.requested_metals = configuration.metals
+ Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
+
configuration.middleware.insert_before(
:"ActionController::RewindableInput",
Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
@@ -699,6 +716,11 @@ Run `rake gems:install` to install the missing gems.
@plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
end
+ # The list of metals to load. If this is set to <tt>nil</tt>, all metals will
+ # be loaded in alphabetical order. If this is set to <tt>[]</tt>, no metals will
+ # be loaded. Otherwise metals will be loaded in the order specified
+ attr_accessor :metals
+
# The path to the root of the plugins directory. By default, it is in
# <tt>vendor/plugins</tt>.
attr_accessor :plugin_paths
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb
index e1b422716d..923ed8b31d 100644
--- a/railties/lib/rails/backtrace_cleaner.rb
+++ b/railties/lib/rails/backtrace_cleaner.rb
@@ -2,15 +2,15 @@ module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
ERB_METHOD_SIG = /:in `_run_erb_.*/
- VENDOR_DIRS = %w( vendor/gems vendor/rails )
+ RAILS_GEMS = %w( actionpack activerecord actionmailer activesupport activeresource rails )
+
+ VENDOR_DIRS = %w( vendor/rails )
SERVER_DIRS = %w( lib/mongrel bin/mongrel
lib/passenger bin/passenger-spawn-server
lib/rack )
RAILS_NOISE = %w( script/server )
RUBY_NOISE = %w( rubygems/custom_require benchmark.rb )
- GEMS_DIR = Gem.default_dir
-
ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE
def initialize
@@ -18,10 +18,25 @@ module Rails
add_filter { |line| line.sub("#{RAILS_ROOT}/", '') }
add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
add_filter { |line| line.sub('./', '/') } # for tests
- add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430
+
+ add_gem_filters
+
add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } }
+ add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
end
+
+
+ private
+ def add_gem_filters
+ Gem.path.each do |path|
+ # http://gist.github.com/30430
+ add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
+ end
+
+ vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'')
+ add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')}
+ end
end
# For installing the BacktraceCleaner in the test/unit
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
index 5a07841be8..2dd659032f 100644
--- a/railties/lib/rails/gem_dependency.rb
+++ b/railties/lib/rails/gem_dependency.rb
@@ -72,13 +72,14 @@ module Rails
rescue Gem::LoadError
end
- def dependencies
- return [] if framework_gem?
- return [] if specification.nil?
+ def dependencies(options = {})
+ return [] if framework_gem? || specification.nil?
+
all_dependencies = specification.dependencies.map do |dependency|
GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
end
- all_dependencies += all_dependencies.map(&:dependencies).flatten
+
+ all_dependencies += all_dependencies.map { |d| d.dependencies(options) }.flatten if options[:flatten]
all_dependencies.uniq
end
@@ -149,6 +150,8 @@ module Rails
end
def unpack_to(directory)
+ return if specification.nil? || File.directory?(gem_dir(directory)) || framework_gem?
+
FileUtils.mkdir_p directory
Dir.chdir directory do
Gem::GemRunner.new.run(unpack_command)
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 4901abe808..80deb73bbb 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -80,6 +80,10 @@ module Rails
File.join(directory, 'app', 'controllers')
end
+ def metal_path
+ File.join(directory, 'app', 'metal')
+ end
+
def routing_file
File.join(directory, 'config', 'routes.rb')
end
@@ -100,7 +104,7 @@ module Rails
def app_paths
- [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ]
+ [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ]
end
def lib_path
@@ -160,4 +164,4 @@ module Rails
File.join(directory, 'rails', 'init.rb')
end
end
-end \ No newline at end of file
+end
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
index 7f85bb8966..66e01d70da 100644
--- a/railties/lib/rails/plugin/loader.rb
+++ b/railties/lib/rails/plugin/loader.rb
@@ -65,6 +65,9 @@ module Rails
$LOAD_PATH.uniq!
end
+ def engine_metal_paths
+ engines.collect(&:metal_path)
+ end
protected
def configure_engines
@@ -178,11 +181,11 @@ module Rails
if explicit_plugin_loading_order?
if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all])
- raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
+ raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence(:locale => :en)}"
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb
index b185227234..78b8a01449 100644
--- a/railties/lib/rails/rack/metal.rb
+++ b/railties/lib/rails/rack/metal.rb
@@ -6,15 +6,30 @@ module Rails
NotFoundResponse = [404, {}, []].freeze
NotFound = lambda { NotFoundResponse }
+ cattr_accessor :metal_paths
+ self.metal_paths = ["#{Rails.root}/app/metal"]
+ cattr_accessor :requested_metals
+
def self.metals
- base = "#{Rails.root}/app/metal"
- matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/
+ matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/
+ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" }
+ all_metals = {}
- Dir["#{base}/**/*.rb"].sort.map do |file|
- file.sub!(matcher, '\1')
- require file
- file.classify.constantize
+ metal_glob.each do |glob|
+ Dir[glob].sort.map do |file|
+ file = file.match(matcher)[1]
+ all_metals[file.classify] = file
+ end
end
+
+ load_list = requested_metals || all_metals.keys
+
+ load_list.map do |requested_metal|
+ if metal = all_metals[requested_metal]
+ require metal
+ requested_metal.constantize
+ end
+ end.compact
end
def initialize(app)
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index 9bb4b2a96d..fd38705e75 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -2,7 +2,7 @@ module Rails
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
- TINY = 0
+ TINY = 1
STRING = [MAJOR, MINOR, TINY].join('.')
end
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb
index 299044c3d7..b684dc92be 100644
--- a/railties/lib/rails_generator/commands.rb
+++ b/railties/lib/rails_generator/commands.rb
@@ -182,15 +182,19 @@ HELP
nesting = class_name.split('::')
name = nesting.pop
+ # Hack to limit const_defined? to non-inherited on 1.9.
+ extra = []
+ extra << false unless Object.method(:const_defined?).arity == 1
+
# Extract the last Module in the nesting.
last = nesting.inject(Object) { |last, nest|
- break unless last.const_defined?(nest)
+ break unless last.const_defined?(nest, *extra)
last.const_get(nest)
}
# If the last Module exists, check whether the given
# class exists and raise a collision if so.
- if last and last.const_defined?(name.camelize)
+ if last and last.const_defined?(name.camelize, *extra)
raise_class_collision(class_name)
end
end
diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
index eeb6b17661..73ab57d4f0 100644
--- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb
+++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
@@ -85,6 +85,7 @@ module Rails
# Adds an entry into config/environment.rb for the supplied gem :
def gem(name, options = {})
log 'gem', name
+ env = options.delete(:env)
gems_code = "config.gem '#{name}'"
@@ -93,18 +94,26 @@ module Rails
gems_code << ", #{opts}"
end
- environment gems_code
+ environment gems_code, :env => env
end
# Adds a line inside the Initializer block for config/environment.rb. Used by #gem
- def environment(data = nil, &block)
+ # If options :env is specified, the line is appended to the corresponding
+ # file in config/environments/#{env}.rb
+ def environment(data = nil, options = {}, &block)
sentinel = 'Rails::Initializer.run do |config|'
data = block.call if !data && block_given?
in_root do
- gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
- "#{match}\n " << data
+ if options[:env].nil?
+ gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
+ "#{match}\n " << data
+ end
+ else
+ Array.wrap(options[:env]).each do|env|
+ append_file "config/environments/#{env}.rb", "\n#{data}"
+ end
end
end
end
@@ -307,7 +316,7 @@ module Rails
#
def ask(string)
log '', string
- gets.strip
+ STDIN.gets.strip
end
# Do something in the root of the Rails application or
@@ -356,6 +365,17 @@ module Rails
File.open(path, 'wb') { |file| file.write(content) }
end
+ # Append text to a file
+ #
+ # ==== Example
+ #
+ # append_file 'config/environments/test.rb', 'config.gem "rspec"'
+ #
+ def append_file(relative_destination, data)
+ path = destination_path(relative_destination)
+ File.open(path, 'ab') { |file| file.write(data) }
+ end
+
def destination_path(relative_destination)
File.join(root, relative_destination)
end
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index d538e52ca6..0932ba73b5 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -47,8 +47,8 @@ namespace :gems do
require 'rubygems'
require 'rubygems/gem_runner'
Rails.configuration.gems.each do |gem|
- next unless !gem.frozen? && (ENV['GEM'].blank? || ENV['GEM'] == gem.name)
- gem.unpack_to(Rails::GemDependency.unpacked_path) if gem.loaded?
+ next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name
+ gem.unpack_to(Rails::GemDependency.unpacked_path)
end
end
@@ -59,8 +59,7 @@ namespace :gems do
require 'rubygems/gem_runner'
Rails.configuration.gems.each do |gem|
next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name
- gem.dependencies.each do |dependency|
- next if dependency.frozen?
+ gem.dependencies(:flatten => true).each do |dependency|
dependency.unpack_to(Rails::GemDependency.unpacked_path)
end
end
diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake
index 4242458672..fd5e52a05b 100644
--- a/railties/lib/tasks/testing.rake
+++ b/railties/lib/tasks/testing.rake
@@ -48,7 +48,7 @@ task :test do
task
end
end.compact
- abort "Errors running #{errors.to_sentence}!" if errors.any?
+ abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?
end
namespace :test do
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index a950fc8b7e..0addcb8bf3 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -1,5 +1,7 @@
$:.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"
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/console_app_test.rb b/railties/test/console_app_test.rb
index 7a5de5af8f..f11de087e3 100644
--- a/railties/test/console_app_test.rb
+++ b/railties/test/console_app_test.rb
@@ -11,30 +11,32 @@ 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
- def test_reload_should_fire_preparation_callbacks
- a = b = c = nil
+ def test_reload_should_fire_preparation_callbacks
+ a = b = c = nil
- Dispatcher.to_prepare { a = b = c = 1 }
- Dispatcher.to_prepare { b = c = 2 }
- Dispatcher.to_prepare { c = 3 }
- ActionController::Routing::Routes.expects(:reload)
+ Dispatcher.to_prepare { a = b = c = 1 }
+ Dispatcher.to_prepare { b = c = 2 }
+ Dispatcher.to_prepare { c = 3 }
+ ActionController::Routing::Routes.expects(:reload)
- reload!
+ reload!
- assert_equal 1, a
- assert_equal 2, b
- assert_equal 3, c
+ assert_equal 1, a
+ assert_equal 2, b
+ assert_equal 3, c
+ end
end
end
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..b8e7001351
--- /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..adc2f45fcf
--- /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/singlemetal/app/metal/foo_metal.rb b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
new file mode 100644
index 0000000000..9ade2ce8e7
--- /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..71a5a62eb8
--- /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..430d7bfed6
--- /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/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
index 9cb02fcd06..8b761c48b2 100644
--- a/railties/test/gem_dependency_test.rb
+++ b/railties/test/gem_dependency_test.rb
@@ -133,7 +133,7 @@ class GemDependencyTest < Test::Unit::TestCase
dummy_gem.add_load_paths
dummy_gem.load
assert dummy_gem.loaded?
- assert_equal 2, dummy_gem.dependencies.size
+ assert_equal 2, dummy_gem.dependencies(:flatten => true).size
assert_nothing_raised do
dummy_gem.dependencies.each do |g|
g.dependencies
diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb
index 56afc85eba..4e1937e0c6 100644
--- a/railties/test/generators/rails_template_runner_test.rb
+++ b/railties/test/generators/rails_template_runner_test.rb
@@ -82,6 +82,17 @@ 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_environment_should_include_data_in_environment_initializer_block
load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]'
run_template_method(:environment, load_paths)
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index eb9ec750da..561f7b8b54 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
@@ -234,7 +237,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
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
+ assert_raise(LoadError) do
load_plugins!
end
end
@@ -268,7 +271,6 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
end
-
private
def load_plugins!
@@ -288,7 +290,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
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" ])
@@ -298,7 +300,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
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" ])
@@ -306,17 +308,15 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
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(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
@@ -325,6 +325,69 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
end
end
+class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase
+ def setup
+ @config = Rails::Configuration.new
+ @config.frameworks = [:active_record, :action_controller, :action_view]
+ end
+
+ 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
+
+ def test_database_middleware_initializes_when_session_store_is_active_record
+ store = ActionController::Base.session_store
+ ActionController::Base.session_store = ActiveRecord::SessionStore
+
+ @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 = ActionController::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]
+
+ 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
+
+ def test_load_view_paths_loads_view_paths
+ ActionController::Base.view_paths.expects(:load!)
+ ActionMailer::Base.view_paths.expects(:load!)
+ Rails::Initializer.run(:load_view_paths, @config)
+ end
+end
+
class RailsRootTest < Test::Unit::TestCase
def test_rails_dot_root_equals_rails_root
assert_equal RAILS_ROOT, Rails.root.to_s
@@ -333,4 +396,4 @@ class RailsRootTest < Test::Unit::TestCase
def test_rails_dot_root_should_be_a_pathname
assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s
end
-end
+end \ No newline at end of file
diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb
new file mode 100644
index 0000000000..143efdda11
--- /dev/null
+++ b/railties/test/metal_test.rb
@@ -0,0 +1,66 @@
+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_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 e802b1ace7..b270748dd6 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -120,7 +120,7 @@ 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"
@@ -161,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 c8404e126e..471d9fc7c3 100644
--- a/railties/test/plugin_locator_test.rb
+++ b/railties/test/plugin_locator_test.rb
@@ -2,7 +2,7 @@ require 'plugin_test_helper'
class PluginLocatorTest < Test::Unit::TestCase
def test_should_require_subclasses_to_implement_the_plugins_method
- assert_raises(RuntimeError) do
+ assert_raise(RuntimeError) do
Rails::Plugin::Locator.new(nil).plugins
end
end
diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb
index 5500711df8..a6c390a45a 100644
--- a/railties/test/plugin_test.rb
+++ b/railties/test/plugin_test.rb
@@ -52,11 +52,11 @@ class PluginTest < Test::Unit::TestCase
plugin_for(@valid_plugin_path).load_paths
end
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin_for(@empty_plugin_path).load_paths
end
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin_for('this_is_not_a_plugin_directory').load_paths
end
end
@@ -77,13 +77,13 @@ class PluginTest < Test::Unit::TestCase
end
# This is an empty path so it raises
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin = plugin_for(@empty_plugin_path)
plugin.stubs(:evaluate_init_rb)
plugin.send(:load, @initializer)
end
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin = plugin_for('this_is_not_a_plugin_directory')
plugin.stubs(:evaluate_init_rb)
plugin.send(:load, @initializer)
@@ -97,11 +97,11 @@ class PluginTest < Test::Unit::TestCase
end
# This is an empty path so it raises
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin_for(@empty_plugin_path).load_paths
end
- assert_raises(LoadError) do
+ assert_raise(LoadError) do
plugin_for('this_is_not_a_plugin_directory').load_paths
end
end