aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-11-22 10:31:47 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-22 10:31:47 -0800
commite68bc3f14ea93eabdd4274e66071b65debb5a0a8 (patch)
tree223c11f38dac1217d8e7e3cd427fdf6018975a9d /railties
parent3cb46b40a0df1a1f4912625cc2be40b3d630f1f3 (diff)
parente1935e3c0c35f8f1196239e2b1213c4436049fa5 (diff)
downloadrails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.tar.gz
rails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.tar.bz2
rails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.zip
Merge commit 'origin/master' into mail
Diffstat (limited to 'railties')
-rw-r--r--railties/Rakefile32
-rw-r--r--railties/lib/rails.rb12
-rw-r--r--railties/lib/rails/application.rb55
-rw-r--r--railties/lib/rails/commands/destroy.rb3
-rwxr-xr-xrailties/lib/rails/commands/generate.rb3
-rw-r--r--railties/lib/rails/commands/server.rb4
-rw-r--r--railties/lib/rails/configuration.rb33
-rw-r--r--railties/lib/rails/generators.rb2
-rw-r--r--railties/lib/rails/generators/base.rb56
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb6
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/about (renamed from railties/lib/rails/generators/rails/app/templates/script/about.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/console (renamed from railties/lib/rails/generators/rails/app/templates/script/console.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/dbconsole (renamed from railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/destroy (renamed from railties/lib/rails/generators/rails/app/templates/script/destroy.tt)3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/generate (renamed from railties/lib/rails/generators/rails/app/templates/script/generate.tt)3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/benchmarker (renamed from railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/profiler (renamed from railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/plugin (renamed from railties/lib/rails/generators/rails/app/templates/script/plugin.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/runner (renamed from railties/lib/rails/generators/rails/app/templates/script/runner.tt)1
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/server (renamed from railties/lib/rails/generators/rails/app/templates/script/server.tt)1
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
-rw-r--r--railties/lib/rails/initializable.rb3
-rw-r--r--railties/lib/rails/initializer.rb14
-rw-r--r--railties/lib/rails/paths.rb6
-rw-r--r--railties/lib/rails/plugin.rb209
-rw-r--r--railties/lib/rails/plugin/loader.rb200
-rw-r--r--railties/lib/rails/plugin/locator.rb100
-rw-r--r--railties/lib/rails/rack/static.rb2
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc)7
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/LICENSE (renamed from railties/lib/rails/vendor/thor-0.11.8/LICENSE)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/README.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.8/README.rdoc)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/Thorfile (renamed from railties/lib/rails/vendor/thor-0.11.8/Thorfile)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb)14
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/file_manipulation.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/inject_into_file.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/base.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/hash_with_indifferent_access.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/ordered_hash.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/error.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb)2
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/invocation.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/argument.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/arguments.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/option.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/options.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/rake_compat.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/runner.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/basic.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/color.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/task.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/util.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb (renamed from railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb)0
-rw-r--r--railties/test/application/plugins_test.rb117
-rw-r--r--railties/test/backtrace_cleaner_test.rb4
-rw-r--r--railties/test/generators_test.rb5
-rw-r--r--railties/test/initializable_test.rb8
-rw-r--r--railties/test/initializer/initialize_i18n_test.rb42
-rw-r--r--railties/test/isolation/abstract_unit.rb36
-rw-r--r--railties/test/plugin_loader_test.rb176
-rw-r--r--railties/test/plugin_locator_test.rb73
-rw-r--r--railties/test/plugin_test.rb174
-rw-r--r--railties/test/plugin_test_helper.rb29
-rw-r--r--railties/test/plugins/vendored_test.rb190
-rw-r--r--railties/test/rails_info_test.rb13
71 files changed, 413 insertions, 1237 deletions
diff --git a/railties/Rakefile b/railties/Rakefile
index 3a87a88ddc..e6f698fc74 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -6,12 +6,8 @@ require 'rake/gempackagetask'
require 'date'
require 'rbconfig'
-begin
- require File.expand_path('../../vendor/gems/environment', __FILE__)
-rescue LoadError
-end
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib"
-require 'rails'
+require 'rails/version'
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME = ENV['PKG_NAME'] || 'rails'
@@ -26,21 +22,23 @@ RUBY_FORGE_USER = "webster132"
task :default => :test
+task :test => 'test:isolated'
## This is required until the regular test task
## below passes. It's not ideal, but at least
## we can see the failures
-task :test do
- dir = ENV["TEST_DIR"] || "**"
- Dir["test/#{dir}/*_test.rb"].all? do |file|
- next true if file.include?("fixtures")
- ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- system(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file)
- end or raise "Failures"
-end
-task :isolated_test => :test
-
-Rake::TestTask.new("regular_test") do |t|
+namespace :test do
+ task :isolated do
+ dir = ENV["TEST_DIR"] || "**"
+ Dir["test/#{dir}/*_test.rb"].all? do |file|
+ next true if file.include?("fixtures")
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ system(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file)
+ end or raise "Failures"
+ end
+end
+
+Rake::TestTask.new('test:regular') do |t|
t.libs << 'test' << "#{File.dirname(__FILE__)}/../activesupport/lib"
t.pattern = 'test/**/*_test.rb'
t.warning = true
@@ -152,7 +150,7 @@ end
# Publishing -------------------------------------------------------
desc "Publish the rails gem"
-task :pgem => [:gem] do
+task :pgem => [:gem] do
require 'rake/contrib/sshpublisher'
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index 43ece14a49..c23b67e321 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -1 +1,13 @@
+require "pathname"
+
+require 'rails/initializable'
+require 'rails/application'
+require 'rails/railties_path'
+require 'rails/version'
+require 'rails/rack'
+require 'rails/paths'
+require 'rails/core'
+require 'rails/configuration'
+require 'rails/deprecation'
require 'rails/initializer'
+require 'rails/plugin' \ No newline at end of file
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index b43dcb0041..7c2d8eab67 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -3,6 +3,11 @@ module Rails
include Initializable
class << self
+ def inherited(klass)
+ Rails.application ||= klass unless klass.name =~ /Rails/
+ super
+ end
+
# Stub out App initialize
def initialize!
new
@@ -23,10 +28,6 @@ module Rails
@config = config
end
- def plugin_loader
- @plugin_loader ||= config.plugin_loader.new(self)
- end
-
def root
config.root
end
@@ -37,7 +38,7 @@ module Rails
end
def initialize
- run_initializers
+ run_initializers(self)
end
def config
@@ -46,10 +47,6 @@ module Rails
alias configuration config
- def plugin_loader
- self.class.plugin_loader
- end
-
def middleware
config.middleware
end
@@ -58,6 +55,18 @@ module Rails
ActionController::Routing::Routes
end
+ def initializers
+ initializers = super
+ plugins.each { |p| initializers += p.initializers }
+ initializers
+ end
+
+ def plugins
+ @plugins ||= begin
+ Plugin::Vendored.all(config.plugins || [:all], config.paths.vendor.plugins)
+ end
+ end
+
def call(env)
@app ||= middleware.build(routes)
@app.call(env)
@@ -111,13 +120,6 @@ module Rails
config.load_once_paths.freeze
end
- # Adds all load paths from plugins to the global set of load paths, so that
- # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
- initializer :add_plugin_load_paths do
- require 'active_support/dependencies'
- plugin_loader.add_plugin_load_paths
- end
-
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
@@ -321,7 +323,6 @@ module Rails
# TODO: Make Rails and metal work without ActionController
if config.frameworks.include?(:action_controller)
Rails::Rack::Metal.requested_metals = config.metals
- Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
config.middleware.insert_before(
:"ActionDispatch::ParamsParser",
@@ -329,26 +330,6 @@ module Rails
end
end
- # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
- # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
- # paths, such as
- # config.plugin_paths = ["#{config.root}/lib/plugins", "#{config.root}/vendor/plugins"]
- #
- # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
- # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
- # * <tt>init.rb</tt> is evaluated, if present
- #
- # After all plugins are loaded, duplicates are removed from the load path.
- # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
- # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
- # order.
- #
- # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
- # plugins will be loaded in alphabetical order
- initializer :load_plugins do
- plugin_loader.load_plugins
- end
-
# # bail out if gems are missing - note that check_gem_dependencies will have
# # already called abort() unless $gems_rake_task is set
# return unless gems_dependencies_loaded
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index 15ff90f78a..f85c17bb94 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,3 +1,6 @@
+require 'rails/generators'
+Rails::Generators.configure!
+
if ARGV.size == 0
Rails::Generators.help
exit
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 82a658e2ed..c5e3ae3529 100755
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,3 +1,6 @@
+require 'rails/generators'
+Rails::Generators.configure!
+
if ARGV.size == 0
Rails::Generators.help
exit
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 29359e49a4..2c90851fb2 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -1,4 +1,4 @@
-require 'action_controller'
+require 'action_dispatch'
require 'fileutils'
require 'optparse'
@@ -42,7 +42,7 @@ unless server
end
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
-puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}}"
+puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}"
if options[:detach]
Process.daemon
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 2b847ba711..102a0836dc 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,17 +1,13 @@
-require 'rails/plugin/loader'
-require 'rails/plugin/locator'
require 'active_support/ordered_options'
module Rails
class Configuration
- attr_accessor :cache_classes, :load_paths,
- :load_once_paths, :after_initialize_blocks,
- :frameworks, :framework_root_path, :root, :plugin_paths, :plugins,
- :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
+ attr_accessor :cache_classes, :load_paths, :load_once_paths, :after_initialize_blocks,
+ :frameworks, :framework_root_path, :root, :gems, :plugins,
:i18n, :gems, :whiny_nils, :consider_all_requests_local,
:action_controller, :active_record, :action_view, :active_support,
:action_mailer, :active_resource,
- :log_path, :log_level, :logger, :preload_frameworks,
+ :reload_plugins, :log_path, :log_level, :logger, :preload_frameworks,
:database_configuration_file, :cache_store, :time_zone,
:view_path, :metals, :controller_paths, :routes_configuration_file,
:eager_load_paths, :dependency_loading, :paths, :serve_static_assets
@@ -19,7 +15,6 @@ module Rails
def initialize
@load_once_paths = []
@after_initialize_blocks = []
- @loaded_plugins = []
@dependency_loading = true
@serve_static_assets = true
@@ -199,24 +194,6 @@ module Rails
@frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
- def plugin_paths
- @plugin_paths ||= ["#{root}/vendor/plugins"]
- end
-
- def plugin_loader
- @plugin_loader ||= begin
- Plugin::Loader
- end
- end
-
- def plugin_locators
- @plugin_locators ||= begin
- locators = []
- locators << Plugin::GemLocator if defined? Gem
- locators << Plugin::FileSystemLocator
- end
- end
-
def i18n
@i18n ||= begin
i18n = ActiveSupport::OrderedOptions.new
@@ -235,10 +212,6 @@ module Rails
"#{root}/config/environments/#{RAILS_ENV}.rb"
end
- def reload_plugins?
- @reload_plugins
- end
-
# Holds generators configuration:
#
# config.generators do |g|
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index fa2c11795b..19412c259e 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -9,7 +9,7 @@ require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/inflections'
# TODO: Do not always push on vendored thor
-$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.8/lib")
+$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.0/lib")
require 'rails/generators/base'
require 'rails/generators/named_base'
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index af1bf26f4a..226ae63963 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -25,8 +25,11 @@ module Rails
# Automatically sets the source root based on the class name.
#
def self.source_root
- @_rails_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
- base_name, generator_name, 'templates'))
+ @_rails_source_root ||= begin
+ if base_name && generator_name
+ File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates'))
+ end
+ end
end
# Tries to get the description from a USAGE file one folder above the source
@@ -212,7 +215,11 @@ module Rails
def self.inherited(base) #:nodoc:
super
- if base.name && base.name !~ /Base$/ && defined?(Rails.root) && Rails.root
+ # Cache source root, we need to do this, since __FILE__ is a relative value
+ # and can point to wrong directions when inside an specified directory.
+ base.source_root
+
+ if base.name && base.name !~ /Base$/ && base.base_name && base.generator_name && defined?(Rails.root) && Rails.root
path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
if base.name.include?('::')
base.source_paths << File.join(path, base.base_name, base.generator_name)
@@ -272,8 +279,10 @@ module Rails
# Sets the base_name taking into account the current class namespace.
#
def self.base_name
- if name
- @base_name ||= name.split('::').first.underscore
+ @base_name ||= begin
+ if base = name.to_s.split('::').first
+ base.underscore
+ end
end
end
@@ -283,9 +292,10 @@ module Rails
def self.generator_name
if name
@generator_name ||= begin
- klass_name = name.to_s.split('::').last
- klass_name.sub!(/Generator$/, '')
- klass_name.underscore
+ if klass_name = name.to_s.split('::').last
+ klass_name.sub!(/Generator$/, '')
+ klass_name.underscore
+ end
end
end
end
@@ -294,35 +304,27 @@ module Rails
# Rails::Generators.options.
#
def self.default_value_for_option(name, options)
- config = Rails::Generators.options
- generator, base = generator_name.to_sym, base_name.to_sym
-
- if config[generator] && config[generator].key?(name)
- config[generator][name]
- elsif config[base] && config[base].key?(name)
- config[base][name]
- elsif config[:rails].key?(name)
- config[:rails][name]
- else
- options[:default]
- end
+ default_for_option(Rails::Generators.options, name, options, options[:default])
end
# Return default aliases for the option name given doing a lookup in
# Rails::Generators.aliases.
#
def self.default_aliases_for_option(name, options)
- config = Rails::Generators.aliases
- generator, base = generator_name.to_sym, base_name.to_sym
+ default_for_option(Rails::Generators.aliases, name, options, options[:aliases])
+ end
- if config[generator] && config[generator].key?(name)
- config[generator][name]
- elsif config[base] && config[base].key?(name)
- config[base][name]
+ # Return default for the option name given doing a lookup in config.
+ #
+ def self.default_for_option(config, name, options, default)
+ if generator_name and c = config[generator_name.to_sym] and c.key?(name)
+ c[name]
+ elsif base_name and c = config[base_name.to_sym] and c.key?(name)
+ c[name]
elsif config[:rails].key?(name)
config[:rails][name]
else
- options[:aliases]
+ default
end
end
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index e552cc4520..2bcea4bc8f 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -123,8 +123,10 @@ module Rails::Generators
end
def create_script_files
- directory "script"
- chmod "script", 0755, :verbose => false
+ directory "script" do |file|
+ prepend_file file, "#{shebang}\n", :verbose => false
+ chmod file, 0755, :verbose => false
+ end
end
def create_test_files
diff --git a/railties/lib/rails/generators/rails/app/templates/script/about.tt b/railties/lib/rails/generators/rails/app/templates/script/about
index 7639d4040f..93fd007649 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/about.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/about
@@ -1,4 +1,3 @@
-<%= shebang %>
require File.expand_path('../../config/environment', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'rails/commands/about'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/console.tt b/railties/lib/rails/generators/rails/app/templates/script/console
index 1cd2eb8b53..20aa799d2f 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/console.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/console
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/console'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
index 94beb13715..e6a1c59394 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/dbconsole'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt b/railties/lib/rails/generators/rails/app/templates/script/destroy
index 6adc90b2c3..adfa8e8426 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/destroy
@@ -1,5 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/environment', __FILE__)
-require 'rails/generators'
-Rails::Generators.configure!
require 'rails/commands/destroy'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate
index 71d47dec92..6fb8ad0395 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/generate
@@ -1,5 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/environment', __FILE__)
-require 'rails/generators'
-Rails::Generators.configure!
require 'rails/commands/generate'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
index 9ebc4c92fc..9647d8f10a 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../../config/environment', __FILE__)
require 'rails/commands/performance/benchmarker'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
index 5f4c763f9d..a5822042d2 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../../config/environment', __FILE__)
require 'rails/commands/performance/profiler'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt b/railties/lib/rails/generators/rails/app/templates/script/plugin
index 4a335ee33c..1f1af6c880 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/plugin
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/plugin'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner.tt b/railties/lib/rails/generators/rails/app/templates/script/runner
index 34ad7c18eb..7a70828e90 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/runner.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/runner
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/environment', __FILE__)
require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/server.tt b/railties/lib/rails/generators/rails/app/templates/script/server
index 932e72ea58..a7aaee2953 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/server.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/server
@@ -1,3 +1,2 @@
-<%= shebang %>
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/server'
diff --git a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
index 4b60558b43..a3dc38d9e4 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
@@ -1,5 +1,5 @@
require 'test_helper'
-require 'performance_test_help'
+require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionController::PerformanceTest
diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
index 27c91b0fca..362e3dc09f 100644
--- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
+++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
@@ -1,5 +1,5 @@
require 'test_helper'
-require 'performance_test_help'
+require 'rails/performance_test_help'
class <%= class_name %>Test < ActionController::PerformanceTest
# Replace this with your real tests.
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb
index d78eab9a75..3866b856b2 100644
--- a/railties/lib/rails/initializable.rb
+++ b/railties/lib/rails/initializable.rb
@@ -42,7 +42,8 @@ module Rails
if initializer.before
index = index_for(initializer.before)
elsif initializer.after
- index = index_for(initializer.after) + 1
+ index = index_for(initializer.after)
+ index += 1 if index
else
index = length
end
diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb
index 2ad1e52746..44d04688c8 100644
--- a/railties/lib/rails/initializer.rb
+++ b/railties/lib/rails/initializer.rb
@@ -1,14 +1,4 @@
-require "pathname"
-
-require 'rails/initializable'
-require 'rails/application'
-require 'rails/railties_path'
-require 'rails/version'
-require 'rails/rack'
-require 'rails/paths'
-require 'rails/core'
-require 'rails/configuration'
-require 'rails/deprecation'
+require "rails" # In case people require this file directly
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -24,4 +14,4 @@ module Rails
end
end
end
-end
+end \ No newline at end of file
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index 0f24106353..b3d105d8c7 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -64,7 +64,7 @@ module Rails
end
class Path
- include PathParent
+ include PathParent, Enumerable
attr_reader :path
attr_accessor :glob
@@ -83,6 +83,10 @@ module Rails
@root.all_paths << self
end
+ def each
+ to_a.each { |p| yield p }
+ end
+
def push(path)
@paths.push path
end
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 090ec6e4cb..86bf032641 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,183 +1,64 @@
module Rails
- # The Plugin class should be an object which provides the following methods:
- #
- # * +name+ - Used during initialisation to order the plugin (based on name and
- # the contents of <tt>config.plugins</tt>).
- # * +valid?+ - Returns true if this plugin can be loaded.
- # * +load_paths+ - Each path within the returned array will be added to the <tt>$LOAD_PATH</tt>.
- # * +load+ - Finally 'load' the plugin.
- #
- # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes.
- # The default implementation returns the <tt>lib</tt> directory as its <tt>load_paths</tt>,
- # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called.
- #
- # You can also inspect the about.yml data programmatically:
- #
- # plugin = Rails::Plugin.new(path_to_my_plugin)
- # plugin.about["author"] # => "James Adam"
- # plugin.about["url"] # => "http://interblah.net"
class Plugin
- include Comparable
include Initializable
-
- attr_reader :directory, :name
-
- def initialize(directory)
- @directory = directory
- @name = File.basename(@directory) rescue nil
- @loaded = false
- end
-
- def valid?
- File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?)
- end
-
- # Returns a list of paths this plugin wishes to make available in <tt>$LOAD_PATH</tt>.
- def load_paths
- report_nonexistant_or_empty_plugin! unless valid?
-
- load_paths = []
- load_paths << lib_path if has_lib_directory?
- load_paths << app_paths if has_app_directory?
- load_paths.flatten
- end
-
- # Evaluates a plugin's init.rb file.
- def load(initializer)
- return if loaded?
- report_nonexistant_or_empty_plugin! unless valid?
- evaluate_init_rb(initializer)
- @loaded = true
- end
-
- def loaded?
- @loaded
- end
-
- def <=>(other_plugin)
- name <=> other_plugin.name
- end
-
- def about
- @about ||= load_about_information
- end
-
- # Engines are plugins with an app/ directory.
- def engine?
- has_app_directory?
- end
-
- # Returns true if the engine ships with a routing file
- def routed?
- File.exist?(routing_file)
- end
-
- # Returns true if there is any localization file in locale_path
- def localized?
- locale_files.any?
- end
-
- def view_path
- File.join(directory, 'app', 'views')
- end
-
- def controller_path
- 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
-
- def locale_path
- File.join(directory, 'config', 'locales')
- end
-
- def locale_files
- Dir[ File.join(locale_path, '*.{rb,yml}') ]
- end
-
- private
- def load_about_information
- about_yml_path = File.join(@directory, "about.yml")
- parsed_yml = File.exist?(about_yml_path) ? YAML.load(File.read(about_yml_path)) : {}
- parsed_yml || {}
- rescue Exception
- {}
- end
- def report_nonexistant_or_empty_plugin!
- raise LoadError, "Can not find the plugin named: #{name}"
- end
-
- def app_paths
- [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ]
- end
-
- def lib_path
- File.join(directory, 'lib')
- end
-
- def classic_init_path
- File.join(directory, 'init.rb')
- end
+ class Vendored < Plugin
+ def self.all(list, paths)
+ plugins = []
+ paths.each do |path|
+ Dir["#{path}/*"].each do |plugin_path|
+ plugin = new(plugin_path)
+ next unless list.include?(plugin.name) || list.include?(:all)
+ plugins << plugin
+ end
+ end
- def gem_init_path
- File.join(directory, 'rails', 'init.rb')
- end
+ plugins.sort_by do |p|
+ [list.index(p.name) || list.index(:all), p.name.to_s]
+ end
+ end
- def init_path
- File.file?(gem_init_path) ? gem_init_path : classic_init_path
- end
+ attr_reader :name, :path
- def has_app_directory?
- File.directory?(File.join(directory, 'app'))
- end
+ def initialize(path)
+ @name = File.basename(path).to_sym
+ @path = path
+ end
- def has_lib_directory?
- File.directory?(lib_path)
- end
+ def load_paths
+ Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
+ end
- def has_init_file?
- File.file?(init_path)
- end
+ initializer :add_to_load_path, :after => :set_autoload_paths do |app|
+ load_paths.each do |path|
+ $LOAD_PATH << path
+ require "active_support/dependencies"
- def evaluate_init_rb(initializer)
- if has_init_file?
- require 'active_support/core_ext/kernel/reporting'
- silence_warnings do
- # Allow plugins to reference the current configuration object
- config = initializer.configuration
+ ActiveSupport::Dependencies.load_paths << path
- eval(IO.read(init_path), binding, init_path)
+ unless app.config.reload_plugins
+ ActiveSupport::Dependencies.load_once_paths << path
+ end
end
end
- end
- class Vendored < Plugin
- initializer :init_rb do |application|
- evaluate_init_rb(application)
+ initializer :load_init_rb, :before => :load_application_initializers do |app|
+ file = "#{@path}/init.rb"
+ config = app.config
+ eval File.read(file), binding, file if File.file?(file)
end
- end
- end
- # This Plugin subclass represents a Gem plugin. Although RubyGems has already
- # taken care of $LOAD_PATHs, it exposes its load_paths to add them
- # to Dependencies.load_paths.
- class GemPlugin < Plugin
- # Initialize this plugin from a Gem::Specification.
- def initialize(spec, gem)
- directory = spec.full_gem_path
- super(directory)
- @name = spec.name
- end
+ initializer :add_view_paths, :after => :initialize_framework_views do
+ ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views")
+ end
- def init_path
- File.join(directory, 'rails', 'init.rb')
+ initializer :add_routing_file, :after => :initialize_routing do |app|
+ routing_file = "#{path}/config/routes.rb"
+ if File.exist?(routing_file)
+ app.routes.add_configuration_file(routing_file)
+ app.routes.reload!
+ end
+ end
end
end
-end
+end \ No newline at end of file
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
deleted file mode 100644
index 4808c6ad57..0000000000
--- a/railties/lib/rails/plugin/loader.rb
+++ /dev/null
@@ -1,200 +0,0 @@
-require "rails/plugin"
-
-module Rails
- class Plugin
- class Loader
- attr_reader :initializer
-
- # Creates a new Plugin::Loader instance, associated with the given
- # Rails::Initializer. This default implementation automatically locates
- # all plugins, and adds all plugin load paths, when it is created. The plugins
- # are then fully loaded (init.rb is evaluated) when load_plugins is called.
- #
- # It is the loader's responsibility to ensure that only the plugins specified
- # in the configuration are actually loaded, and that the order defined
- # is respected.
- def initialize(initializer)
- @initializer = initializer
- end
-
- # Returns the plugins to be loaded, in the order they should be loaded.
- def plugins
- @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
- end
-
- # Returns the plugins that are in engine-form (have an app/ directory)
- def engines
- @engines ||= plugins.select {|plugin| plugin.engine? }
- end
-
- # Returns all the plugins that could be found by the current locators.
- def all_plugins
- @all_plugins ||= locate_plugins
- @all_plugins
- end
-
- def load_plugins
- plugins.each do |plugin|
- plugin.load(initializer)
- register_plugin_as_loaded(plugin)
- end
-
- configure_engines
-
- ensure_all_registered_plugins_are_loaded!
- end
-
- # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
- # added *after* the application's <tt>lib</tt> directory, to ensure that an application
- # can always override code within a plugin.
- #
- # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
- def add_plugin_load_paths
- plugins.each do |plugin|
- plugin.load_paths.each do |path|
- $LOAD_PATH.insert(application_lib_index + 1, path)
-
- ActiveSupport::Dependencies.load_paths << path
-
- unless configuration.reload_plugins?
- ActiveSupport::Dependencies.load_once_paths << path
- end
- end
- end
-
- $LOAD_PATH.uniq!
- end
-
- def engine_metal_paths
- engines.collect {|engine| engine.metal_path }
- end
-
- protected
- def configure_engines
- if engines.any?
- add_engine_routing_configurations
- add_engine_locales
- add_engine_controller_paths
- add_engine_view_paths
- end
- end
-
- def add_engine_routing_configurations
- engines.select {|engine| engine.routed? }.map {|engine| engine.routing_file }.each do |routing_file|
- ActionController::Routing::Routes.add_configuration_file(routing_file)
- end
- end
-
- def add_engine_locales
- localized_engines = engines.select { |engine| engine.localized? }
-
- # reverse it such that the last engine can overwrite translations from the first, like with routes
- locale_files = localized_engines.collect { |engine| engine.locale_files }.reverse.flatten
- I18n.load_path += locale_files - I18n.load_path
- end
-
- def add_engine_controller_paths
- ActionController::Routing.controller_paths += engines.collect {|engine| engine.controller_path }
- end
-
- def add_engine_view_paths
- # reverse it such that the last engine can overwrite view paths from the first, like with routes
- paths = ActionView::PathSet.new(engines.collect {|engine| engine.view_path }.reverse)
- ActionController::Base.view_paths.concat(paths)
- ActionMailer::Base.view_paths.concat(paths) if configuration.frameworks.include?(:action_mailer)
- end
-
- # The locate_plugins method uses each class in config.plugin_locators to
- # find the set of all plugins available to this Rails application.
- def locate_plugins
- configuration.plugin_locators.map do |locator|
- locator.new(initializer).plugins
- end.flatten
- # TODO: sorting based on config.plugins
- end
-
- def register_plugin_as_loaded(plugin)
- initializer.config.loaded_plugins << plugin
- end
-
- def configuration
- initializer.configuration
- end
-
- def should_load?(plugin)
- # uses Plugin#name and Plugin#valid?
- enabled?(plugin) && plugin.valid?
- end
-
- def order_plugins(plugin_a, plugin_b)
- if !explicit_plugin_loading_order?
- plugin_a <=> plugin_b
- else
- if !explicitly_enabled?(plugin_a) && !explicitly_enabled?(plugin_b)
- plugin_a <=> plugin_b
- else
- effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
- end
- end
- end
-
- def effective_order_of(plugin)
- if explicitly_enabled?(plugin)
- registered_plugin_names.index(plugin.name)
- else
- registered_plugin_names.index('all')
- end
- end
-
- def application_lib_index
- $LOAD_PATH.index(File.join(Rails.root, 'lib')) || 0
- end
-
- def enabled?(plugin)
- !explicit_plugin_loading_order? || registered?(plugin)
- end
-
- def explicit_plugin_loading_order?
- !registered_plugin_names.nil?
- end
-
- def registered?(plugin)
- explicit_plugin_loading_order? && registered_plugins_names_plugin?(plugin)
- end
-
- def explicitly_enabled?(plugin)
- !explicit_plugin_loading_order? || explicitly_registered?(plugin)
- end
-
- def explicitly_registered?(plugin)
- explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
- end
-
- def registered_plugins_names_plugin?(plugin)
- registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
- end
-
- # The plugins that have been explicitly listed with config.plugins. If this list is nil
- # then it means the client does not care which plugins or in what order they are loaded,
- # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
- # non empty, we load the named plugins in the order specified.
- def registered_plugin_names
- configuration.plugins ? configuration.plugins.map {|plugin| plugin.to_s } : nil
- end
-
- def loaded?(plugin_name)
- initializer.config.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
- end
-
- def ensure_all_registered_plugins_are_loaded!
- 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(:locale => :en)}"
- end
- end
- end
-
- end
- end
-end
diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb
deleted file mode 100644
index 56cbaf37c6..0000000000
--- a/railties/lib/rails/plugin/locator.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-module Rails
- class Plugin
-
- # The Plugin::Locator class should be subclasses to provide custom plugin-finding
- # abilities to Rails (i.e. loading plugins from Gems, etc). Each subclass should implement
- # the <tt>located_plugins</tt> method, which return an array of Plugin objects that have been found.
- class Locator
- include Enumerable
-
- attr_reader :initializer
-
- def initialize(initializer)
- @initializer = initializer
- end
-
- # This method should return all the plugins which this Plugin::Locator can find
- # These will then be used by the current Plugin::Loader, which is responsible for actually
- # loading the plugins themselves
- def plugins
- raise "The `plugins' method must be defined by concrete subclasses of #{self.class}"
- end
-
- def each(&block)
- plugins.each(&block)
- end
-
- def plugin_names
- plugins.map {|plugin| plugin.name }
- end
- end
-
- # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories
- # in the paths given in configuration.plugin_paths. Any plugins that can be found are returned
- # in a list.
- #
- # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although
- # other subclasses of Rails::Plugin::Locator can of course use different conditions.
- class FileSystemLocator < Locator
-
- # Returns all the plugins which can be loaded in the filesystem, under the paths given
- # by configuration.plugin_paths.
- def plugins
- initializer.configuration.plugin_paths.flatten.inject([]) do |plugins, path|
- plugins.concat locate_plugins_under(path)
- plugins
- end.flatten
- end
-
- private
-
- # Attempts to create a plugin from the given path. If the created plugin is valid?
- # (see Rails::Plugin#valid?) then the plugin instance is returned; otherwise nil.
- def create_plugin(path)
- plugin = Rails::Plugin.new(path)
- plugin.valid? ? plugin : nil
- end
-
- # This starts at the base path looking for valid plugins (see Rails::Plugin#valid?).
- # Since plugins can be nested arbitrarily deep within an unspecified number of intermediary
- # directories, this method runs recursively until it finds a plugin directory, e.g.
- #
- # locate_plugins_under('vendor/plugins/acts/acts_as_chunky_bacon')
- # => <Rails::Plugin name: 'acts_as_chunky_bacon' ... >
- #
- def locate_plugins_under(base_path)
- Dir.glob(File.join(base_path, '*')).sort.inject([]) do |plugins, path|
- if plugin = create_plugin(path)
- plugins << plugin
- elsif File.directory?(path)
- plugins.concat locate_plugins_under(path)
- end
- plugins
- end
- end
- end
-
- # The GemLocator scans all the loaded RubyGems, looking for gems with
- # a <tt>rails/init.rb</tt> file.
- class GemLocator < Locator
- def plugins
- gem_index = {}
- specs = gem_index.keys
- specs += Gem.loaded_specs.values.select do |spec|
- spec.loaded_from && # prune stubs
- File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
- end
- specs.compact!
-
- require "rubygems/dependency_list"
-
- deps = Gem::DependencyList.new
- deps.add(*specs) unless specs.empty?
-
- deps.dependency_order.collect do |spec|
- Rails::GemPlugin.new(spec, gem_index[spec])
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
index d6b8face27..ebe8b9e103 100644
--- a/railties/lib/rails/rack/static.rb
+++ b/railties/lib/rails/rack/static.rb
@@ -1,5 +1,5 @@
require 'action_dispatch'
module Rails::Rack
- Static = Deprecation::DeprecatedConstantProxy.new('Rails::Rack::Static', ActionDispatch::Static)
+ Static = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Rails::Rack::Static', ActionDispatch::Static)
end
diff --git a/railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc b/railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc
index dba25b7205..adedfeca9d 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc
+++ b/railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc
@@ -2,7 +2,12 @@
* Improve spec coverage for Thor::Runner
-== 0.11.x, released 2009-07-01
+== 0.12, released 2009-11-06
+
+* [#7] Do not force white color on status
+* [#8] Yield a block with the filename on directory
+
+== 0.11, released 2009-07-01
* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
Thor classes.
diff --git a/railties/lib/rails/vendor/thor-0.11.8/LICENSE b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
index 98722da459..98722da459 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/LICENSE
+++ b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
diff --git a/railties/lib/rails/vendor/thor-0.11.8/README.rdoc b/railties/lib/rails/vendor/thor-0.12.0/README.rdoc
index f1106f02b6..f1106f02b6 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/README.rdoc
+++ b/railties/lib/rails/vendor/thor-0.12.0/README.rdoc
diff --git a/railties/lib/rails/vendor/thor-0.11.8/Thorfile b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
index f71a1e57e2..f71a1e57e2 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/Thorfile
+++ b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
index 68944f140d..68944f140d 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb
index d561ccb2aa..d561ccb2aa 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb
index 8f6badee27..a3d9296823 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb
@@ -60,6 +60,7 @@ class Thor
FileUtils.mkdir_p(File.dirname(destination))
File.open(destination, 'w'){ |f| f.write render }
end
+ given_destination
end
protected
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb
index 063ac57406..467e63732a 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb
@@ -40,15 +40,16 @@ class Thor
# directory "doc"
# directory "doc", "docs", :recursive => false
#
- def directory(source, destination=nil, config={})
- action Directory.new(self, source, destination || source, config)
+ def directory(source, destination=nil, config={}, &block)
+ action Directory.new(self, source, destination || source, config, &block)
end
class Directory < EmptyDirectory #:nodoc:
attr_reader :source
- def initialize(base, source, destination=nil, config={})
+ def initialize(base, source, destination=nil, config={}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s))
+ @block = block
super(base, destination, { :recursive => true }.merge(config))
end
@@ -70,6 +71,7 @@ class Thor
Dir[lookup].each do |file_source|
next if File.directory?(file_source)
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
+ file_destination.gsub!('/./', '/')
case file_source
when /\.empty_directory$/
@@ -77,9 +79,11 @@ class Thor
next if dirname == given_destination
base.empty_directory(dirname, config)
when /\.tt$/
- base.template(file_source, file_destination[0..-4], config)
+ destination = base.template(file_source, file_destination[0..-4], config)
+ @block.call(destination) if @block
else
- base.copy_file(file_source, file_destination, config)
+ destination = base.copy_file(file_source, file_destination, config)
+ @block.call(destination) if @block
end
end
end
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb
index 03c1fe4af1..484cb820f8 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb
@@ -55,6 +55,7 @@ class Thor
def revoke!
say_status :remove, :red
::FileUtils.rm_rf(destination) if !pretend? && exists?
+ given_destination
end
protected
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/file_manipulation.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb
index d77d90d448..d77d90d448 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/file_manipulation.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/inject_into_file.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb
index 0636ec6591..0636ec6591 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/inject_into_file.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/base.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb
index 700d794123..700d794123 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/base.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb
index 78bc5cf4bf..78bc5cf4bf 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/hash_with_indifferent_access.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/ordered_hash.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb
index 27fea5bb35..27fea5bb35 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/ordered_hash.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/error.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb
index f9b31a35d1..f9b31a35d1 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/error.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb
index 1e59df2313..0964a9667a 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb
@@ -74,7 +74,7 @@ class Thor::Group
#
def invoke(*names, &block)
options = names.last.is_a?(Hash) ? names.pop : {}
- verbose = options.fetch(:verbose, :white)
+ verbose = options.fetch(:verbose, true)
names.each do |name|
invocations[name] = false
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/invocation.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb
index 32e6a72454..32e6a72454 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/invocation.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb
index 57a3f6e1a5..57a3f6e1a5 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/argument.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb
index aa8ace4719..aa8ace4719 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/argument.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/arguments.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb
index fb5d965e06..fb5d965e06 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/arguments.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/option.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb
index 9e40ec73fa..9e40ec73fa 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/option.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/options.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb
index 75092308b5..75092308b5 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/options.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/rake_compat.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
index 0d0757fdda..0d0757fdda 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/rake_compat.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/runner.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
index 9dc70ea069..9dc70ea069 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/runner.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
index 1dc8f0e5b4..1dc8f0e5b4 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/basic.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb
index ea9665380b..ea9665380b 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/basic.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/color.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb
index 24704f7885..24704f7885 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/color.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/task.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb
index 91c7564d3f..91c7564d3f 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/task.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/util.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
index ebae0a3193..ebae0a3193 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/util.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
index 885230fac4..885230fac4 100644
--- a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb
deleted file mode 100644
index 80a19856d7..0000000000
--- a/railties/test/application/plugins_test.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-require "isolation/abstract_unit"
-
-module ApplicationTests
- class PluginTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
-
- def assert_plugins(list_of_names, array_of_plugins, message=nil)
- assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message
- end
-
- def setup
- build_app
- boot_rails
- require "rails"
- @failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- # Tmp hax to get tests working
- FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor"
- end
-
- test "all plugins are loaded when registered plugin list is untouched" do
- Rails::Initializer.run { |c| c.root = app_path }
- Rails.initialize!
- assert_plugins [
- :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby
- ], Rails.application.config.loaded_plugins, @failure_tip
- end
-
- test "no plugins are loaded if the configuration has an empty plugin list" do
- Rails::Initializer.run { |c| c.root = app_path; c.plugins = [] }
- assert_plugins [], Rails.application.config.loaded_plugins
- end
-
- test "only the specified plugins are located in the order listed" do
- plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
- Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names }
- Rails.initialize!
- assert_plugins plugin_names, Rails.application.config.loaded_plugins
- end
-
- test "all plugins loaded after all" do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = [:stubby, :all, :acts_as_chunky_bacon]
- end
- Rails.initialize!
- assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip
- end
-
- test "plugin names may be strings" do
- plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- end
- Rails.initialize!
-
- assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip
- end
-
- test "all plugins loaded when all is used" do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = [:stubby, :acts_as_chunky_bacon, :all]
- end
- Rails.initialize!
-
- assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip
- end
-
- test "all loaded plugins are added to the load paths" do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = [:stubby, :acts_as_chunky_bacon]
- end
- Rails.initialize!
-
- assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib")
- assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib")
- end
-
- test "registering a plugin name that does not exist raises a load error" do
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = [:stubby, :acts_as_a_non_existant_plugin]
- end
-
- assert_raise(LoadError) do
- Rails.initialize!
- end
- end
-
- test "load error messages mention missing plugins and no others" do
- valid_plugins = [:stubby, :acts_as_chunky_bacon]
- invalid_plugins = [:non_existant_plugin1, :non_existant_plugin2]
-
- begin
- Rails::Initializer.run do |config|
- config.root = app_path
- config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2]
- end
- Rails.initialize!
- flunk "Expected a LoadError but did not get one"
- rescue LoadError => e
- assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip
-
- invalid_plugins.each do |plugin|
- assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
- end
-
- valid_plugins.each do |plugin|
- assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'")
- end
- end
- end
-
- end
-end \ No newline at end of file
diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb
index 4e273852e0..6cff591b94 100644
--- a/railties/test/backtrace_cleaner_test.rb
+++ b/railties/test/backtrace_cleaner_test.rb
@@ -16,12 +16,12 @@ if defined? Test::Unit::Util::BacktraceFilter
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.send(: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')
+ @test.send(:filter_backtrace, @backtrace, '/opt/local/lib')
end
end
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 9c9a4e6016..a8716d9992 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -166,10 +166,7 @@ class GeneratorsTest < GeneratorsTestCase
Rails::Generators.options[:new_generator] = { :generate => false }
klass = Class.new(Rails::Generators::Base) do
- def self.name
- "NewGenerator"
- end
-
+ def self.name() 'NewGenerator' end
class_option :generate, :default => true
end
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index 2920883132..a9e60680ac 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -94,6 +94,10 @@ module InitializableTests
include Rails::Initializable
initializer :startup, :before => :last do
+ $arr << 3
+ end
+
+ initializer :terminate, :after => :first do
$arr << two
end
@@ -109,7 +113,7 @@ module InitializableTests
end
initializer :last do
- $arr << 3
+ $arr << 4
end
def self.initializers
@@ -189,7 +193,7 @@ module InitializableTests
test "merges in the initializers from the parent in the right order" do
$arr = []
OverriddenInitializer.new.run_initializers
- assert_equal [1, 2, 3], $arr
+ assert_equal [1, 2, 3, 4], $arr
end
end
end \ No newline at end of file
diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb
index d664f96ad1..076816d73b 100644
--- a/railties/test/initializer/initialize_i18n_test.rb
+++ b/railties/test/initializer/initialize_i18n_test.rb
@@ -30,27 +30,27 @@ module InitializerTests
end
test "i18n finds locale files in engines" do
- app_file "vendor/plugins/engine/init.rb", ""
- app_file "vendor/plugins/engine/app/models/hellos.rb", "class Hello ; end"
- app_file "vendor/plugins/engine/lib/omg.rb", "puts 'omg'"
- app_file "vendor/plugins/engine/config/locales/en.yml", "hello:"
-
- Rails::Initializer.run do |c|
- c.root = app_path
- c.i18n.load_path << "my/other/locale.yml"
- end
- Rails.initialize!
-
- #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
- assert_equal %W(
- #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml
- #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
- #{app_path}/config/locales/en.yml
- my/other/locale.yml
- #{app_path}/vendor/plugins/engine/config/locales/en.yml
- ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
+ # app_file "vendor/plugins/engine/init.rb", ""
+ # app_file "vendor/plugins/engine/app/models/hellos.rb", "class Hello ; end"
+ # app_file "vendor/plugins/engine/lib/omg.rb", "puts 'omg'"
+ # app_file "vendor/plugins/engine/config/locales/en.yml", "hello:"
+ #
+ # Rails::Initializer.run do |c|
+ # c.root = app_path
+ # c.i18n.load_path << "my/other/locale.yml"
+ # end
+ # Rails.initialize!
+ #
+ # #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
+ # assert_equal %W(
+ # #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
+ # #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml
+ # #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml
+ # #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
+ # #{app_path}/config/locales/en.yml
+ # my/other/locale.yml
+ # #{app_path}/vendor/plugins/engine/config/locales/en.yml
+ # ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
end
end
end \ No newline at end of file
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 462a4d8dea..ba8b35d5cc 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -92,6 +92,34 @@ module TestHelpers
add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
end
+ class Bukkit
+ def initialize(path)
+ @path = path
+ end
+
+ def write(file, string)
+ path = "#{@path}/#{file}"
+ FileUtils.mkdir_p(File.dirname(path))
+ File.open(path, "w") {|f| f.puts string }
+ end
+
+ def delete(file)
+ File.delete("#{@path}/#{file}")
+ end
+ end
+
+ def plugin(name, string = "")
+ dir = "#{app_path}/vendor/plugins/#{name}"
+ FileUtils.mkdir_p(dir)
+ File.open("#{dir}/init.rb", 'w') do |f|
+ f.puts "::#{name.upcase} = 'loaded'"
+ f.puts string
+ end
+ Bukkit.new(dir).tap do |bukkit|
+ yield bukkit if block_given?
+ end
+ end
+
def script(script)
Dir.chdir(app_path) do
`#{Gem.ruby} #{app_path}/script/#{script}`
@@ -157,9 +185,13 @@ Module.new do
FileUtils.mkdir(tmp_path)
environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
+ if File.exist?("#{environment}.rb")
+ require_environment = "-r #{environment}"
+ end
- `#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
+ `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
- f.puts "require '#{environment}' ; require 'rails'"
+ f.puts "require '#{environment}'" if require_environment
+ f.puts "require 'rails'"
end
end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
deleted file mode 100644
index 0b43c49bb2..0000000000
--- a/railties/test/plugin_loader_test.rb
+++ /dev/null
@@ -1,176 +0,0 @@
-require 'plugin_test_helper'
-
-$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
-$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
-require 'action_controller'
-require 'action_mailer'
-
-# TODO: Rewrite all these tests
-class FakeInitializerSlashApplication
- attr_reader :config
- alias configuration config
-
- def initialize
- @config = Rails::Configuration.new
- end
-end
-
-class TestPluginLoader < Test::Unit::TestCase
- ORIGINAL_LOAD_PATH = $LOAD_PATH.dup
-
- def setup
- reset_load_path!
-
- @initializer = FakeInitializerSlashApplication.new
- @configuration = @initializer.config
- Rails.application = @initializer
- @configuration.plugin_paths << plugin_fixture_root_path
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
-
- @failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
-
- @loader = Rails::Plugin::Loader.new(@initializer)
- end
-
- def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result
- locator_1 = stub(:plugins => [:a, :b, :c])
- locator_2 = stub(:plugins => [:d, :e, :f])
- locator_class_1 = stub(:new => locator_1)
- locator_class_2 = stub(:new => locator_2)
- @configuration.plugin_locators = [locator_class_1, locator_class_2]
- assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins)
- end
-
- def test_should_memoize_the_result_of_locate_plugins_as_all_plugins
- plugin_list = [:a, :b, :c]
- @loader.expects(:locate_plugins).once.returns(plugin_list)
- assert_equal plugin_list, @loader.all_plugins
- assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again
- end
-
- def test_should_return_empty_array_if_configuration_plugins_is_empty
- @configuration.plugins = []
- assert_equal [], @loader.plugins
- end
-
- def test_should_find_all_availble_plugins_and_return_as_all_plugins
- assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip
- end
-
- def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
- end
-
- def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil
- @configuration.plugins = nil
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
- end
-
- def test_should_return_specific_plugins_named_in_config_plugins_array_if_set
- plugin_names = [:acts_as_chunky_bacon, :stubby]
- only_load_the_following_plugins! plugin_names
- assert_plugins plugin_names, @loader.plugins
- end
-
- def test_should_respect_the_order_of_plugins_given_in_configuration
- plugin_names = [:stubby, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- assert_plugins plugin_names, @loader.plugins
- end
-
- def test_should_load_all_plugins_in_natural_order_when_all_is_used
- only_load_the_following_plugins! [:all]
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
- end
-
- def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all]
- assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
- end
-
- def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all
- only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon]
- assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip
- end
-
- def test_should_accept_plugin_names_given_as_strings
- only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
- end
-
- def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
- stubbed_application_lib_index_in_LOAD_PATHS = 4
- @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS)
-
- @loader.add_plugin_load_paths
-
- assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
- assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
- end
-
- def test_should_add_plugin_load_paths_to_Dependencies_load_paths
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
-
- @loader.add_plugin_load_paths
-
- assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
- assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
- end
-
- def test_should_add_engine_load_paths_to_Dependencies_load_paths
- only_load_the_following_plugins! [:engine]
-
- @loader.add_plugin_load_paths
-
- %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_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.map { |p| p.to_s }
- assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths.map { |p| p.to_s }
- end
-
- def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
-
- @loader.add_plugin_load_paths
-
- assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
- assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
- end
-
- def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array
- plugin_load_paths = ["a", "b"]
- plugin = stub(:load_paths => plugin_load_paths)
- @loader.stubs(:plugins).returns([plugin])
-
- @loader.add_plugin_load_paths
-
- plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) }
- end
-
- def test_should_add_locale_files_to_I18n_load_path
- only_load_the_following_plugins! [:engine]
-
- @loader.send :add_engine_locales
-
- assert I18n.load_path.include?(File.join(plugin_fixture_path('engines/engine'), 'config', 'locales', 'en.yml'))
- end
-
-
- private
- def reset_load_path!
- $LOAD_PATH.clear
- ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path }
- end
-end
diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb
deleted file mode 100644
index ef57e7ed4c..0000000000
--- a/railties/test/plugin_locator_test.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-require 'plugin_test_helper'
-
-# TODO: Rewrite all these tests
-class FakeInitializerSlashApplication
- attr_reader :config
- alias configuration config
-
- def initialize
- @config = Rails::Configuration.new
- end
-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)
-
- locator.each do |plugin|
- plugin_consumer.consume(plugin)
- end
- end
-end
-
-class PluginFileSystemLocatorTest < Test::Unit::TestCase
- def setup
- @initializer = FakeInitializerSlashApplication.new
- @configuration = @initializer.config
- Rails.application = @initializer
- # 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
- @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_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 { |p| p.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 { |p| p.name }.sort
-
- @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
- assert_equal ["a"], @locator.plugins.map { |p| p.name }
- end
-
- 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
deleted file mode 100644
index 199adcfe39..0000000000
--- a/railties/test/plugin_test.rb
+++ /dev/null
@@ -1,174 +0,0 @@
-require 'plugin_test_helper'
-
-# TODO: Rewrite all these tests
-class FakeInitializerSlashApplication
- attr_reader :config
- alias configuration config
-
- def initialize
- @config = Rails::Configuration.new
- end
-end
-
-class PluginTest < Test::Unit::TestCase
- def setup
- @initializer = FakeInitializerSlashApplication.new
- @configuration = @initializer.config
- Rails.application = @initializer
- @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_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 test_should_not_be_loaded_when_created
- assert !plugin_for(@valid_plugin_path).loaded?
- 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?
- 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
- 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
-
- assert_raise(LoadError) do
- plugin_for(@empty_plugin_path).load_paths
- end
-
- assert_raise(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
-
- # 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_raise(LoadError) do
- plugin = plugin_for(@empty_plugin_path)
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
-
- assert_raise(LoadError) do
- plugin = plugin_for('this_is_not_a_plugin_directory')
- plugin.stubs(:evaluate_init_rb)
- plugin.send(:load, @initializer)
- end
- 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_raise(LoadError) do
- plugin_for(@empty_plugin_path).load_paths
- end
-
- assert_raise(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)
- 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
-
- 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 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_should_return_empty_hash_for_about_if_about_yml_is_malformed
- assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about)
- end
-
- 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/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb
deleted file mode 100644
index 93004e0ddf..0000000000
--- a/railties/test/plugin_test_helper.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../lib"
-$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
-
-require 'test/unit'
-require 'active_support'
-require 'rails/initializer'
-require 'abstract_unit'
-
-# We need to set RAILS_ROOT if it isn't already set
-RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
-
-class Test::Unit::TestCase
- private
- def plugin_fixture_root_path
- File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'plugins'))
- end
-
- def only_load_the_following_plugins!(plugins)
- @initializer.configuration.plugins = plugins
- end
-
- def plugin_fixture_path(path)
- File.join(plugin_fixture_root_path, path)
- end
-
- def assert_plugins(list_of_names, array_of_plugins, message=nil)
- assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message
- end
-end
diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb
index 71de542ff7..9a2d40cad8 100644
--- a/railties/test/plugins/vendored_test.rb
+++ b/railties/test/plugins/vendored_test.rb
@@ -1,19 +1,195 @@
require "isolation/abstract_unit"
-module ApplicationTests
- class PluginTest < Test::Unit::TestCase
+module PluginsTest
+ class VendoredTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
- end
- test "generates the plugin" do
- script "generate plugin my_plugin"
- File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f|
- f.puts "OMG = 'hello'"
+ @plugin = plugin "bukkits", "::LEVEL = config.log_level" do |plugin|
+ plugin.write "lib/bukkits.rb", "class Bukkits; end"
end
+ end
+
+ def boot_rails
+ super
+ require "#{app_path}/config/environment"
+ end
+
+ test "it loads the plugin's init.rb file" do
+ boot_rails
+ assert_equal "loaded", BUKKITS
+ end
+
+ test "the init.rb file has access to the config object" do
+ boot_rails
+ assert_equal :debug, LEVEL
+ end
+
+ test "the plugin puts its lib directory on the load path" do
+ boot_rails
+ require "bukkits"
+ assert_equal "Bukkits", Bukkits.name
+ end
+
+ test "plugin paths get added to the AS::Dependency list" do
+ boot_rails
+ assert_equal "Bukkits", Bukkits.name
+ end
+
+ test "plugin constants do not get reloaded by default" do
+ boot_rails
+ assert_equal "Bukkits", Bukkits.name
+ ActiveSupport::Dependencies.clear
+ @plugin.delete("lib/bukkits.rb")
+ assert_nothing_raised { Bukkits }
+ end
+
+ test "plugin constants get reloaded if config.reload_plugins is set" do
+ add_to_config <<-RUBY
+ config.reload_plugins = true
+ RUBY
+
+ boot_rails
+
+ assert_equal "Bukkits", Bukkits.name
+ ActiveSupport::Dependencies.clear
+ @plugin.delete("lib/bukkits.rb")
+ assert_raises(NameError) { Bukkits }
+ end
+
+ test "plugin should work without init.rb" do
+ @plugin.delete("init.rb")
+
+ boot_rails
+
+ require "bukkits"
+ assert_nothing_raised { Bukkits }
+ end
+
+ test "the plugin puts its models directory on the load path" do
+ @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end"
+
+ boot_rails
+
+ assert_nothing_raised { MyBukkit }
+ end
+
+ test "the plugin puts is controllers directory on the load path" do
+ @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end"
+
+ boot_rails
+
+ assert_nothing_raised { BukkitController }
+ end
+
+ test "the plugin adds its view to the load path" do
+ @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY
+ class BukkitController < ActionController::Base
+ def index
+ end
+ end
+ RUBY
+
+ @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits"
+
+ boot_rails
+
+ require "action_controller"
+ require "rack/mock"
+ response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/"))
+ assert_equal "Hello bukkits\n", response[2].body
+ end
+
+ test "the plugin adds helpers to the controller's views" do
+ @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY
+ class BukkitController < ActionController::Base
+ def index
+ end
+ end
+ RUBY
+
+ @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY
+ module BukkitHelper
+ def bukkits
+ "bukkits"
+ end
+ end
+ RUBY
+
+ @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>"
+
+ boot_rails
+
+ require "rack/mock"
+ response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/"))
+ assert_equal "Hello bukkits\n", response[2].body
+ end
+
+ test "routes.rb are added to the router" do
+ @plugin.write "config/routes.rb", <<-RUBY
+ class Sprokkit
+ def self.call(env)
+ [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]]
+ end
+ end
+
+ ActionController::Routing::Routes.draw do
+ match "/sprokkit", :to => Sprokkit
+ end
+ RUBY
+
+ boot_rails
+ require "rack/mock"
+ response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit"))
+ assert_equal "I am a Sprokkit", response[2].join
+ end
+ end
+
+ class VendoredOrderingTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ $arr = []
+ plugin "a_plugin", "$arr << :a"
+ plugin "b_plugin", "$arr << :b"
+ plugin "c_plugin", "$arr << :c"
+ end
+
+ def boot_rails
+ super
require "#{app_path}/config/environment"
end
+
+ test "plugins are loaded alphabetically by default" do
+ boot_rails
+ assert_equal [:a, :b, :c], $arr
+ end
+
+ test "if specified, only those plugins are loaded" do
+ add_to_config "config.plugins = [:b_plugin]"
+ boot_rails
+ assert_equal [:b], $arr
+ end
+
+ test "the plugins are initialized in the order they are specified" do
+ add_to_config "config.plugins = [:b_plugin, :a_plugin]"
+ boot_rails
+ assert_equal [:b, :a], $arr
+ end
+
+ test "if :all is specified, the remaining plugins are loaded in alphabetical order" do
+ add_to_config "config.plugins = [:c_plugin, :all]"
+ boot_rails
+ assert_equal [:c, :a, :b], $arr
+ end
+
+ test "if :all is at the beginning, it represents the plugins not otherwise specified" do
+ add_to_config "config.plugins = [:all, :b_plugin]"
+ boot_rails
+ assert_equal [:a, :c, :b], $arr
+ end
end
end \ No newline at end of file
diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb
index dcf9966c0d..fc28d7e912 100644
--- a/railties/test/rails_info_test.rb
+++ b/railties/test/rails_info_test.rb
@@ -1,15 +1,4 @@
-$:.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 'rubygems'
-gem 'rack', '~> 1.0.0'
-
-require 'test/unit'
-require 'active_support'
-require 'active_support/test_case'
-require 'action_controller'
+require 'abstract_unit'
unless defined?(Rails) && defined?(Rails::Info)
module Rails