aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-11-17 22:47:23 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-11-17 22:47:23 +0000
commit5446d5cb05b50a9a3f317ded774be438e0eff909 (patch)
tree6b0b87efe3e95783763208215a3159fb63217a6d /railties
parent9754debb9a72f9385950e5282f3642b995ab76d8 (diff)
parentf8877d4b2a2a6f68770b376f0b1391a6295f62f2 (diff)
downloadrails-5446d5cb05b50a9a3f317ded774be438e0eff909.tar.gz
rails-5446d5cb05b50a9a3f317ded774be438e0eff909.tar.bz2
rails-5446d5cb05b50a9a3f317ded774be438e0eff909.zip
Merge remote branch 'mainstream/master'
Conflicts: activesupport/lib/active_support/core_ext/hash/conversions.rb
Diffstat (limited to 'railties')
-rw-r--r--railties/.gitignore1
-rw-r--r--railties/Rakefile26
-rwxr-xr-xrailties/bin/rails1
-rw-r--r--railties/builtin/rails_info/rails/info.rb4
-rw-r--r--railties/guides/source/2_2_release_notes.textile2
-rw-r--r--railties/guides/source/action_controller_overview.textile2
-rw-r--r--railties/guides/source/command_line.textile8
-rw-r--r--railties/lib/rails.rb12
-rw-r--r--railties/lib/rails/application.rb195
-rw-r--r--railties/lib/rails/backtrace_cleaner.rb10
-rw-r--r--railties/lib/rails/commands/about.rb1
-rw-r--r--railties/lib/rails/commands/console.rb2
-rw-r--r--railties/lib/rails/commands/dbconsole.rb2
-rw-r--r--railties/lib/rails/commands/destroy.rb4
-rwxr-xr-xrailties/lib/rails/commands/generate.rb4
-rw-r--r--railties/lib/rails/commands/performance/benchmarker.rb3
-rw-r--r--railties/lib/rails/commands/performance/profiler.rb4
-rw-r--r--railties/lib/rails/commands/runner.rb2
-rw-r--r--railties/lib/rails/commands/server.rb8
-rw-r--r--railties/lib/rails/commands/update.rb1
-rw-r--r--railties/lib/rails/configuration.rb290
-rw-r--r--railties/lib/rails/core.rb40
-rw-r--r--railties/lib/rails/deprecation.rb25
-rw-r--r--railties/lib/rails/gem_builder.rb21
-rw-r--r--railties/lib/rails/gem_dependency.rb311
-rw-r--r--railties/lib/rails/generators.rb68
-rw-r--r--railties/lib/rails/generators/actions.rb63
-rw-r--r--railties/lib/rails/generators/active_model.rb18
-rw-r--r--railties/lib/rails/generators/active_record.rb35
-rw-r--r--railties/lib/rails/generators/base.rb80
-rw-r--r--railties/lib/rails/generators/named_base.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb17
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile18
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config.ru4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb41
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/boot.rb156
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environment.rb56
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/about (renamed from railties/lib/rails/generators/rails/app/templates/script/about.tt)3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/console2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/console.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/dbconsole2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/dbconsole.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/destroy2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/destroy.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/generate2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/generate.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/benchmarker2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/profiler2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/plugin2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/plugin.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/runner2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/runner.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/server2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/server.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb2
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb25
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
-rw-r--r--railties/lib/rails/initializable.rb134
-rw-r--r--railties/lib/rails/initializer.rb15
-rw-r--r--railties/lib/rails/paths.rb18
-rw-r--r--railties/lib/rails/plugin.rb202
-rw-r--r--railties/lib/rails/plugin/loader.rb200
-rw-r--r--railties/lib/rails/plugin/locator.rb100
-rw-r--r--railties/lib/rails/ruby_version_check.rb11
-rw-r--r--railties/lib/rails/tasks.rb5
-rw-r--r--railties/lib/rails/tasks/databases.rake24
-rw-r--r--railties/lib/rails/tasks/framework.rake13
-rw-r--r--railties/lib/rails/tasks/gems.rake78
-rw-r--r--railties/lib/rails/tasks/misc.rake2
-rw-r--r--railties/lib/rails/tasks/routes.rake9
-rw-r--r--railties/lib/rails/tasks/statistics.rake5
-rw-r--r--railties/lib/rails/test_help.rb2
-rwxr-xr-xrailties/lib/rails/vendor/thor-0.11.6/bin/rake2thor87
-rwxr-xr-xrailties/lib/rails/vendor/thor-0.11.6/bin/thor7
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc)7
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/LICENSE (renamed from railties/lib/rails/vendor/thor-0.11.6/LICENSE)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/README.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.6/README.rdoc)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/Thorfile63
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/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.6/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.6/lib/thor/actions/directory.rb)18
-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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/lib/thor/rake_compat.rb)11
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb)2
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb)10
-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.6/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.6/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.6/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.6/lib/thor/util.rb)4
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb3
-rw-r--r--railties/lib/rails/vendor_gem_source_index.rb140
-rw-r--r--railties/test/abstract_unit.rb28
-rw-r--r--railties/test/application/configuration_test.rb48
-rw-r--r--railties/test/application/generators_test.rb16
-rw-r--r--railties/test/application/initializer_test.rb73
-rw-r--r--railties/test/application/load_test.rb2
-rw-r--r--railties/test/application/notifications_test.rb46
-rw-r--r--railties/test/application/plugins_test.rb101
-rw-r--r--railties/test/backtrace_cleaner_test.rb43
-rw-r--r--railties/test/boot_test.rb172
-rw-r--r--railties/test/fixtures/lib/generators/foobar/foobar_generator.rb4
-rw-r--r--railties/test/gem_dependency_test.rb220
-rw-r--r--railties/test/generators/actions_test.rb53
-rw-r--r--railties/test/generators/app_generator_test.rb11
-rw-r--r--railties/test/generators/generators_test_helper.rb26
-rw-r--r--railties/test/generators/resource_generator_test.rb2
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb41
-rw-r--r--railties/test/generators_test.rb25
-rw-r--r--railties/test/initializable_test.rb161
-rw-r--r--railties/test/initializer/check_ruby_version_test.rb31
-rw-r--r--railties/test/initializer/initialize_i18n_test.rb45
-rw-r--r--railties/test/initializer/path_test.rb3
-rw-r--r--railties/test/initializer_test.rb20
-rw-r--r--railties/test/isolation/abstract_unit.rb87
-rw-r--r--railties/test/metal_test.rb2
-rw-r--r--railties/test/paths_test.rb21
-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.rb195
-rw-r--r--railties/test/rails_info_controller_test.rb12
-rw-r--r--railties/test/rails_info_test.rb13
140 files changed, 1603 insertions, 3144 deletions
diff --git a/railties/.gitignore b/railties/.gitignore
new file mode 100644
index 0000000000..80dd262d2f
--- /dev/null
+++ b/railties/.gitignore
@@ -0,0 +1 @@
+log/
diff --git a/railties/Rakefile b/railties/Rakefile
index e36930af4f..e6f698fc74 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -6,7 +6,8 @@ require 'rake/gempackagetask'
require 'date'
require 'rbconfig'
-require File.join(File.dirname(__FILE__), 'lib/rails', 'version')
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib"
+require 'rails/version'
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME = ENV['PKG_NAME'] || 'rails'
@@ -21,20 +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|
- 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"
+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
-task :isolated_test => :test
-Rake::TestTask.new("regular_test") do |t|
+Rake::TestTask.new('test:regular') do |t|
t.libs << 'test' << "#{File.dirname(__FILE__)}/../activesupport/lib"
t.pattern = 'test/**/*_test.rb'
t.warning = true
@@ -80,7 +84,7 @@ end
# Run application generator -------------------------------------------------------------
task :create_rails do
- require File.join(File.dirname(__FILE__), 'lib', 'generators')
+ require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
Rails::Generators::AppGenerator.start [ File.basename(PKG_DESTINATION), "--quiet" ],
:destination_root => File.expand_path(File.dirname(PKG_DESTINATION))
@@ -146,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/bin/rails b/railties/bin/rails
index e743aa83f1..808df97429 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -19,6 +19,7 @@ end
ARGV << "--help" if ARGV.empty?
+require 'rails'
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
diff --git a/railties/builtin/rails_info/rails/info.rb b/railties/builtin/rails_info/rails/info.rb
index 48d89ad06a..c3784cff32 100644
--- a/railties/builtin/rails_info/rails/info.rb
+++ b/railties/builtin/rails_info/rails/info.rb
@@ -75,7 +75,7 @@ module Rails
protected
def rails_vendor_root
- @rails_vendor_root ||= "#{RAILS_ROOT}/vendor/rails"
+ @rails_vendor_root ||= "#{Rails.root}/vendor/rails"
end
def git_info
@@ -124,7 +124,7 @@ module Rails
# The application's location on the filesystem.
property 'Application root' do
- File.expand_path(RAILS_ROOT)
+ File.expand_path(Rails.root)
end
# The current Rails environment (development, test, or production).
diff --git a/railties/guides/source/2_2_release_notes.textile b/railties/guides/source/2_2_release_notes.textile
index f60af01050..15a7bdbd44 100644
--- a/railties/guides/source/2_2_release_notes.textile
+++ b/railties/guides/source/2_2_release_notes.textile
@@ -51,7 +51,7 @@ If you want to generate these guides locally, inside your application:
rake doc:guides
</ruby>
-This will put the guides inside +RAILS_ROOT/doc/guides+ and you may start surfing straight away by opening +RAILS_ROOT/doc/guides/index.html+ in your favourite browser.
+This will put the guides inside +Rails.root/doc/guides+ and you may start surfing straight away by opening +Rails.root/doc/guides/index.html+ in your favourite browser.
* Lead Contributors: "Rails Documentation Team":http://guides.rails.info/credits.html
* Major contributions from "Xavier Noria":http://advogato.org/person/fxn/diary.html and "Hongli Lai":http://izumi.plan99.net/blog/.
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile
index 756caea5fe..46a28da8c4 100644
--- a/railties/guides/source/action_controller_overview.textile
+++ b/railties/guides/source/action_controller_overview.textile
@@ -653,7 +653,7 @@ class ClientsController < ApplicationController
# Stream a file that has already been generated and stored on disk.
def download_pdf
client = Client.find(params[:id])
- send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf",
+ send_data("#{Rails.root}/files/clients/#{client.id}.pdf",
:filename => "#{client.name}.pdf",
:type => "application/pdf")
end
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index d042458419..1a571358a1 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -424,10 +424,10 @@ INFO: For a good rundown on generators, see "Understanding Generators":http://wi
Generators are code that generates code. Let's experiment by building one. Our generator will generate a text file.
-The Rails generator by default looks in these places for available generators, where RAILS_ROOT is the root of your Rails application, like /home/foobar/commandsapp:
+The Rails generator by default looks in these places for available generators, where Rails.root is the root of your Rails application, like /home/foobar/commandsapp:
-* RAILS_ROOT/lib/generators
-* RAILS_ROOT/vendor/generators
+* Rails.root/lib/generators
+* Rails.root/vendor/generators
* Inside any plugin with a directory like "generators" or "rails_generators"
* ~/.rails/generators
* Inside any Gem you have installed with a name ending in "_generator"
@@ -465,7 +465,7 @@ We take whatever args are supplied, save them to an instance variable, and liter
* Check there's a *public* directory. You bet there is.
* Run the ERb template called "tutorial.erb".
-* Save it into "RAILS_ROOT/public/tutorial.txt".
+* Save it into "Rails.root/public/tutorial.txt".
* Pass in the arguments we saved through the +:assign+ parameter.
Next we'll build the template:
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 d54120f850..7c2d8eab67 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -1,8 +1,22 @@
module Rails
class Application
- extend Initializable
+ include Initializable
class << self
+ def inherited(klass)
+ Rails.application ||= klass unless klass.name =~ /Rails/
+ super
+ end
+
+ # Stub out App initialize
+ def initialize!
+ new
+ end
+
+ def new
+ @instance ||= super
+ end
+
def config
@config ||= Configuration.new
end
@@ -14,31 +28,52 @@ module Rails
@config = config
end
- def plugin_loader
- @plugin_loader ||= config.plugin_loader.new(self)
+ def root
+ config.root
end
- def routes
- ActionController::Routing::Routes
+ def call(env)
+ new.call(env)
end
+ end
- def middleware
- config.middleware
- end
+ def initialize
+ run_initializers(self)
+ end
- def call(env)
- @app ||= middleware.build(routes)
- @app.call(env)
- end
+ def config
+ self.class.config
+ end
- def new
- initializers.run
- self
+ alias configuration config
+
+ def middleware
+ config.middleware
+ end
+
+ def routes
+ 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)
+ end
+
initializer :initialize_rails do
- Rails.initializers.run
+ Rails.run_initializers
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
@@ -48,13 +83,6 @@ module Rails
$LOAD_PATH.uniq!
end
- # Bail if boot.rb is outdated
- initializer :freak_out_if_boot_rb_is_outdated do
- unless defined?(Rails::BOOTSTRAP_VERSION)
- abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
- end
- end
-
# Requires all frameworks specified by the Configuration#frameworks
# list. By default, all frameworks (Active Record, Active Support,
# Action Pack, Action Mailer, and Active Resource) are loaded.
@@ -92,17 +120,10 @@ 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|
- FileUtils.mkdir_p(File.join(config.root_path, 'tmp', dir_to_make))
+ FileUtils.mkdir_p(File.join(config.root, 'tmp', dir_to_make))
end
end
@@ -124,15 +145,6 @@ module Rails
end
end
- initializer :add_gem_load_paths do
- require 'rails/gem_dependency'
- Rails::GemDependency.add_frozen_gem_path
- unless config.gems.empty?
- require "rubygems"
- config.gems.each { |gem| gem.add_load_paths }
- end
- end
-
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
@@ -249,6 +261,7 @@ module Rails
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer :initialize_time_zone do
if config.time_zone
+ require 'active_support/core_ext/time/zones'
zone_default = Time.__send__(:get_zone, config.time_zone)
unless zone_default
@@ -310,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",
@@ -318,94 +330,19 @@ module Rails
end
end
- initializer :check_for_unbuilt_gems do
- unbuilt_gems = config.gems.select {|gem| gem.frozen? && !gem.built? }
- if unbuilt_gems.size > 0
- # don't print if the gems:build rake tasks are being run
- unless $gems_build_rake_task
- abort <<-end_error
- The following gems have native components that need to be built
- #{unbuilt_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:build` to build the unbuilt gems.
- end_error
- end
- end
- end
-
- initializer :load_gems do
- unless $gems_rake_task
- config.gems.each { |gem| gem.load }
- 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 = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_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
-
- # TODO: Figure out if this needs to run a second time
- # load_gems
-
- initializer :check_gem_dependencies do
- unloaded_gems = config.gems.reject { |g| g.loaded? }
- if unloaded_gems.size > 0
- configuration.gems_dependencies_loaded = false
- # don't print if the gems rake tasks are being run
- unless $gems_rake_task
- abort <<-end_error
- Missing these required gems:
- #{unloaded_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:install` to install the missing gems.
- end_error
- end
- else
- configuration.gems_dependencies_loaded = true
- end
- 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
-
initializer :load_application_initializers do
- if config.gems_dependencies_loaded
- Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
- end
+ Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer|
+ load(initializer)
end
end
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
initializer :after_initialize do
- if config.gems_dependencies_loaded
- configuration.after_initialize_blocks.each do |block|
- block.call
- end
+ configuration.after_initialize_blocks.each do |block|
+ block.call
end
end
@@ -447,7 +384,7 @@ module Rails
#
# # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
initializer :load_observers do
- if config.gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
+ if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.instantiate_observers
end
end
@@ -473,14 +410,14 @@ module Rails
end
end
- # Configure generators if they were already loaded
- # ===
- # TODO: Does this need to be an initializer here?
- initializer :initialize_generators do
- if defined?(Rails::Generators)
- Rails::Generators.no_color! unless config.generators.colorize_logging
- Rails::Generators.aliases.deep_merge! config.generators.aliases
- Rails::Generators.options.deep_merge! config.generators.options
+ # For each framework, search for instrument file with Notifications hooks.
+ #
+ initializer :load_notifications_hooks do
+ config.frameworks.each do |framework|
+ begin
+ require "#{framework}/notifications"
+ rescue LoadError => e
+ end
end
end
end
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb
index 9ff8367807..cd7dd0f80a 100644
--- a/railties/lib/rails/backtrace_cleaner.rb
+++ b/railties/lib/rails/backtrace_cleaner.rb
@@ -1,5 +1,4 @@
require 'active_support/backtrace_cleaner'
-require 'rails/gem_dependency'
module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
@@ -18,7 +17,7 @@ module Rails
def initialize
super
- add_filter { |line| line.sub("#{RAILS_ROOT}/", '') }
+ add_filter { |line| line.sub("#{Rails.root}/", '') }
add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
add_filter { |line| line.sub('./', '/') } # for tests
@@ -28,17 +27,14 @@ module Rails
add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
end
-
-
+
private
def add_gem_filters
+ return unless defined? Gem
(Gem.path + [Gem.default_dir]).uniq.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
diff --git a/railties/lib/rails/commands/about.rb b/railties/lib/rails/commands/about.rb
index bc2cfcb948..d4c30bbeb2 100644
--- a/railties/lib/rails/commands/about.rb
+++ b/railties/lib/rails/commands/about.rb
@@ -1,3 +1,2 @@
-require "#{RAILS_ROOT}/config/environment"
require 'rails/info'
puts Rails::Info
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index 31448bdf1a..b977b7162f 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -12,7 +12,7 @@ OptionParser.new do |opt|
end
libs = " -r irb/completion"
-libs << %( -r "#{RAILS_ROOT}/config/environment")
+libs << %( -r "#{Rails.root}/config/environment")
libs << " -r rails/console_app"
libs << " -r rails/console_sandbox" if options[:sandbox]
libs << " -r rails/console_with_helpers"
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index e6f11a45db..4e699acf6b 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -25,7 +25,7 @@ OptionParser.new do |opt|
end
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
-unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[env]
+unless config = YAML::load(ERB.new(IO.read(Rails.root + "/config/database.yml")).result)[env]
abort "No database is configured for the environment '#{env}'"
end
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index 5013d30b83..f85c17bb94 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,5 +1,5 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
+require 'rails/generators'
+Rails::Generators.configure!
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 32cabcab10..c5e3ae3529 100755
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,5 +1,5 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
+require 'rails/generators'
+Rails::Generators.configure!
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/commands/performance/benchmarker.rb b/railties/lib/rails/commands/performance/benchmarker.rb
index e8804fe1bf..dfba4bf034 100644
--- a/railties/lib/rails/commands/performance/benchmarker.rb
+++ b/railties/lib/rails/commands/performance/benchmarker.rb
@@ -10,7 +10,6 @@ rescue ArgumentError
N = 1
end
-require RAILS_ROOT + '/config/environment'
require 'benchmark'
include Benchmark
@@ -21,4 +20,4 @@ bm(6) do |x|
ARGV.each_with_index do |expression, idx|
x.report("##{idx + 1}") { N.times { eval(expression) } }
end
-end
+end
diff --git a/railties/lib/rails/commands/performance/profiler.rb b/railties/lib/rails/commands/performance/profiler.rb
index 7df840f197..aaa075018c 100644
--- a/railties/lib/rails/commands/performance/profiler.rb
+++ b/railties/lib/rails/commands/performance/profiler.rb
@@ -3,10 +3,6 @@ if ARGV.empty?
exit(1)
end
-# Keep the expensive require out of the profile.
-$stderr.puts 'Loading Rails...'
-require RAILS_ROOT + '/config/environment'
-
# Define a method to profile.
if ARGV[1] and ARGV[1].to_i > 1
eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 510128318a..0246348c77 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -36,8 +36,6 @@ ARGV.delete(code_or_file)
ENV["RAILS_ENV"] = options[:environment]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
-require RAILS_ROOT + '/config/environment'
-
begin
if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index c138cbc9bf..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'
@@ -7,7 +7,7 @@ options = {
:Port => 3000,
:Host => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
- :config => RAILS_ROOT + "/config.ru",
+ :config => "#{Rails.root}/config.ru",
:detach => false,
:debugger => false
}
@@ -42,11 +42,11 @@ 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
- pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
+ pid = "#{Rails.root}/tmp/pids/server.pid"
File.open(pid, 'w'){ |f| f.write(Process.pid) }
at_exit { File.delete(pid) if File.exist?(pid) }
end
diff --git a/railties/lib/rails/commands/update.rb b/railties/lib/rails/commands/update.rb
index f3b3ad0775..85a81cddf0 100644
--- a/railties/lib/rails/commands/update.rb
+++ b/railties/lib/rails/commands/update.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 4a70a4800e..102a0836dc 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,84 +1,75 @@
+require 'active_support/ordered_options'
+
module Rails
class Configuration
- attr_accessor :cache_classes, :load_paths, :eager_load_paths, :framework_paths,
- :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
- :frameworks, :framework_root_path, :root_path, :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
def initialize
- set_root_path!
-
- @framework_paths = []
@load_once_paths = []
@after_initialize_blocks = []
- @loaded_plugins = []
@dependency_loading = true
- @eager_load_paths = default_eager_load_paths
- @load_paths = default_load_paths
- @plugin_paths = default_plugin_paths
- @frameworks = default_frameworks
- @plugin_loader = default_plugin_loader
- @plugin_locators = default_plugin_locators
- @gems = default_gems
- @i18n = default_i18n
- @log_path = default_log_path
- @log_level = default_log_level
- @cache_store = default_cache_store
- @view_path = default_view_path
- @controller_paths = default_controller_paths
- @routes_configuration_file = default_routes_configuration_file
- @database_configuration_file = default_database_configuration_file
- @serve_static_assets = default_serve_static_assets
-
- for framework in default_frameworks
- self.send("#{framework}=", Rails::OrderedOptions.new)
+ @serve_static_assets = true
+
+ for framework in frameworks
+ self.send("#{framework}=", ActiveSupport::OrderedOptions.new)
end
- self.active_support = Rails::OrderedOptions.new
+ self.active_support = ActiveSupport::OrderedOptions.new
end
def after_initialize(&blk)
@after_initialize_blocks << blk if blk
end
- def set_root_path!
- raise 'RAILS_ROOT is not set' unless defined?(RAILS_ROOT)
- raise 'RAILS_ROOT is not a directory' unless File.directory?(RAILS_ROOT)
-
- self.root_path =
- # Pathname is incompatible with Windows, but Windows doesn't have
- # real symlinks so File.expand_path is safe.
- if RUBY_PLATFORM =~ /(:?mswin|mingw)/
- File.expand_path(RAILS_ROOT)
+ def root
+ @root ||= begin
+ call_stack = caller.map { |p| p.split(':').first }
+ root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] }
+ root_path = File.dirname(root_path)
- # Otherwise use Pathname#realpath which respects symlinks.
- else
- Pathname.new(RAILS_ROOT).realpath.to_s
+ while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru")
+ parent = File.dirname(root_path)
+ root_path = parent != root_path && parent
end
- @paths = Rails::Application::Root.new(root_path)
- @paths.app "app", :load_path => true
- @paths.app.metals "app/metal", :eager_load => true
- @paths.app.models "app/models", :eager_load => true
- @paths.app.controllers "app/controllers", builtin_directories, :eager_load => true
- @paths.app.helpers "app/helpers", :eager_load => true
- @paths.app.services "app/services", :load_path => true
- @paths.lib "lib", :load_path => true
- @paths.vendor "vendor", :load_path => true
- @paths.vendor.plugins "vendor/plugins"
- @paths.tmp "tmp"
- @paths.tmp.cache "tmp/cache"
- @paths.config "config"
- @paths.config.locales "config/locales"
- @paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
-
- RAILS_ROOT.replace root_path
+ root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd
+
+ RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
+ Pathname.new(root).expand_path :
+ Pathname.new(root).realpath
+ end
+ end
+
+ def root=(root)
+ @root = Pathname.new(root).expand_path
+ end
+
+ def paths
+ @paths ||= begin
+ paths = Rails::Application::Root.new(root)
+ paths.app "app", :load_path => true
+ paths.app.metals "app/metal", :eager_load => true
+ paths.app.models "app/models", :eager_load => true
+ paths.app.controllers "app/controllers", builtin_directories, :eager_load => true
+ paths.app.helpers "app/helpers", :eager_load => true
+ paths.app.services "app/services", :load_path => true
+ paths.lib "lib", :load_path => true
+ paths.vendor "vendor", :load_path => true
+ paths.vendor.plugins "vendor/plugins"
+ paths.tmp "tmp"
+ paths.tmp.cache "tmp/cache"
+ paths.config "config"
+ paths.config.locales "config/locales"
+ paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
+ paths
+ end
end
# Enable threaded mode. Allows concurrent requests to controller actions and
@@ -105,7 +96,7 @@ module Rails
end
def framework_root_path
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
+ defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root}/vendor/rails"
end
def middleware
@@ -121,63 +112,69 @@ module Rails
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
end
- def default_routes_configuration_file
- File.join(root_path, 'config', 'routes.rb')
+ def routes_configuration_file
+ @routes_configuration_file ||= File.join(root, 'config', 'routes.rb')
end
- def default_controller_paths
- paths = [File.join(root_path, 'app', 'controllers')]
- paths.concat builtin_directories
- paths
+ def controller_paths
+ @controller_paths ||= begin
+ paths = [File.join(root, 'app', 'controllers')]
+ paths.concat builtin_directories
+ paths
+ end
end
- def default_cache_store
- if File.exist?("#{root_path}/tmp/cache/")
- [ :file_store, "#{root_path}/tmp/cache/" ]
- else
- :memory_store
+ def cache_store
+ @cache_store ||= begin
+ if File.exist?("#{root}/tmp/cache/")
+ [ :file_store, "#{root}/tmp/cache/" ]
+ else
+ :memory_store
+ end
end
end
- def default_database_configuration_file
- File.join(root_path, 'config', 'database.yml')
+ def database_configuration_file
+ @database_configuration_file ||= File.join(root, 'config', 'database.yml')
end
- def default_view_path
- File.join(root_path, 'app', 'views')
+ def view_path
+ @view_path ||= File.join(root, 'app', 'views')
end
- def default_eager_load_paths
- %w(
+ def eager_load_paths
+ @eager_load_paths ||= %w(
app/metal
app/models
app/controllers
app/helpers
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+ ).map { |dir| "#{root}/#{dir}" }.select { |dir| File.directory?(dir) }
end
- def default_load_paths
- paths = []
-
- # Add the old mock paths only if the directories exists
- paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
-
- # Add the app's controller directory
- paths.concat(Dir["#{root_path}/app/controllers/"])
-
- # Followed by the standard includes.
- paths.concat %w(
- app
- app/metal
- app/models
- app/controllers
- app/helpers
- app/services
- lib
- vendor
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
-
- paths.concat builtin_directories
+ def load_paths
+ @load_paths ||= begin
+ paths = []
+
+ # Add the old mock paths only if the directories exists
+ paths.concat(Dir["#{root}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root}/test/mocks/#{RAILS_ENV}")
+
+ # Add the app's controller directory
+ paths.concat(Dir["#{root}/app/controllers/"])
+
+ # Followed by the standard includes.
+ paths.concat %w(
+ app
+ app/metal
+ app/models
+ app/controllers
+ app/helpers
+ app/services
+ lib
+ vendor
+ ).map { |dir| "#{root}/#{dir}" }.select { |dir| File.directory?(dir) }
+
+ paths.concat builtin_directories
+ end
end
def builtin_directories
@@ -185,75 +182,34 @@ module Rails
(RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end
- def default_log_path
- File.join(root_path, 'log', "#{RAILS_ENV}.log")
+ def log_path
+ @log_path ||= File.join(root, 'log', "#{RAILS_ENV}.log")
end
- def default_log_level
- RAILS_ENV == 'production' ? :info : :debug
+ def log_level
+ @log_level ||= RAILS_ENV == 'production' ? :info : :debug
end
- def default_frameworks
- [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
+ def frameworks
+ @frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
- def default_plugin_paths
- ["#{root_path}/vendor/plugins"]
- end
-
- def default_plugin_loader
- require 'rails/plugin/loader'
- Plugin::Loader
- end
+ def i18n
+ @i18n ||= begin
+ i18n = ActiveSupport::OrderedOptions.new
+ i18n.load_path = []
- def default_plugin_locators
- require 'rails/plugin/locator'
- locators = []
- locators << Plugin::GemLocator if defined? Gem
- locators << Plugin::FileSystemLocator
- end
-
- def default_i18n
- i18n = Rails::OrderedOptions.new
- i18n.load_path = []
+ if File.exist?(File.join(root, 'config', 'locales'))
+ i18n.load_path << Dir[File.join(root, 'config', 'locales', '*.{rb,yml}')]
+ i18n.load_path.flatten!
+ end
- if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
- i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
- i18n.load_path.flatten!
+ i18n
end
-
- i18n
- end
-
- def default_serve_static_assets
- true
- end
-
- # Adds a single Gem dependency to the rails application. By default, it will require
- # the library with the same name as the gem. Use :lib to specify a different name.
- #
- # # gem 'aws-s3', '>= 0.4.0'
- # # require 'aws/s3'
- # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
- # :source => "http://code.whytheluckystiff.net"
- #
- # To require a library be installed, but not attempt to load it, pass :lib => false
- #
- # config.gem 'qrp', :version => '0.4.1', :lib => false
- def gem(name, options = {})
- @gems << Rails::GemDependency.new(name, options)
- end
-
- def default_gems
- []
end
def environment_path
- "#{root_path}/config/environments/#{RAILS_ENV}.rb"
- end
-
- def reload_plugins?
- @reload_plugins
+ "#{root}/config/environments/#{RAILS_ENV}.rb"
end
# Holds generators configuration:
@@ -277,6 +233,14 @@ module Rails
end
end
+ # Allows Notifications queue to be modified.
+ #
+ # config.notifications.queue = MyNewQueue.new
+ #
+ def notifications
+ ActiveSupport::Notifications
+ end
+
class Generators #:nodoc:
attr_accessor :aliases, :options, :colorize_logging
@@ -287,12 +251,16 @@ module Rails
end
def method_missing(method, *args)
- method = method.to_s.sub(/=$/, '').to_sym
- namespace = args.first.is_a?(Symbol) ? args.shift : nil
- configuration = args.first.is_a?(Hash) ? args.shift : nil
+ method = method.to_s.sub(/=$/, '').to_sym
- @options[:rails][method] = namespace if namespace
- namespace ||= method
+ if method == :rails
+ namespace, configuration = :rails, args.shift
+ elsif args.first.is_a?(Hash)
+ namespace, configuration = method, args.shift
+ else
+ namespace, configuration = args.shift, args.shift
+ @options[:rails][method] = namespace
+ end
if configuration
aliases = configuration.delete(:aliases)
diff --git a/railties/lib/rails/core.rb b/railties/lib/rails/core.rb
index 929c38bd22..a5e51ad04a 100644
--- a/railties/lib/rails/core.rb
+++ b/railties/lib/rails/core.rb
@@ -6,7 +6,7 @@ module Rails
# TODO: w0t?
class << self
def application
- @@application
+ @@application ||= nil
end
def application=(application)
@@ -18,6 +18,10 @@ module Rails
application.configuration
end
+ def initialize!
+ application.initialize!
+ end
+
def initialized?
@initialized || false
end
@@ -43,7 +47,7 @@ module Rails
end
def root
- Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
+ application && application.config.root
end
def env
@@ -66,36 +70,4 @@ module Rails
@@public_path = path
end
end
-
- class OrderedOptions < Array #:nodoc:
- def []=(key, value)
- key = key.to_sym
-
- if pair = find_pair(key)
- pair.pop
- pair << value
- else
- self << [key, value]
- end
- end
-
- def [](key)
- pair = find_pair(key.to_sym)
- pair ? pair.last : nil
- end
-
- def method_missing(name, *args)
- if name.to_s =~ /(.*)=$/
- self[$1.to_sym] = args.first
- else
- self[name]
- end
- end
-
- private
- def find_pair(key)
- self.each { |i| return i if i.first == key }
- return false
- end
- end
end \ No newline at end of file
diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb
new file mode 100644
index 0000000000..3c5b8bdec7
--- /dev/null
+++ b/railties/lib/rails/deprecation.rb
@@ -0,0 +1,25 @@
+require "active_support/string_inquirer"
+require "active_support/deprecation"
+
+RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
+ def target
+ Rails.root
+ end
+
+ def replace(val)
+ puts OMG
+ end
+
+ def warn(callstack, called, args)
+ msg = "RAILS_ROOT is deprecated! Use Rails.root instead."
+ ActiveSupport::Deprecation.warn(msg, callstack)
+ end
+end).new
+
+module Rails
+ class Configuration
+ def gem(*args)
+ ActiveSupport::Deprecation.warn("config.gem has been deprecated in favor of the Gemfile.")
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/gem_builder.rb b/railties/lib/rails/gem_builder.rb
deleted file mode 100644
index 79c61cc034..0000000000
--- a/railties/lib/rails/gem_builder.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'rubygems'
-require 'rubygems/installer'
-
-module Rails
-
- # this class hijacks the functionality of Gem::Installer by overloading its
- # initializer to only provide the information needed by
- # Gem::Installer#build_extensions (which happens to be what we have)
- class GemBuilder < Gem::Installer
-
- def initialize(spec, gem_dir)
- @spec = spec
- @gem_dir = gem_dir
- end
-
- # silence the underlying builder
- def say(message)
- end
-
- end
-end
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
deleted file mode 100644
index 06d830ba24..0000000000
--- a/railties/lib/rails/gem_dependency.rb
+++ /dev/null
@@ -1,311 +0,0 @@
-require 'rails/vendor_gem_source_index'
-
-module Gem
- def self.source_index=(index)
- @@source_index = index
- end
-end
-
-module Rails
- class GemDependency < Gem::Dependency
- attr_accessor :lib, :source, :dep
-
- def self.unpacked_path
- @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
- end
-
- @@framework_gems = {}
-
- def self.add_frozen_gem_path
- @@paths_loaded ||= begin
- source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
- Gem.clear_paths
- Gem.source_index = source_index
- # loaded before us - we can't change them, so mark them
- Gem.loaded_specs.each do |name, spec|
- @@framework_gems[name] = spec
- end
- true
- end
- end
-
- def self.from_directory_name(directory_name, load_spec=true)
- directory_name_parts = File.basename(directory_name).split('-')
- name = directory_name_parts[0..-2].join('-')
- version = directory_name_parts.last
- result = self.new(name, :version => version)
- spec_filename = File.join(directory_name, '.specification')
- if load_spec
- raise "Missing specification file in #{File.dirname(spec_filename)}. Perhaps you need to do a 'rake gems:refresh_specs'?" unless File.exists?(spec_filename)
- spec = YAML::load_file(spec_filename)
- result.specification = spec
- end
- result
- rescue ArgumentError => e
- raise "Unable to determine gem name and version from '#{directory_name}'"
- end
-
- def initialize(name, options = {})
- require 'rubygems' unless Object.const_defined?(:Gem)
-
- if options[:requirement]
- req = options[:requirement]
- elsif options[:version]
- req = Gem::Requirement.create(options[:version])
- else
- req = Gem::Requirement.default
- end
-
- @lib = options[:lib]
- @source = options[:source]
- @loaded = @frozen = @load_paths_added = false
-
- super(name, req)
- end
-
- def add_load_paths
- self.class.add_frozen_gem_path
- return if @loaded || @load_paths_added
- if framework_gem?
- @load_paths_added = @loaded = @frozen = true
- return
- end
- gem self
- @spec = Gem.loaded_specs[name]
- @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec
- @load_paths_added = true
- rescue Gem::LoadError
- end
-
- def dependencies
- return [] if framework_gem?
- return [] unless installed?
- specification.dependencies.reject do |dependency|
- dependency.type == :development
- end.map do |dependency|
- GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
- end
- end
-
- def specification
- # code repeated from Gem.activate. Find a matching spec, or the currently loaded version.
- # error out if loaded version and requested version are incompatible.
- @spec ||= begin
- matches = Gem.source_index.search(self)
- matches << @@framework_gems[name] if framework_gem?
- if Gem.loaded_specs[name] then
- # This gem is already loaded. If the currently loaded gem is not in the
- # list of candidate gems, then we have a version conflict.
- existing_spec = Gem.loaded_specs[name]
- unless matches.any? { |spec| spec.version == existing_spec.version } then
- raise Gem::Exception,
- "can't activate #{@dep}, already activated #{existing_spec.full_name}"
- end
- # we're stuck with it, so change to match
- version_requirements = Gem::Requirement.create("=#{existing_spec.version}")
- existing_spec
- else
- # new load
- matches.last
- end
- end
- end
-
- def specification=(s)
- @spec = s
- end
-
- def requirement
- r = version_requirements
- (r == Gem::Requirement.default) ? nil : r
- end
-
- def built?
- return false unless frozen?
-
- if vendor_gem?
- specification.extensions.each do |ext|
- makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile')
- return false unless File.exists?(makefile)
- end
- end
-
- true
- end
-
- def framework_gem?
- @@framework_gems.has_key?(name)
- end
-
- def frozen?
- @frozen ||= vendor_rails? || vendor_gem?
- end
-
- def installed?
- Gem.loaded_specs.keys.include?(name)
- end
-
- def load_paths_added?
- # always try to add load paths - even if a gem is loaded, it may not
- # be a compatible version (ie random_gem 0.4 is loaded and a later spec
- # needs >= 0.5 - gem 'random_gem' will catch this and error out)
- @load_paths_added
- end
-
- def loaded?
- @loaded ||= begin
- if vendor_rails?
- true
- elsif specification.nil?
- false
- else
- # check if the gem is loaded by inspecting $"
- # specification.files lists all the files contained in the gem
- gem_files = specification.files
- # select only the files contained in require_paths - typically in bin and lib
- require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/")
- gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) }
- # chop the leading directory off - a typical file might be in
- # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb
- gem_lib_files.map! { |f| f.split('/', 2)[1] }
- # if any of the files from the above list appear in $", the gem is assumed to
- # have been loaded
- !(gem_lib_files & $").empty?
- end
- end
- end
-
- def vendor_rails?
- Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?
- end
-
- def vendor_gem?
- specification && File.exists?(unpacked_gem_directory)
- end
-
- def build(options={})
- require 'rails/gem_builder'
- return if specification.nil?
- if options[:force] || !built?
- return unless File.exists?(unpacked_specification_filename)
- spec = YAML::load_file(unpacked_specification_filename)
- Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions
- puts "Built gem: '#{unpacked_gem_directory}'"
- end
- dependencies.each { |dep| dep.build(options) }
- end
-
- def install
- unless installed?
- cmd = "#{gem_command} #{install_command.join(' ')}"
- puts cmd
- puts %x(#{cmd})
- end
- end
-
- def load
- return if @loaded || @load_paths_added == false
- require(@lib || name) unless @lib == false
- @loaded = true
- rescue LoadError
- puts $!.to_s
- $!.backtrace.each { |b| puts b }
- end
-
- def refresh
- Rails::VendorGemSourceIndex.silence_spec_warnings = true
- real_gems = Gem.source_index.installed_source_index
- exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
- matches = real_gems.search(exact_dep)
- installed_spec = matches.first
- if frozen?
- if installed_spec
- # we have a real copy
- # get a fresh spec - matches should only have one element
- # note that there is no reliable method to check that the loaded
- # spec is the same as the copy from real_gems - Gem.activate changes
- # some of the fields
- real_spec = Gem::Specification.load(matches.first.loaded_from)
- write_specification(real_spec)
- puts "Reloaded specification for #{name} from installed gems."
- else
- # the gem isn't installed locally - write out our current specs
- write_specification(specification)
- puts "Gem #{name} not loaded locally - writing out current spec."
- end
- else
- if framework_gem?
- puts "Gem directory for #{name} not found - check if it's loading before rails."
- else
- puts "Something bad is going on - gem directory not found for #{name}."
- end
- end
- end
-
- def unpack(options={})
- unless frozen? || framework_gem?
- FileUtils.mkdir_p unpack_base
- Dir.chdir unpack_base do
- Gem::GemRunner.new.run(unpack_command)
- end
- # Gem.activate changes the spec - get the original
- real_spec = Gem::Specification.load(specification.loaded_from)
- write_specification(real_spec)
- end
- dependencies.each { |dep| dep.unpack(options) } if options[:recursive]
- end
-
- def write_specification(spec)
- # copy the gem's specification into GEMDIR/.specification so that
- # we can access information about the gem on deployment systems
- # without having the gem installed
- File.open(unpacked_specification_filename, 'w') do |file|
- file.puts spec.to_yaml
- end
- end
-
- def ==(other)
- self.name == other.name && self.requirement == other.requirement
- end
- alias_method :"eql?", :"=="
-
- private
-
- def gem_command
- case RUBY_PLATFORM
- when /win32/
- 'gem.bat'
- when /java/
- 'jruby -S gem'
- else
- 'gem'
- end
- end
-
- def install_command
- cmd = %w(install) << name
- cmd << "--version" << %("#{requirement.to_s}") if requirement
- cmd << "--source" << @source if @source
- cmd
- end
-
- def unpack_command
- cmd = %w(unpack) << name
- cmd << "--version" << "= "+specification.version.to_s if requirement
- cmd
- end
-
- def unpack_base
- Rails::GemDependency.unpacked_path
- end
-
- def unpacked_gem_directory
- File.join(unpack_base, specification.full_name)
- end
-
- def unpacked_specification_filename
- File.join(unpacked_gem_directory, '.specification')
- end
-
- end
-end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 0419a4e36c..19412c259e 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -1,4 +1,4 @@
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+activesupport_path = "#{File.dirname(__FILE__)}/../../../activesupport/lib"
$LOAD_PATH.unshift(activesupport_path) if File.directory?(activesupport_path)
require 'active_support'
require 'active_support/core_ext/object/blank'
@@ -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.6/lib")
+$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.0/lib")
require 'rails/generators/base'
require 'rails/generators/named_base'
@@ -72,6 +72,12 @@ module Rails
}
}
+ def self.configure!(config = Rails.application.config.generators) #:nodoc:
+ no_color! unless config.colorize_logging
+ aliases.deep_merge! config.aliases
+ options.deep_merge! config.options
+ end
+
def self.aliases #:nodoc:
@aliases ||= DEFAULT_ALIASES.dup
end
@@ -92,8 +98,6 @@ module Rails
generator_path = File.join(spec.full_gem_path, "lib/generators")
paths << generator_path if File.exist?(generator_path)
end
- elsif defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
end
paths
@@ -102,8 +106,8 @@ module Rails
# Load paths from plugin.
#
def self.plugins_generators_paths
- return [] unless defined?(RAILS_ROOT)
- Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
+ return [] unless Rails.root
+ Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "generators")]
end
# Hold configured generators fallbacks. If a plugin developer wants a
@@ -143,7 +147,7 @@ module Rails
def self.load_paths
@load_paths ||= begin
paths = []
- paths << File.join(RAILS_ROOT, "lib", "generators") if defined?(RAILS_ROOT)
+ paths << File.join(Rails.root, "lib", "generators") if Rails.root
paths << File.join(Thor::Util.user_home, ".rails", "generators")
paths += self.plugins_generators_paths
paths += self.gems_generators_paths
@@ -154,7 +158,18 @@ module Rails
end
load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
- # Receives a namespace and tries different combinations to find a generator.
+ # Rails finds namespaces exactly as thor, with three conveniences:
+ #
+ # 1) If your generator name ends with generator, as WebratGenerator, it sets
+ # its namespace to "webrat", so it can be invoked as "webrat" and not
+ # "webrat_generator";
+ #
+ # 2) If your generator has a generators namespace, as Rails::Generators::WebratGenerator,
+ # the namespace is set to "rails:generators:webrat", but Rails allows it
+ # to be invoked simply as "rails:webrat". The "generators" is added
+ # automatically when doing the lookup;
+ #
+ # 3) Rails looks in load paths and loads the generator just before it's going to be used.
#
# ==== Examples
#
@@ -164,30 +179,29 @@ module Rails
#
# "rails:generators:webrat", "webrat:generators:integration", "webrat"
#
- # If the namespace has ":" included we consider that a absolute namespace
- # was given and the lookup above does not happen. Just the name is searched.
+ # On the other hand, if "rails:webrat" is given, it will search for:
#
- # Finally, it deals with one kind of shortcut:
+ # "rails:generators:webrat", "rails:webrat"
#
- # find_by_namespace "test_unit:model"
- #
- # It will search for generators at:
- #
- # "test_unit:generators:model", "test_unit:model"
+ # Notice that the "generators" namespace is handled automatically by Rails,
+ # so you don't need to type it when you want to invoke a generator in specific.
#
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
- name, attempts = name.to_s, []
+ name, attempts = name.to_s, [ ]
case name.count(':')
when 1
base, name = name.split(':')
return find_by_namespace(name, base)
when 0
- attempts << "#{base}:generators:#{name}" if base
- attempts << "#{name}:generators:#{context}" if context
+ attempts += generator_names(base, name) if base
+ attempts += generator_names(name, context) if context
end
attempts << name
+ attempts += generator_names(name, name) unless name.include?(?:)
+ attempts.uniq!
+
unloaded = attempts - namespaces
lookup(unloaded)
@@ -233,7 +247,10 @@ module Rails
until tail.empty?
others += Dir[File.join(path, *tail)].collect do |file|
- file.split('/')[-tail.size, 2].join(':').sub(/_generator\.rb$/, '')
+ name = file.split('/')[-tail.size, 2]
+ name.last.sub!(/_generator\.rb$/, '')
+ name.uniq!
+ name.join(':')
end
tail.shift
end
@@ -248,7 +265,7 @@ module Rails
# Return all defined namespaces.
#
def self.namespaces #:nodoc:
- Thor::Base.subclasses.map{ |klass| klass.namespace }
+ Thor::Base.subclasses.map { |klass| klass.namespace }
end
# Keep builtin generators in an Array[Array[group, name]].
@@ -259,6 +276,12 @@ module Rails
end
end
+ # By default, Rails strips the generator namespace to make invocations
+ # easier. This method generaters the both possibilities names.
+ def self.generator_names(first, second)
+ [ "#{first}:generators:#{second}", "#{first}:#{second}" ]
+ end
+
# Try callbacks for the given base.
#
def self.invoke_fallbacks_for(name, base)
@@ -287,6 +310,9 @@ module Rails
Dir[File.join(path, '**', attempts)].each do |file|
begin
require file
+ rescue NameError => e
+ raise unless e.message =~ /Rails::Generator/
+ warn "[WARNING] Could not load generator at #{file.inspect} because it's a Rails 2.x generator, which is not supported anymore"
rescue Exception => e
warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index c4552dd399..8677bf283b 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -1,4 +1,5 @@
require 'open-uri'
+require 'active_support/deprecation'
module Rails
module Generators
@@ -45,19 +46,56 @@ module Rails
#
# gem "rspec", :env => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
+ # gem "rails", "3.0", :git => "git://github.com/rails/rails"
#
- def gem(name, options={})
- log :gem, name
- env = options.delete(:env)
+ def gem(*args)
+ options = args.extract_options!
+ name, version = args
- gems_code = "config.gem '#{name}'"
+ # Deal with deprecated options
+ { :env => :only, :lib => :require_as }.each do |old, new|
+ next unless options[old]
+ options[new] = options.delete(old)
+ ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead"
+ end
+
+ # Deal with deprecated source
+ if source = options.delete(:source)
+ ActiveSupport::Deprecation.warn ":source option in gem is deprecated, use add_source method instead"
+ add_source(source)
+ end
+
+ # Set the message to be shown in logs. Uses the git repo if one is given,
+ # otherwise use name (version).
+ parts, message = [ name.inspect ], name
+ if version ||= options.delete(:version)
+ parts << version
+ message << " (#{version})"
+ end
+ message = options[:git] if options[:git]
+
+ log :gemfile, message
+
+ options.each do |option, value|
+ parts << ":#{option} => #{value.inspect}"
+ end
- if options.any?
- opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
- gems_code << ", #{opts}"
+ in_root do
+ append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false
end
+ end
+
+ # Add the given source to Gemfile
+ #
+ # ==== Example
+ #
+ # source "http://gems.github.com/"
+ def add_source(source, options={})
+ log :source, source
- environment gems_code, :env => env
+ in_root do
+ prepend_file "Gemfile", "source #{source.inspect}", :verbose => false
+ end
end
# Adds a line inside the Initializer block for config/environment.rb.
@@ -71,7 +109,7 @@ module Rails
in_root do
if options[:env].nil?
- inject_into_file 'config/environment.rb', "\n #{data}", :after => sentinel, :verbose => false
+ inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
else
Array.wrap(options[:env]).each do|env|
append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
@@ -79,6 +117,7 @@ module Rails
end
end
end
+ alias :application :environment
# Run a command in git.
#
@@ -222,9 +261,8 @@ module Rails
#
# freeze!
#
- def freeze!(args = {})
- log :vendor, "rails"
- in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) }
+ def freeze!(args={})
+ ActiveSupport::Deprecation.warn "freeze! is deprecated since your rails app now comes bundled with Rails by default, please check your Gemfile"
end
# Make an entry in Rails routing file conifg/routes.rb
@@ -251,6 +289,7 @@ module Rails
if args.size == 1
say args.first.to_s
else
+ args << (self.behavior == :invoke ? :green : :red)
say_status *args
end
end
diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb
index 1a849a0e02..fe6321af30 100644
--- a/railties/lib/rails/generators/active_model.rb
+++ b/railties/lib/rails/generators/active_model.rb
@@ -32,7 +32,7 @@ module Rails
# GET index
def self.all(klass)
- raise NotImplementedError
+ "#{klass}.all"
end
# GET show
@@ -40,34 +40,38 @@ module Rails
# PUT update
# DELETE destroy
def self.find(klass, params=nil)
- raise NotImplementedError
+ "#{klass}.find(#{params})"
end
# GET new
# POST create
def self.build(klass, params=nil)
- raise NotImplementedError
+ if params
+ "#{klass}.new(#{params})"
+ else
+ "#{klass}.new"
+ end
end
# POST create
def save
- raise NotImplementedError
+ "#{name}.save"
end
# PUT update
def update_attributes(params=nil)
- raise NotImplementedError
+ "#{name}.update_attributes(#{params})"
end
# POST create
# PUT update
def errors
- raise NotImplementedError
+ "#{name}.errors"
end
# DELETE destroy
def destroy
- raise NotImplementedError
+ "#{name}.destroy"
end
end
end
diff --git a/railties/lib/rails/generators/active_record.rb b/railties/lib/rails/generators/active_record.rb
index c03ea59c1b..c62f75c384 100644
--- a/railties/lib/rails/generators/active_record.rb
+++ b/railties/lib/rails/generators/active_record.rb
@@ -1,6 +1,7 @@
require 'rails/generators/named_base'
require 'rails/generators/migration'
require 'rails/generators/active_model'
+require 'active_record'
module ActiveRecord
module Generators
@@ -18,39 +19,5 @@ module ActiveRecord
end
end
end
-
- class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
- def self.all(klass)
- "#{klass}.all"
- end
-
- def self.find(klass, params=nil)
- "#{klass}.find(#{params})"
- end
-
- def self.build(klass, params=nil)
- if params
- "#{klass}.new(#{params})"
- else
- "#{klass}.new"
- end
- end
-
- def save
- "#{name}.save"
- end
-
- def update_attributes(params=nil)
- "#{name}.update_attributes(#{params})"
- end
-
- def errors
- "#{name}.errors"
- end
-
- def destroy
- "#{name}.destroy"
- end
- end
end
end
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 720caa5b3f..226ae63963 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -12,11 +12,24 @@ module Rails
add_runtime_options!
+ # Always move to rails source root.
+ #
+ def initialize(*args) #:nodoc:
+ if !invoked?(args) && defined?(Rails.root) && Rails.root
+ self.destination_root = Rails.root
+ FileUtils.cd(destination_root)
+ end
+ super
+ end
+
# 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
@@ -201,10 +214,13 @@ module Rails
#
def self.inherited(base) #:nodoc:
super
- base.source_root # Cache source root
- if defined?(RAILS_ROOT) && base.name !~ /Base$/
- path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates'))
+ # 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)
else
@@ -247,6 +263,13 @@ module Rails
end
end
+ # Check if this generator was invoked from another one by inspecting
+ # parameters.
+ #
+ def invoked?(args)
+ args.last.is_a?(Hash) && args.last.key?(:invocations)
+ end
+
# Use Rails default banner.
#
def self.banner
@@ -256,17 +279,24 @@ module Rails
# Sets the base_name taking into account the current class namespace.
#
def self.base_name
- @base_name ||= self.name.split('::').first.underscore
+ @base_name ||= begin
+ if base = name.to_s.split('::').first
+ base.underscore
+ end
+ end
end
# Removes the namespaces and get the generator name. For example,
# Rails::Generators::MetalGenerator will return "metal" as generator name.
#
def self.generator_name
- @generator_name ||= begin
- klass_name = self.name.split('::').last
- klass_name.sub!(/Generator$/, '')
- klass_name.underscore
+ if name
+ @generator_name ||= begin
+ if klass_name = name.to_s.split('::').last
+ klass_name.sub!(/Generator$/, '')
+ klass_name.underscore
+ end
+ end
end
end
@@ -274,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/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 0e5976f915..1d4f52286e 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -11,7 +11,10 @@ module Rails
alias :file_name :singular_name
- def initialize(*args) #:nodoc:
+ def initialize(args, *options) #:nodoc:
+ # Unfreeze name in case it's given as a frozen string
+ args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
+
super
assign_names!(self.name)
parse_attributes! if respond_to?(:attributes)
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 78b4b057ae..2bcea4bc8f 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -1,4 +1,4 @@
-require 'digest/md5'
+require 'digest/md5'
require 'active_support/secure_random'
require 'rails/version' unless defined?(Rails::VERSION)
@@ -12,9 +12,6 @@ module Rails::Generators
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
- class_option :freeze, :type => :boolean, :aliases => "-F", :default => false,
- :desc => "Freeze Rails in vendor/rails from the gems"
-
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an application template (can be a filesystem path or URL)."
@@ -54,6 +51,7 @@ module Rails::Generators
copy_file "Rakefile"
copy_file "README"
copy_file "config.ru"
+ template "Gemfile"
end
def create_app_files
@@ -65,6 +63,7 @@ module Rails::Generators
inside "config" do
copy_file "routes.rb"
+ template "application.rb"
template "environment.rb"
directory "environments"
@@ -124,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
@@ -153,10 +154,6 @@ module Rails::Generators
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
end
- def freeze?
- freeze! if options[:freeze]
- end
-
protected
attr_accessor :rails_template
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
new file mode 100644
index 0000000000..8e851a64e7
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -0,0 +1,18 @@
+# Edit this Gemfile to bundle your application's dependencies.
+
+gem "rails", "<%= Rails::VERSION::STRING %>"
+
+## Bundle edge rails:
+# gem "rails", :git => "git://github.com/rails/rails.git"
+
+## Bundle the gems you use:
+# gem "bj"
+# gem "hpricot", "0.6"
+# gem "sqlite3-ruby", :require_as => "sqlite3"
+# gem "aws-s3", :require_as => "aws/s3"
+
+## Bundle gems used only in certain environments:
+# gem "rspec", :only => :test
+# only :test do
+# gem "webrat"
+# end
diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile
index bd4dec5389..6b6d07e8cc 100755
--- a/railties/lib/rails/generators/rails/app/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/app/templates/Rakefile
@@ -1,7 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru b/railties/lib/rails/generators/rails/app/templates/config.ru
index 50ee033d44..509a0da5b7 100644
--- a/railties/lib/rails/generators/rails/app/templates/config.ru
+++ b/railties/lib/rails/generators/rails/app/templates/config.ru
@@ -1,5 +1,5 @@
# Require your environment file to bootstrap Rails
-require ::File.dirname(__FILE__) + '/config/environment'
+require ::File.expand_path('../config/environment', __FILE__)
# Dispatch the request
-run Rails.application.new
+run Rails.application
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
new file mode 100644
index 0000000000..8008c6ba07
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -0,0 +1,41 @@
+require File.expand_path('../boot', __FILE__)
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{root}/extras )
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Skip frameworks you're not going to use. To use Rails without a database,
+ # you must remove the Active Record framework.
+<% if options[:skip_activerecord] -%>
+ config.frameworks -= [ :active_record ]
+<% else -%>
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+<% end -%>
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names.
+ config.time_zone = 'UTC'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+ # config.i18n.default_locale = :de
+
+ # Configure generators values. Many other options are available, be sure to
+ # check the documentation.
+ # config.generators do |g|
+ # g.orm :active_record
+ # g.template_engine :erb
+ # g.test_framework :test_unit, :fixture => true
+ # end
+end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
index 6e0e2279cd..5aa49ca5e6 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,148 +1,16 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- # Mark the version of Rails that generated the boot.rb file. This is
- # a temporary solution and will most likely be removed as Rails 3.0
- # comes closer.
- BOOTSTRAP_VERSION = "3.0"
-
- class << self
- def boot!
- unless booted?
- preinitialize
- pick_boot.run
- end
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
-
- def preinitialize
- load(preinitializer_path) if File.exist?(preinitializer_path)
- end
-
- def preinitializer_path
- "#{RAILS_ROOT}/config/preinitializer.rb"
- end
- end
-
- class Boot
- def run
- set_load_paths
- load_initializer
- end
-
- def set_load_paths
- %w(
- actionmailer/lib
- actionpack/lib
- activemodel/lib
- activerecord/lib
- activeresource/lib
- activesupport/lib
- railties/lib
- railties
- ).reverse_each do |path|
- path = "#{framework_root_path}/#{path}"
- $LOAD_PATH.unshift(path) if File.directory?(path)
- $LOAD_PATH.uniq!
- end
- end
-
- def framework_root_path
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{RAILS_ROOT}/vendor/rails"
- end
+# Use Bundler (preferred)
+environment = File.expand_path('../../vendor/gems/environment', __FILE__)
+if File.exist?("#{environment}.rb")
+ require environment
+
+# Use 2.x style vendor/rails and RubyGems
+else
+ vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
+ if File.exist?(vendor_rails)
+ Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
end
- class VendorBoot < Boot
- def load_initializer
- require "rails"
- install_gem_spec_stubs
- Rails::GemDependency.add_frozen_gem_path
- end
-
- def install_gem_spec_stubs
- begin; require "rubygems"; rescue LoadError; return; end
-
- %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub|
- Gem.loaded_specs[stub] ||= Gem::Specification.new do |s|
- s.name = stub
- s.version = Rails::VERSION::STRING
- s.loaded_from = ""
- end
- end
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'rails'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', version
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion rescue nil
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- min_version = '1.3.2'
- require 'rubygems'
- unless rubygems_version >= min_version
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
+ require 'rubygems'
end
-# All that for this:
-Rails.boot!
+require 'rails'
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
index adb3a3060a..0bb191f205 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
@@ -1,53 +1,5 @@
-# Be sure to restart your server when you modify this file
+# Load the rails application
+require File.expand_path('../application', __FILE__)
-# Specifies gem version of Rails to use when vendor/rails is not present
-<%= '# ' if options[:freeze] %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>' unless defined? RAILS_GEM_VERSION
-
-# Bootstrap the Rails environment, frameworks, and default configuration
-require File.join(File.dirname(__FILE__), 'boot')
-
-Rails::Initializer.run do |config|
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
-
- # Specify gems that this application depends on and have them installed with rake gems:install
- # config.gem "bj"
- # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
- # config.gem "sqlite3-ruby", :lib => "sqlite3"
- # config.gem "aws-s3", :lib => "aws/s3"
-
- # Only load the plugins named here, in the order given (default is alphabetical).
- # :all can be used as a placeholder for all plugins not explicitly named
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Skip frameworks you're not going to use. To use Rails without a database,
- # you must remove the Active Record framework.
-<% if options[:skip_activerecord] -%>
- config.frameworks -= [ :active_record ]
-<% else -%>
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
-
- # Activate observers that should always be running
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-<% end -%>
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names.
- config.time_zone = 'UTC'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
- # config.i18n.default_locale = :de
-
- # Configure generators values. Many other options are available, be sure to
- # check the documentation.
- # config.generators do |g|
- # g.orm :active_record
- # g.template_engine :erb
- # g.test_framework :test_unit, :fixture => true
- # end
-end
+# Initialize the rails application
+Rails.initialize!
diff --git a/railties/lib/rails/generators/rails/app/templates/script/about.tt b/railties/lib/rails/generators/rails/app/templates/script/about
index 1220676c08..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/boot', __FILE__)
+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 b/railties/lib/rails/generators/rails/app/templates/script/console
new file mode 100755
index 0000000000..20aa799d2f
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/console
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/console'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/console.tt b/railties/lib/rails/generators/rails/app/templates/script/console.tt
deleted file mode 100755
index 5aec193853..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/console.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/console'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/dbconsole b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
new file mode 100755
index 0000000000..e6a1c59394
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/dbconsole'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
deleted file mode 100755
index 632563f470..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/dbconsole'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy b/railties/lib/rails/generators/rails/app/templates/script/destroy
new file mode 100755
index 0000000000..adfa8e8426
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/destroy
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/destroy'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt b/railties/lib/rails/generators/rails/app/templates/script/destroy.tt
deleted file mode 100755
index c5f94862c3..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/destroy'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate b/railties/lib/rails/generators/rails/app/templates/script/generate
new file mode 100755
index 0000000000..6fb8ad0395
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/generate
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/generate'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate.tt
deleted file mode 100755
index d466c94767..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/generate'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
new file mode 100755
index 0000000000..9647d8f10a
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
@@ -0,0 +1,2 @@
+require File.expand_path('../../../config/environment', __FILE__)
+require 'rails/commands/performance/benchmarker'
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.tt
deleted file mode 100755
index 3e03aaa767..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../../config/boot', __FILE__)
-require 'rails/commands/performance/benchmarker'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
new file mode 100755
index 0000000000..a5822042d2
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
@@ -0,0 +1,2 @@
+require File.expand_path('../../../config/environment', __FILE__)
+require 'rails/commands/performance/profiler'
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.tt
deleted file mode 100755
index deada2f561..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../../config/boot', __FILE__)
-require 'rails/commands/performance/profiler'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/plugin b/railties/lib/rails/generators/rails/app/templates/script/plugin
new file mode 100755
index 0000000000..1f1af6c880
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/plugin
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/plugin'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt b/railties/lib/rails/generators/rails/app/templates/script/plugin.tt
deleted file mode 100755
index f4081f56b6..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/plugin'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner b/railties/lib/rails/generators/rails/app/templates/script/runner
new file mode 100755
index 0000000000..7a70828e90
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/runner
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner.tt b/railties/lib/rails/generators/rails/app/templates/script/runner.tt
deleted file mode 100755
index 60c8c0bba1..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/runner.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/server b/railties/lib/rails/generators/rails/app/templates/script/server
new file mode 100755
index 0000000000..a7aaee2953
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/server
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/server'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/server.tt b/railties/lib/rails/generators/rails/app/templates/script/server.tt
deleted file mode 100755
index 54e3346bec..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/server.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __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/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index d4b0d4b945..99954e2292 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -1,9 +1,13 @@
+require 'rails/generators/active_model'
+
module Rails
module Generators
# Deal with controller names on scaffold and add some helpers to deal with
# ActiveModel.
#
module ResourceHelpers
+ mattr_accessor :skip_warn
+
def self.included(base) #:nodoc:
base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name,
:controller_class_path, :controller_file_path
@@ -17,7 +21,11 @@ module Rails
super
if name == name.pluralize && !options[:force_plural]
- say "Plural version of the model detected, using singularized version. Override with --force-plural."
+ unless ResourceHelpers.skip_warn
+ say "Plural version of the model detected, using singularized version. Override with --force-plural."
+ ResourceHelpers.skip_warn = true
+ end
+
name.replace name.singularize
assign_names!(self.name)
end
@@ -47,20 +55,11 @@ module Rails
raise "You need to have :orm as class option to invoke orm_class and orm_instance"
end
- active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
-
- # If the orm was not loaded, try to load it at "generators/orm",
- # for example "generators/active_record" or "generators/sequel".
begin
- klass = active_model.constantize
- rescue NameError
- require "rails/generators/#{options[:orm]}"
+ "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize
+ rescue NameError => e
+ Rails::Generators::ActiveModel
end
-
- # Try once again after loading the file with success.
- klass ||= active_model.constantize
- rescue Exception => e
- raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}."
end
end
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 4bd5088207..3866b856b2 100644
--- a/railties/lib/rails/initializable.rb
+++ b/railties/lib/rails/initializable.rb
@@ -1,85 +1,117 @@
module Rails
module Initializable
+ def self.included(base)
+ base.extend ClassMethods
+ end
- # A collection of initializers
- class Collection
- def initialize(context)
- @context = context
- @keys = []
- @values = {}
- @ran = false
- end
+ class Initializer
+ attr_reader :name, :before, :after, :global, :block
- def run
- return self if @ran
- each do |key, initializer|
- @context.class_eval(&initializer.block)
- end
- @ran = true
- self
+ def initialize(name, context, options, &block)
+ @name, @context, @options, @block = name, context, options, block
end
- def [](key)
- keys, values = merge_with_parent
- values[key.to_sym]
+ def before
+ @options[:before]
end
- def []=(key, value)
- key = key.to_sym
- @keys |= [key]
- @values[key] = value
+ def after
+ @options[:after]
end
- def each
- keys, values = merge_with_parent
- keys.each { |k| yield k, values[k] }
- self
+ def global
+ @options[:global]
end
- protected
-
- attr_reader :keys, :values
+ alias global? global
- private
+ def run(*args)
+ @context.instance_exec(*args, &block)
+ end
- def merge_with_parent
- keys, values = [], {}
+ def bind(context)
+ return self if @context
+ Initializer.new(@name, context, @options, &block)
+ end
+ end
- if @context.is_a?(Class) && @context.superclass.is_a?(Initializable)
- parent = @context.superclass.initializers
- keys, values = parent.keys, parent.values
+ class Collection < Array
+ def initialize(initializers = [])
+ super()
+ initializers.each do |initializer|
+ if initializer.before
+ index = index_for(initializer.before)
+ elsif initializer.after
+ index = index_for(initializer.after)
+ index += 1 if index
+ else
+ index = length
+ end
+ insert(index || -1, initializer)
end
-
- values = values.merge(@values)
- return keys | @keys, values
end
- end
-
- class Initializer
- attr_reader :name, :options, :block
+ def +(other)
+ Collection.new(to_a + other.to_a)
+ end
- def initialize(name, options = {}, &block)
- @name, @options, @block = name, options, block
+ def index_for(name)
+ initializer = find { |i| i.name == name }
+ initializer && index(initializer)
end
end
- def initializer(name, options = {}, &block)
- @initializers ||= Collection.new(self)
- @initializers[name] = Initializer.new(name, options, &block)
+ def run_initializers(*args)
+ return if @ran
+ initializers.each do |initializer|
+ initializer.run(*args)
+ end
+ @ran = true
end
def initializers
- @initializers ||= Collection.new(self)
+ @initializers ||= begin
+ initializers = self.class.initializers_for(:instance)
+ Collection.new(initializers.map { |i| i.bind(self) })
+ end
end
+ module ClassMethods
+ def initializers
+ @initializers ||= []
+ end
+
+ def initializers_for(scope = :global)
+ initializers = Collection.new
+ ancestors.reverse_each do |klass|
+ next unless klass.respond_to?(:initializers)
+ initializers = initializers + klass.initializers.select { |i|
+ (scope == :global) == !!i.global?
+ }
+ end
+ initializers
+ end
+
+ def initializer(name, opts = {}, &blk)
+ @initializers ||= []
+ @initializers << Initializer.new(name, nil, opts, &blk)
+ end
+
+ def run_initializers(*args)
+ return if @ran
+ initializers_for(:global).each do |initializer|
+ instance_exec(*args, &initializer.block)
+ end
+ @ran = true
+ end
+ end
end
- extend Initializable
+ include Initializable
# Check for valid Ruby version (1.8.2 or 1.8.4 or higher). This is done in an
# external file, so we can use it from the `rails` program as well without duplication.
- initializer :check_ruby_version do
+ initializer :check_ruby_version, :global => true do
require 'rails/ruby_version_check'
end
@@ -89,7 +121,7 @@ module Rails
# on ActionController::Base.
#
# For Ruby 1.9, UTF-8 is the default internal and external encoding.
- initializer :initialize_encoding do
+ initializer :initialize_encoding, :global => true do
if RUBY_VERSION < '1.9'
$KCODE='u'
else
diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb
index f7c3774450..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/gem_dependency'
-require 'rails/rack'
-require 'rails/paths'
-require 'rails/core'
-require 'rails/configuration'
+require "rails" # In case people require this file directly
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -21,8 +11,7 @@ module Rails
else
Rails.application = Class.new(Application)
yield Rails.application.config if block_given?
- Rails.application.new
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 3899b744b0..b3d105d8c7 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -19,14 +19,14 @@ module Rails
class Root
include PathParent
- attr_reader :path
+ attr_accessor :path
+
def initialize(path)
- raise unless path.is_a?(String)
+ raise if path.is_a?(Array)
@children = {}
- # TODO: Move logic from set_root_path initializer
- @path = File.expand_path(path)
+ @path = path
@root = self
@all_paths = []
end
@@ -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
@@ -123,8 +127,10 @@ module Rails
end
def paths
+ raise "You need to set a path root" unless @root.path
+
@paths.map do |path|
- path.index('/') == 0 ? path : File.join(@root.path, path)
+ path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path))
end
end
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 1c0af6411a..86bf032641 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,180 +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
-
- 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
-
+ include Initializable
+
+ 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
- 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
- {}
+ plugins.sort_by do |p|
+ [list.index(p.name) || list.index(:all), p.name.to_s]
+ end
end
- def report_nonexistant_or_empty_plugin!
- raise LoadError, "Can not find the plugin named: #{name}"
- end
+ attr_reader :name, :path
-
- 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')
+ def initialize(path)
+ @name = File.basename(path).to_sym
+ @path = path
end
- def classic_init_path
- File.join(directory, 'init.rb')
+ def load_paths
+ Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
end
- def gem_init_path
- File.join(directory, 'rails', 'init.rb')
- 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 init_path
- File.file?(gem_init_path) ? gem_init_path : classic_init_path
- end
+ ActiveSupport::Dependencies.load_paths << path
-
- def has_app_directory?
- File.directory?(File.join(directory, 'app'))
+ unless app.config.reload_plugins
+ ActiveSupport::Dependencies.load_once_paths << path
+ end
+ end
end
- def has_lib_directory?
- File.directory?(lib_path)
+ 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
- def has_init_file?
- File.file?(init_path)
+ 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 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
-
- eval(IO.read(init_path), binding, init_path)
- end
+ 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
-
- # 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
-
- def init_path
- File.join(directory, 'rails', 'init.rb')
+ 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 0d16cbd7c3..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 1057c004e0..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 = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem }
- 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/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb
index 68d3acc876..62d7804bf3 100644
--- a/railties/lib/rails/ruby_version_check.rb
+++ b/railties/lib/rails/ruby_version_check.rb
@@ -1,13 +1,6 @@
-min_release = "1.8.2 (2004-12-25)"
+min_release = "1.8.7"
ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
-if ruby_release =~ /1\.8\.3/
- abort <<-end_message
-
- Rails does not work with Ruby version 1.8.3.
- Please upgrade to version 1.8.4 or downgrade to 1.8.2.
-
- end_message
-elsif ruby_release < min_release
+if ruby_release < min_release
abort <<-end_message
Rails requires Ruby version #{min_release} or later.
diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb
index aad965306c..82113a297c 100644
--- a/railties/lib/rails/tasks.rb
+++ b/railties/lib/rails/tasks.rb
@@ -6,7 +6,6 @@ $VERBOSE = nil
databases
documentation
framework
- gems
log
middleware
misc
@@ -20,5 +19,5 @@ end
# Load any custom rakefile extensions
# TODO: Don't hardcode these paths.
-Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
-Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
diff --git a/railties/lib/rails/tasks/databases.rake b/railties/lib/rails/tasks/databases.rake
index ed015e7a67..a35a6c156b 100644
--- a/railties/lib/rails/tasks/databases.rake
+++ b/railties/lib/rails/tasks/databases.rake
@@ -283,7 +283,7 @@ namespace :db do
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
task :dump => :environment do
require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
+ File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
Rake::Task["db:schema:dump"].reenable
@@ -291,11 +291,11 @@ namespace :db do
desc "Load a schema.rb file into the database"
task :load => :environment do
- file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
+ file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
if File.exists?(file)
load(file)
else
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
end
end
end
@@ -307,7 +307,7 @@ namespace :db do
case abcs[RAILS_ENV]["adapter"]
when "mysql", "oci", "oracle"
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
when "postgresql"
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
@@ -327,13 +327,13 @@ namespace :db do
when "firebird"
set_firebird_env(abcs[RAILS_ENV])
db_string = firebird_db_string(abcs[RAILS_ENV])
- sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql"
+ sh "isql -a #{db_string} > #{Rails.root}/db/#{RAILS_ENV}_structure.sql"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
if ActiveRecord::Base.connection.supports_migrations?
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
end
end
@@ -356,28 +356,28 @@ namespace :db do
when "mysql"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
when "postgresql"
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
- `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
+ `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
when "sqlite", "sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
- `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql`
+ `#{abcs["test"]["adapter"]} #{dbfile} < #{Rails.root}/db/#{RAILS_ENV}_structure.sql`
when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when "firebird"
set_firebird_env(abcs["test"])
db_string = firebird_db_string(abcs["test"])
- sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
+ sh "isql -i #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{db_string}"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
@@ -446,7 +446,7 @@ def drop_database(config)
when /^sqlite/
require 'pathname'
path = Pathname.new(config['database'])
- file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path)
+ file = path.absolute? ? path.to_s : File.join(Rails.root, path)
FileUtils.rm(file)
when 'postgresql'
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 16dd0af44e..1611d1d94d 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -86,7 +86,7 @@ namespace :rails do
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
require 'generators'
- generator = Rails::Generators::App.new [ RAILS_ROOT ], {}, :destination_root => RAILS_ROOT
+ generator = Rails::Generators::App.new [ Rails.root ], {}, :destination_root => Rails.root
generator.apply template, :verbose => false
end
@@ -96,15 +96,10 @@ namespace :rails do
require 'rails/generators/rails/app/app_generator'
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
- :destination_root => RAILS_ROOT
+ :destination_root => Rails.root
generator.invoke(method)
end
- desc "Update config/boot.rb from your current rails install"
- task :configs do
- invoke_from_app_generator :create_boot_file
- end
-
desc "Update Prototype javascripts from your current rails install"
task :javascripts do
invoke_from_app_generator :create_prototype_files
@@ -117,8 +112,8 @@ namespace :rails do
desc "Rename application.rb to application_controller.rb"
task :application_controller do
- old_style = RAILS_ROOT + '/app/controllers/application.rb'
- new_style = RAILS_ROOT + '/app/controllers/application_controller.rb'
+ old_style = Rails.root + '/app/controllers/application.rb'
+ new_style = Rails.root + '/app/controllers/application_controller.rb'
if File.exists?(old_style) && !File.exists?(new_style)
FileUtils.mv(old_style, new_style)
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
diff --git a/railties/lib/rails/tasks/gems.rake b/railties/lib/rails/tasks/gems.rake
deleted file mode 100644
index f1c34c7cca..0000000000
--- a/railties/lib/rails/tasks/gems.rake
+++ /dev/null
@@ -1,78 +0,0 @@
-desc "List the gems that this rails application depends on"
-task :gems => 'gems:base' do
- Rails.configuration.gems.each do |gem|
- print_gem_status(gem)
- end
- puts
- puts "I = Installed"
- puts "F = Frozen"
- puts "R = Framework (loaded before rails starts)"
-end
-
-namespace :gems do
- task :base do
- $gems_rake_task = true
- require 'rubygems'
- require 'rubygems/gem_runner'
- Rake::Task[:environment].invoke
- end
-
- desc "Build any native extensions for unpacked gems"
- task :build do
- $gems_build_rake_task = true
- frozen_gems.each { |gem| gem.build }
- end
-
- namespace :build do
- desc "Force the build of all gems"
- task :force do
- $gems_build_rake_task = true
- frozen_gems.each { |gem| gem.build(:force => true) }
- end
- end
-
- desc "Installs all required gems."
- task :install => :base do
- current_gems.each { |gem| gem.install }
- end
-
- desc "Unpacks all required gems into vendor/gems."
- task :unpack => :install do
- current_gems.each { |gem| gem.unpack }
- end
-
- namespace :unpack do
- desc "Unpacks all required gems and their dependencies into vendor/gems."
- task :dependencies => :install do
- current_gems.each { |gem| gem.unpack(:recursive => true) }
- end
- end
-
- desc "Regenerate gem specifications in correct format."
- task :refresh_specs do
- frozen_gems(false).each { |gem| gem.refresh }
- end
-end
-
-def current_gems
- gems = Rails.configuration.gems
- gems = gems.select { |gem| gem.name == ENV['GEM'] } unless ENV['GEM'].blank?
- gems
-end
-
-def frozen_gems(load_specs=true)
- Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir|
- Rails::GemDependency.from_directory_name(gem_dir, load_specs)
- end
-end
-
-def print_gem_status(gem, indent=1)
- code = case
- when gem.framework_gem? then 'R'
- when gem.frozen? then 'F'
- when gem.installed? then 'I'
- else ' '
- end
- puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}"
- gem.dependencies.each { |g| print_gem_status(g, indent+1) }
-end
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
index fb2fc31dc1..7f244ebaed 100644
--- a/railties/lib/rails/tasks/misc.rake
+++ b/railties/lib/rails/tasks/misc.rake
@@ -1,7 +1,7 @@
task :default => :test
task :environment do
$rails_rake_task = true
- require(File.join(RAILS_ROOT, 'config', 'environment'))
+ require(File.join(Rails.root, 'config', 'environment'))
end
task :rails_env do
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index abbf3258c1..2395d73b2f 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -3,16 +3,13 @@ task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
- verb = route.conditions[:method].to_s.upcase
- segs = route.segments.inject("") { |str,s| str << s.to_s }
- segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
- {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
+ {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
- segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
+ path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
routes.each do |r|
- puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
end
end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
index 2dcc7bdf9d..40f8c1034a 100644
--- a/railties/lib/rails/tasks/statistics.rake
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -1,14 +1,13 @@
STATS_DIRECTORIES = [
%w(Controllers app/controllers),
- %w(Helpers app/helpers),
+ %w(Helpers app/helpers),
%w(Models app/models),
%w(Libraries lib/),
%w(APIs app/apis),
%w(Integration\ tests test/integration),
%w(Functional\ tests test/functional),
%w(Unit\ tests test/unit)
-
-].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
+].collect { |name, dir| [ name, "#{Rails.root}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 8bd4475c7b..9f6c42945f 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -17,7 +17,7 @@ if defined?(ActiveRecord)
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
- self.fixture_path = "#{RAILS_ROOT}/test/fixtures/"
+ self.fixture_path = "#{Rails.root}/test/fixtures/"
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
end
diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor b/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor
deleted file mode 100755
index 50c7410d80..0000000000
--- a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rubygems'
-require 'ruby2ruby'
-require 'parse_tree'
-if Ruby2Ruby::VERSION >= "1.2.0"
- require 'parse_tree_extensions'
-end
-require 'rake'
-
-input = ARGV[0] || 'Rakefile'
-output = ARGV[1] || 'Thorfile'
-
-$requires = []
-
-module Kernel
- def require_with_record(file)
- $requires << file if caller[1] =~ /rake2thor:/
- require_without_record file
- end
- alias_method :require_without_record, :require
- alias_method :require, :require_with_record
-end
-
-load input
-
-@private_methods = []
-
-def file_task_name(name)
- "compile_" + name.gsub('/', '_slash_').gsub('.', '_dot_').gsub(/\W/, '_')
-end
-
-def method_for_task(task)
- file_task = task.is_a?(Rake::FileTask)
- comment = task.instance_variable_get('@comment')
- prereqs = task.instance_variable_get('@prerequisites').select(&Rake::Task.method(:task_defined?))
- actions = task.instance_variable_get('@actions')
- name = task.name.gsub(/^([^:]+:)+/, '')
- name = file_task_name(name) if file_task
- meth = ''
-
- meth << "desc #{name.inspect}, #{comment.inspect}\n" if comment
- meth << "def #{name}\n"
-
- meth << prereqs.map do |pre|
- pre = pre.to_s
- pre = file_task_name(pre) if Rake::Task[pre].is_a?(Rake::FileTask)
- ' ' + pre
- end.join("\n")
-
- meth << "\n\n" unless prereqs.empty? || actions.empty?
-
- meth << actions.map do |act|
- act = act.to_ruby
- unless act.gsub!(/^proc \{ \|(\w+)\|\n/,
- " \\1 = Struct.new(:name).new(#{name.inspect}) # A crude mock Rake::Task object\n")
- act.gsub!(/^proc \{\n/, '')
- end
- act.gsub(/\n\}$/, '')
- end.join("\n")
-
- meth << "\nend"
-
- if file_task
- @private_methods << meth
- return
- end
-
- meth
-end
-
-body = Rake::Task.tasks.map(&method(:method_for_task)).compact.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
-
-unless @private_methods.empty?
- body << "\n\n private\n\n"
- body << @private_methods.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
-end
-
-requires = $requires.map { |r| "require #{r.inspect}" }.join("\n")
-
-File.open(output, 'w') { |f| f.write(<<END.lstrip) }
-#{requires}
-
-class Default < Thor
-#{body}
-end
-END
diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/thor b/railties/lib/rails/vendor/thor-0.11.6/bin/thor
deleted file mode 100755
index eaf849fb4a..0000000000
--- a/railties/lib/rails/vendor/thor-0.11.6/bin/thor
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-# -*- mode: ruby -*-
-
-require File.join(File.dirname(__FILE__), '..', 'lib', 'thor')
-require 'thor/runner'
-
-Thor::Runner.start
diff --git a/railties/lib/rails/vendor/thor-0.11.6/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.6/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.6/LICENSE b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
index 98722da459..98722da459 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/LICENSE
+++ b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
diff --git a/railties/lib/rails/vendor/thor-0.11.6/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.6/README.rdoc
+++ b/railties/lib/rails/vendor/thor-0.12.0/README.rdoc
diff --git a/railties/lib/rails/vendor/thor-0.12.0/Thorfile b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
new file mode 100644
index 0000000000..f71a1e57e2
--- /dev/null
+++ b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
@@ -0,0 +1,63 @@
+# enconding: utf-8
+
+require File.join(File.dirname(__FILE__), "lib", "thor", "version")
+require 'thor/rake_compat'
+require 'spec/rake/spectask'
+require 'rdoc/task'
+
+GEM_NAME = 'thor'
+EXTRA_RDOC_FILES = ["README.rdoc", "LICENSE", "CHANGELOG.rdoc", "VERSION", "Thorfile"]
+
+class Default < Thor
+ include Thor::RakeCompat
+
+ Spec::Rake::SpecTask.new(:spec) do |t|
+ t.libs << 'lib'
+ t.spec_opts = ['--options', "spec/spec.opts"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.libs << 'lib'
+ t.spec_opts = ['--options', "spec/spec.opts"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_dir = "rcov"
+ end
+
+ RDoc::Task.new do |rdoc|
+ rdoc.main = "README.rdoc"
+ rdoc.rdoc_dir = "rdoc"
+ rdoc.title = GEM_NAME
+ rdoc.rdoc_files.include(*EXTRA_RDOC_FILES)
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.options << '--line-numbers' << '--inline-source'
+ end
+
+ begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = GEM_NAME
+ s.version = Thor::VERSION
+ s.rubyforge_project = "textmate"
+ s.platform = Gem::Platform::RUBY
+ s.summary = "A scripting framework that replaces rake, sake and rubigen"
+ s.email = "ruby-thor@googlegroups.com"
+ s.homepage = "http://yehudakatz.com"
+ s.description = "A scripting framework that replaces rake, sake and rubigen"
+ s.authors = ['Yehuda Katz', 'José Valim']
+ s.has_rdoc = true
+ s.extra_rdoc_files = EXTRA_RDOC_FILES
+ s.require_path = 'lib'
+ s.bindir = "bin"
+ s.executables = %w( thor rake2thor )
+ s.files = s.extra_rdoc_files + Dir.glob("{bin,lib}/**/*")
+ s.files.exclude 'spec/sandbox/**/*'
+ s.test_files.exclude 'spec/sandbox/**/*'
+ end
+
+ Jeweler::RubyforgeTasks.new
+ rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+ end
+end
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
index 3b45c4e9b7..68944f140d 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
@@ -1,4 +1,3 @@
-$:.unshift File.expand_path(File.dirname(__FILE__))
require 'thor/base'
require 'thor/group'
require 'thor/actions'
diff --git a/railties/lib/rails/vendor/thor-0.11.6/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.6/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.6/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.6/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.6/lib/thor/actions/directory.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb
index be5eb822ac..467e63732a 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/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,14 +71,19 @@ 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$/
- base.empty_directory(File.dirname(file_destination), config)
+ dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
+ 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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/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.6/lib/thor/rake_compat.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
index 3ab6bb21f5..0d0757fdda 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
@@ -22,7 +22,8 @@ class Thor
def self.included(base)
# Hack. Make rakefile point to invoker, so rdoc task is generated properly.
- Rake.application.instance_variable_set(:@rakefile, caller[0].match(/(.*):\d+/)[1])
+ rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
+ Rake.application.instance_variable_set(:@rakefile, rakefile)
self.rake_classes << base
end
end
@@ -43,11 +44,9 @@ class Object #:nodoc:
description.strip!
klass.desc description, task.comment || non_namespaced_name
- klass.class_eval <<-METHOD
- def #{non_namespaced_name}(#{task.arg_names.join(', ')})
- Rake::Task[#{task.name.to_sym.inspect}].invoke(#{task.arg_names.join(', ')})
- end
- METHOD
+ klass.send :define_method, non_namespaced_name do |*args|
+ Rake::Task[task.name.to_sym].invoke(*args)
+ end
end
task
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
index 43da09b336..9dc70ea069 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
@@ -215,7 +215,7 @@ class Thor::Runner < Thor #:nodoc:
# 5. c:\ <-- no Thorfiles found!
#
def thorfiles(relevant_to=nil, skip_lookup=false)
- # Deal with deprecated thor when :namespaces: is available as constants
+ # TODO Remove this dealing with deprecated thor when :namespaces: is available as constants
save_yaml(thor_yaml) if Thor::Util.convert_constants_to_namespaces(thor_yaml)
thorfiles = []
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
index 0d3f4d5951..1dc8f0e5b4 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
@@ -1,11 +1,17 @@
+require 'rbconfig'
require 'thor/shell/color'
class Thor
module Base
- # Returns the shell used in all Thor classes. Default to color one.
+ # Returns the shell used in all Thor classes. If you are in a Unix platform
+ # it will use a colored log, otherwise it will use a basic one without color.
#
def self.shell
- @shell ||= Thor::Shell::Color
+ @shell ||= if Config::CONFIG['host_os'] =~ /mswin|mingw/
+ Thor::Shell::Basic
+ else
+ Thor::Shell::Color
+ end
end
# Sets the shell used in all Thor classes.
diff --git a/railties/lib/rails/vendor/thor-0.11.6/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.6/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.6/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.6/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.6/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.6/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.6/lib/thor/util.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
index fd820d7462..ebae0a3193 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
@@ -209,7 +209,7 @@ class Thor
# Returns the root where thor files are located, dependending on the OS.
#
def self.thor_root
- File.join(user_home, ".thor")
+ File.join(user_home, ".thor").gsub(/\\/, '/')
end
# Returns the files in the thor root. On Windows thor_root will be something
@@ -220,7 +220,7 @@ class Thor
# If we don't #gsub the \ character, Dir.glob will fail.
#
def self.thor_root_glob
- files = Dir["#{thor_root.gsub(/\\/, '/')}/*"]
+ files = Dir["#{thor_root}/*"]
files.map! do |file|
File.directory?(file) ? File.join(file, "main.thor") : file
diff --git a/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
new file mode 100644
index 0000000000..885230fac4
--- /dev/null
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
@@ -0,0 +1,3 @@
+class Thor
+ VERSION = "0.11.8".freeze
+end
diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb
deleted file mode 100644
index 5b7721f303..0000000000
--- a/railties/lib/rails/vendor_gem_source_index.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-require 'rubygems'
-require 'yaml'
-
-module Rails
-
- class VendorGemSourceIndex
- # VendorGemSourceIndex acts as a proxy for the Gem source index, allowing
- # gems to be loaded from vendor/gems. Rather than the standard gem repository format,
- # vendor/gems contains unpacked gems, with YAML specifications in .specification in
- # each gem directory.
- include Enumerable
-
- attr_reader :installed_source_index
- attr_reader :vendor_source_index
-
- @@silence_spec_warnings = false
-
- def self.silence_spec_warnings
- @@silence_spec_warnings
- end
-
- def self.silence_spec_warnings=(v)
- @@silence_spec_warnings = v
- end
-
- def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path)
- @installed_source_index = installed_index
- @vendor_dir = vendor_dir
- refresh!
- end
-
- def refresh!
- # reload the installed gems
- @installed_source_index.refresh!
- vendor_gems = {}
-
- # handle vendor Rails gems - they are identified by having loaded_from set to ""
- # we add them manually to the list, so that other gems can find them via dependencies
- Gem.loaded_specs.each do |n, s|
- next unless s.loaded_from.empty?
- vendor_gems[s.full_name] = s
- end
-
- # load specifications from vendor/gems
- Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d|
- dir_name = File.basename(d)
- dir_version = version_for_dir(dir_name)
- spec = load_specification(d)
- if spec
- if spec.full_name != dir_name
- # mismatched directory name and gem spec - produced by 2.1.0-era unpack code
- if dir_version
- # fix the spec version - this is not optimal (spec.files may be wrong)
- # but it's better than breaking apps. Complain to remind users to get correct specs.
- # use ActiveSupport::Deprecation.warn, as the logger is not set yet
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+
- " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
- spec.version = dir_version
- else
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+
- "(should be #{spec.full_name}).") unless @@silence_spec_warnings
- # continue, assume everything is OK
- end
- end
- else
- # no spec - produced by early-2008 unpack code
- # emulate old behavior, and complain.
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+
- " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
- if dir_version
- spec = Gem::Specification.new
- spec.version = dir_version
- spec.require_paths = ['lib']
- ext_path = File.join(d, 'ext')
- spec.require_paths << 'ext' if File.exist?(ext_path)
- spec.name = /^(.*)-[^-]+$/.match(dir_name)[1]
- files = ['lib']
- # set files to everything in lib/
- files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') }
- files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path
- spec.files = files
- else
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+
- " Giving up.") unless @@silence_spec_warnings
- next
- end
- end
- spec.loaded_from = File.join(d, '.specification')
- # finally, swap out full_gem_path
- # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class
- class << spec
- def full_gem_path
- path = File.join installation_path, full_name
- return path if File.directory? path
- File.join installation_path, original_name
- end
- end
- vendor_gems[File.basename(d)] = spec
- end
- @vendor_source_index = Gem::SourceIndex.new(vendor_gems)
- end
-
- def version_for_dir(d)
- matches = /-([^-]+)$/.match(d)
- Gem::Version.new(matches[1]) if matches
- end
-
- def load_specification(gem_dir)
- spec_file = File.join(gem_dir, '.specification')
- YAML.load_file(spec_file) if File.exist?(spec_file)
- end
-
- def find_name(*args)
- @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args)
- end
-
- def search(*args)
- # look for vendor gems, and then installed gems - later elements take priority
- @installed_source_index.search(*args) + @vendor_source_index.search(*args)
- end
-
- def each(&block)
- @vendor_source_index.each(&block)
- @installed_source_index.each(&block)
- end
-
- def add_spec(spec)
- @vendor_source_index.add_spec spec
- end
-
- def remove_spec(spec)
- @vendor_source_index.remove_spec spec
- end
-
- def size
- @vendor_source_index.size + @installed_source_index.size
- end
-
- end
-end
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 6c6af0b2bf..47013d7797 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -1,27 +1,27 @@
ORIG_ARGV = ARGV.dup
-require 'rubygems'
-gem 'rack', '~> 1.0.0'
-gem 'rack-test', '~> 0.5.0'
+root = File.expand_path('../../..', __FILE__)
+begin
+ require "#{root}/vendor/gems/environment"
+rescue LoadError
+ %w(activesupport activemodel activerecord actionpack actionmailer activeresource railties).each do |lib|
+ $:.unshift "#{root}/#{lib}/lib"
+ end
+end
-$:.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__) + "/../../activeresource/lib"
-$:.unshift File.dirname(__FILE__) + "/../lib"
-$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info"
+$:.unshift "#{root}/railties/builtin/rails_info"
require 'stringio'
require 'test/unit'
+require 'fileutils'
require 'active_support'
+require 'active_support/core_ext/logger'
require 'active_support/test_case'
require 'action_controller'
+require 'rails'
-if defined?(RAILS_ROOT)
- RAILS_ROOT.replace File.dirname(__FILE__)
-else
- RAILS_ROOT = File.dirname(__FILE__)
+Rails::Initializer.run do |config|
+ config.root = File.dirname(__FILE__)
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
new file mode 100644
index 0000000000..a3e1916494
--- /dev/null
+++ b/railties/test/application/configuration_test.rb
@@ -0,0 +1,48 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ class InitializerTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ end
+
+ test "the application root is set correctly" do
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new(app_path), Rails.application.root
+ end
+
+ test "the application root can be set" do
+ FileUtils.mkdir_p("#{app_path}/hello")
+ add_to_config <<-RUBY
+ config.frameworks = []
+ config.root = '#{app_path}/hello'
+ RUBY
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
+ end
+
+ test "the application root is detected as where config.ru is located" do
+ add_to_config <<-RUBY
+ config.frameworks = []
+ RUBY
+ FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
+ end
+
+ test "the application root is Dir.pwd if there is no config.ru" do
+ File.delete("#{app_path}/config.ru")
+ add_to_config <<-RUBY
+ config.frameworks = []
+ RUBY
+
+ Dir.chdir("#{app_path}/app") do
+ require "#{app_path}/config/environment"
+ assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index 0d6eb4147a..ccbcd84176 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -5,9 +5,10 @@ module ApplicationTests
include ActiveSupport::Testing::Isolation
def setup
- require "rails/generators"
build_app
boot_rails
+ require "rails"
+ require "rails/generators"
end
test "generators default values" do
@@ -22,7 +23,8 @@ module ApplicationTests
Rails::Initializer.run do |c|
c.generators.orm = :datamapper
c.generators.test_framework = :rspec
- expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } }
+ c.generators.helper = false
+ expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } }
assert_equal(expected, c.generators.options)
end
end
@@ -37,10 +39,14 @@ module ApplicationTests
test "generators aliases and options on initialization" do
Rails::Initializer.run do |c|
+ c.frameworks = []
c.generators.rails :aliases => { :test_framework => "-w" }
c.generators.orm :datamapper
c.generators.test_framework :rspec
end
+ # Initialize the application
+ Rails.initialize!
+ Rails::Generators.configure!
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
@@ -48,8 +54,12 @@ module ApplicationTests
test "generators no color on initialization" do
Rails::Initializer.run do |c|
+ c.frameworks = []
c.generators.colorize_logging = false
end
+ # Initialize the application
+ Rails.initialize!
+ Rails::Generators.configure!
assert_equal Thor::Base.shell, Thor::Shell::Basic
end
@@ -86,4 +96,4 @@ module ApplicationTests
assert Rails::Generators.options.size >= 1
end
end
-end \ No newline at end of file
+end
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index f46bf2b656..719520bf68 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -7,36 +7,42 @@ module ApplicationTests
def setup
build_app
boot_rails
+ require "rails"
end
test "initializing an application initializes rails" do
- class MyApp < Rails::Application ; end
+ Rails::Initializer.run do |config|
+ config.root = app_path
+ end
if RUBY_VERSION < '1.9'
$KCODE = ''
- MyApp.new
+ Rails.initialize!
assert_equal 'UTF8', $KCODE
else
Encoding.default_external = Encoding::US_ASCII
- MyApp.new
+ Rails.initialize!
assert_equal Encoding::UTF_8, Encoding.default_external
end
end
test "initializing an application adds the application paths to the load path" do
- class MyApp < Rails::Application ; end
+ Rails::Initializer.run do |config|
+ config.root = app_path
+ end
- MyApp.new
+ Rails.initialize!
assert $:.include?("#{app_path}/app/models")
end
test "adding an unknown framework raises an error" do
- class MyApp < Rails::Application
+ Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks << :action_foo
end
assert_raises RuntimeError do
- MyApp.new
+ Rails.initialize!
end
end
@@ -49,48 +55,40 @@ module ApplicationTests
ZOO
Rails::Initializer.run do |config|
+ config.root = app_path
config.eager_load_paths = "#{app_path}/lib"
end
+ Rails.initialize!
+
assert Zoo
end
test "load environment with global" do
app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'"
assert_nil $initialize_test_set_from_env
- Rails::Initializer.run { }
+ Rails::Initializer.run { |config| config.root = app_path }
+ Rails.initialize!
assert_equal "success", $initialize_test_set_from_env
end
test "action_controller load paths set only if action controller in use" do
assert_nothing_raised NameError do
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = []
end
+ Rails.initialize!
end
end
- test "action_pack is added to the load path if action_controller is required" do
- Rails::Initializer.run do |config|
- config.frameworks = [:action_controller]
- end
-
- assert $:.include?("#{framework_path}/actionpack/lib")
- end
-
- test "action_pack is added to the load path if action_view is required" do
- Rails::Initializer.run do |config|
- config.frameworks = [:action_view]
- end
-
- assert $:.include?("#{framework_path}/actionpack/lib")
- end
-
test "after_initialize block works correctly" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
end
+ Rails.initialize!
assert_equal "success", $test_after_initialize_block1
assert_equal "congratulations", $test_after_initialize_block2
@@ -98,10 +96,12 @@ module ApplicationTests
test "after_initialize block works correctly when no block is passed" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize # don't pass a block, this is what we're testing!
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
end
+ Rails.initialize!
assert_equal "success", $test_after_initialize_block1
assert_equal "congratulations", $test_after_initialize_block2
@@ -110,26 +110,32 @@ module ApplicationTests
# i18n
test "setting another default locale" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.i18n.default_locale = :de
end
+ Rails.initialize!
+
assert_equal :de, I18n.default_locale
end
test "no config locales dir present should return empty load path" do
FileUtils.rm_rf "#{app_path}/config/locales"
Rails::Initializer.run do |c|
+ c.root = app_path
assert_equal [], c.i18n.load_path
end
end
test "config locales dir present should be added to load path" do
Rails::Initializer.run do |c|
+ c.root = app_path
assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path
end
end
test "config defaults should be added with config settings" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.i18n.load_path << "my/other/locale.yml"
end
@@ -141,14 +147,17 @@ module ApplicationTests
# DB middleware
test "database middleware doesn't initialize when session store is not active_record" do
Rails::Initializer.run do |config|
+ config.root = app_path
config.action_controller.session_store = :cookie_store
end
+ Rails.initialize!
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
test "database middleware doesn't initialize when activerecord is not in frameworks" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks = []
end
assert_equal [], Rails.application.config.middleware
@@ -156,8 +165,10 @@ module ApplicationTests
test "database middleware initializes when session store is active record" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.action_controller.session_store = :active_record_store
end
+ Rails.initialize!
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
@@ -166,9 +177,11 @@ module ApplicationTests
test "ensure database middleware doesn't use action_controller on initializing" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks -= [:action_controller]
c.action_controller.session_store = :active_record_store
end
+ Rails.initialize!
assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
end
@@ -176,18 +189,20 @@ module ApplicationTests
# Pathview test
test "load view paths doesn't perform anything when action_view not in frameworks" do
Rails::Initializer.run do |c|
+ c.root = app_path
c.frameworks -= [:action_view]
end
+ Rails.initialize!
+
assert_equal nil, ActionMailer::Base.template_root
assert_equal [], ActionController::Base.view_paths
end
- # Rails root test
- test "Rails.root == RAILS_ROOT" do
- assert_equal RAILS_ROOT, Rails.root.to_s
- end
-
test "Rails.root should be a Pathname" do
+ Rails::Initializer.run do |c|
+ c.root = app_path
+ end
+ Rails.initialize!
assert_instance_of Pathname, Rails.root
end
end
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index 5c3d35fb16..3da51c4355 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -40,7 +40,7 @@ module ApplicationTests
test "Rails.application is available after config.ru has been racked up" do
rackup
- assert Rails.application.new < Rails::Application
+ assert Rails.application < Rails::Application
end
# Passenger still uses AC::Dispatcher, so we need to
diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb
new file mode 100644
index 0000000000..62ed4f4ad4
--- /dev/null
+++ b/railties/test/application/notifications_test.rb
@@ -0,0 +1,46 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ class NotificationsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ class MyQueue
+ attr_reader :events, :subscribers
+
+ def initialize
+ @events = []
+ @subscribers = []
+ end
+
+ def publish(name, *args)
+ @events << name
+ end
+
+ def subscribe(pattern=nil, &block)
+ @subscribers << pattern
+ end
+ end
+
+ def setup
+ build_app
+ boot_rails
+ require "rails"
+ require "active_support/notifications"
+ Rails::Initializer.run do |c|
+ c.notifications.queue = MyQueue.new
+ c.notifications.subscribe(/listening/) do
+ puts "Cool"
+ end
+ end
+ end
+
+ test "new queue is set" do
+ ActiveSupport::Notifications.instrument(:foo)
+ assert_equal :foo, ActiveSupport::Notifications.queue.events.first
+ end
+
+ test "configuration subscribers are loaded" do
+ assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ }
+ end
+ end
+end
diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb
deleted file mode 100644
index 81e7f4d88c..0000000000
--- a/railties/test/application/plugins_test.rb
+++ /dev/null
@@ -1,101 +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
- @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 { }
- 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.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.plugins = plugin_names }
- assert_plugins plugin_names, Rails.application.config.loaded_plugins
- end
-
- test "all plugins loaded after all" do
- Rails::Initializer.run do |config|
- config.plugins = [:stubby, :all, :acts_as_chunky_bacon]
- end
- 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.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- end
-
- 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.plugins = [:stubby, :acts_as_chunky_bacon, :all]
- end
-
- 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.plugins = [:stubby, :acts_as_chunky_bacon]
- end
-
- 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
- assert_raise(LoadError) do
- Rails::Initializer.run do |config|
- config.plugins = [:stubby, :acts_as_a_non_existant_plugin]
- end
- 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.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2]
- end
- 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 c3e4f970fe..6cff591b94 100644
--- a/railties/test/backtrace_cleaner_test.rb
+++ b/railties/test/backtrace_cleaner_test.rb
@@ -1,6 +1,4 @@
require 'abstract_unit'
-
-require 'rails/initializer'
require 'rails/backtrace_cleaner'
if defined? Test::Unit::Util::BacktraceFilter
@@ -18,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
@@ -31,31 +29,26 @@ else
$stderr.puts 'No BacktraceFilter for minitest'
end
-class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
- def setup
- @cleaner = Rails::BacktraceCleaner.new
- end
-
- 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
+if defined? Gem
+ class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
+ def setup
+ @cleaner = Rails::BacktraceCleaner.new
+ end
- 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" ]
+ test "should format installed gems correctly" do
+ @backtrace = [ "#{Gem.path[0]}/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
- 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]
+ 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
-
end
diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb
deleted file mode 100644
index 1280d27ffe..0000000000
--- a/railties/test/boot_test.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-require 'abstract_unit'
-require 'rails/initializer'
-require "#{File.dirname(__FILE__)}/../lib/rails/generators/rails/app/templates/config/boot"
-require 'rails/gem_dependency'
-
-class BootTest < Test::Unit::TestCase
- def test_boot_returns_if_booted
- Rails.expects(:booted?).returns(true)
- Rails.expects(:pick_boot).never
- assert_nil Rails.boot!
- end
-
- def test_boot_preinitializes_then_picks_and_runs_if_not_booted
- Rails.expects(:booted?).returns(false)
- Rails.expects(:preinitialize)
- Rails.expects(:pick_boot).returns(mock(:run => 'result'))
- assert_equal 'result', Rails.boot!
- end
-
- def test_preinitialize_does_not_raise_exception_if_preinitializer_file_does_not_exist
- Rails.stubs(:preinitializer_path).returns('/there/is/no/such/file')
-
- assert_nothing_raised { Rails.preinitialize }
- end
-
- def test_load_preinitializer_loads_preinitializer_file
- Rails.stubs(:preinitializer_path).returns("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
-
- assert_nil $initialize_test_set_from_env
- Rails.preinitialize
- assert_equal "success", $initialize_test_set_from_env
- ensure
- $initialize_test_set_from_env = nil
- end
-
- def test_boot_vendor_rails_by_default
- Rails.expects(:booted?).returns(false)
- Rails.expects(:preinitialize)
- File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(true)
- Rails::VendorBoot.any_instance.expects(:run).returns('result')
- assert_equal 'result', Rails.boot!
- end
-
- def test_boot_gem_rails_otherwise
- Rails.expects(:booted?).returns(false)
- Rails.expects(:preinitialize)
- File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(false)
- Rails::GemBoot.any_instance.expects(:run).returns('result')
- assert_equal 'result', Rails.boot!
- end
-end
-
-class VendorBootTest < Test::Unit::TestCase
- include Rails
-
- def test_load_initializer_requires_from_vendor_rails
- boot = VendorBoot.new
- boot.expects(:require).with("rails")
- boot.expects(:install_gem_spec_stubs)
- Rails::GemDependency.expects(:add_frozen_gem_path)
- boot.load_initializer
- end
-end
-
-class GemBootTest < Test::Unit::TestCase
- include Rails
-
- def test_load_initializer_loads_rubygems_and_the_rails_gem
- boot = GemBoot.new
- GemBoot.expects(:load_rubygems)
- boot.expects(:load_rails_gem)
- boot.expects(:require).with('rails')
- boot.load_initializer
- end
-
- def test_load_rubygems_exits_with_error_if_missing
- GemBoot.expects(:require).with('rubygems').raises(LoadError, 'missing rubygems')
- STDERR.expects(:puts)
- GemBoot.expects(:exit).with(1)
- GemBoot.load_rubygems
- end
-
- def test_load_rubygems_exits_with_error_if_too_old
- GemBoot.stubs(:rubygems_version).returns('0.0.1')
- GemBoot.expects(:require).with('rubygems').returns(true)
- STDERR.expects(:puts)
- GemBoot.expects(:exit).with(1)
- GemBoot.load_rubygems
- end
-
- def test_load_rails_gem_activates_specific_gem_if_version_given
- GemBoot.stubs(:gem_version).returns('0.0.1')
-
- boot = GemBoot.new
- boot.expects(:gem).with('rails', '0.0.1')
- boot.load_rails_gem
- end
-
- def test_load_rails_gem_activates_latest_gem_if_no_version_given
- GemBoot.stubs(:gem_version).returns(nil)
-
- boot = GemBoot.new
- boot.expects(:gem).with('rails')
- boot.load_rails_gem
- end
-
- def test_load_rails_gem_exits_with_error_if_missing
- GemBoot.stubs(:gem_version).returns('0.0.1')
-
- boot = GemBoot.new
- boot.expects(:gem).with('rails', '0.0.1').raises(Gem::LoadError, 'missing rails 0.0.1 gem')
- STDERR.expects(:puts)
- boot.expects(:exit).with(1)
- boot.load_rails_gem
- end
-end
-
-class ParseGemVersionTest < Test::Unit::TestCase
- def test_should_return_nil_if_no_lines_are_passed
- assert_equal nil, parse('')
- assert_equal nil, parse(nil)
- end
-
- def test_should_accept_either_single_or_double_quotes
- assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'")
- assert_equal "1.2.3", parse('RAILS_GEM_VERSION = "1.2.3"')
- end
-
- def test_should_return_nil_if_no_lines_match
- assert_equal nil, parse('nothing matches on this line\nor on this line')
- end
-
- def test_should_parse_with_no_leading_space
- assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION")
- assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'")
- end
-
- def test_should_parse_with_any_number_of_leading_spaces
- assert_equal nil, parse([])
- assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION")
- assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION")
- assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'")
- assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'")
- end
-
- def test_should_ignore_unrelated_comments
- assert_equal "1.2.3", parse("# comment\nRAILS_GEM_VERSION = '1.2.3'\n# comment")
- end
-
- def test_should_ignore_commented_version_lines
- assert_equal "1.2.3", parse("#RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'")
- assert_equal "1.2.3", parse("# RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'")
- assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'\n# RAILS_GEM_VERSION = '9.8.7'")
- end
-
- def test_should_allow_advanced_rubygems_version_specifications
- # See http://rubygems.org/read/chapter/16
- assert_equal "=1.2.3", parse("RAILS_GEM_VERSION = '=1.2.3'") # equal sign
- assert_equal "= 1.2.3", parse("RAILS_GEM_VERSION = '= 1.2.3'") # with space
- assert_equal "!=1.2.3", parse("RAILS_GEM_VERSION = '!=1.2.3'") # not equal
- assert_equal ">1.2.3", parse("RAILS_GEM_VERSION = '>1.2.3'") # greater than
- assert_equal "<1.2.3", parse("RAILS_GEM_VERSION = '<1.2.3'") # less than
- assert_equal ">=1.2.3", parse("RAILS_GEM_VERSION = '>=1.2.3'") # greater than or equal
- assert_equal "<=1.2.3", parse("RAILS_GEM_VERSION = '<=1.2.3'") # less than or equal
- assert_equal "~>1.2.3.0", parse("RAILS_GEM_VERSION = '~>1.2.3.0'") # approximately greater than
- end
-
- private
- def parse(text)
- Rails::GemBoot.parse_gem_version(text)
- end
-end
diff --git a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb b/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb
new file mode 100644
index 0000000000..d1de8c56fa
--- /dev/null
+++ b/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb
@@ -0,0 +1,4 @@
+module Foobar
+ class FoobarGenerator < Rails::Generators::Base
+ end
+end
diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
deleted file mode 100644
index 92132be992..0000000000
--- a/railties/test/gem_dependency_test.rb
+++ /dev/null
@@ -1,220 +0,0 @@
-require 'plugin_test_helper'
-require 'rails/gem_dependency'
-
-class Rails::GemDependency
- public :install_command, :unpack_command
-end
-
-Rails::VendorGemSourceIndex.silence_spec_warnings = true
-
-class GemDependencyTest < Test::Unit::TestCase
- def setup
- @gem = Rails::GemDependency.new "xhpricotx"
- @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net"
- @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6"
- @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3"
- @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false
- end
-
- def test_configuration_adds_gem_dependency
- config = Rails::Configuration.new
- config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
- assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect { |g| g.install_command }
- end
-
- def test_gem_creates_install_command
- assert_equal %w(install xhpricotx), @gem.install_command
- end
-
- def test_gem_with_source_creates_install_command
- assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
- end
-
- def test_gem_with_version_creates_install_command
- assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
- end
-
- def test_gem_creates_unpack_command
- assert_equal %w(unpack xhpricotx), @gem.unpack_command
- end
-
- def test_gem_with_version_unpack_install_command
- # stub out specification method, or else test will fail if hpricot 0.6 isn't installed
- mock_spec = mock()
- mock_spec.stubs(:version).returns('0.6')
- @gem_with_version.stubs(:specification).returns(mock_spec)
- assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command
- end
-
- def test_gem_adds_load_paths
- @gem.expects(:gem).with(@gem)
- @gem.add_load_paths
- end
-
- def test_gem_with_version_adds_load_paths
- @gem_with_version.expects(:gem).with(@gem_with_version)
- @gem_with_version.add_load_paths
- assert @gem_with_version.load_paths_added?
- end
-
- def test_gem_loading
- @gem.expects(:gem).with(@gem)
- @gem.expects(:require).with(@gem.name)
- @gem.add_load_paths
- @gem.load
- assert @gem.loaded?
- end
-
- def test_gem_with_lib_loading
- @gem_with_lib.expects(:gem).with(@gem_with_lib)
- @gem_with_lib.expects(:require).with(@gem_with_lib.lib)
- @gem_with_lib.add_load_paths
- @gem_with_lib.load
- assert @gem_with_lib.loaded?
- end
-
- def test_gem_without_lib_loading
- @gem_without_load.expects(:gem).with(@gem_without_load)
- @gem_without_load.expects(:require).with(@gem_without_load.lib).never
- @gem_without_load.add_load_paths
- @gem_without_load.load
- end
-
- def test_gem_dependencies_compare_for_uniq
- gem1 = Rails::GemDependency.new "gem1"
- gem1a = Rails::GemDependency.new "gem1"
- gem2 = Rails::GemDependency.new "gem2"
- gem2a = Rails::GemDependency.new "gem2"
- gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
- gem4 = Rails::GemDependency.new "gem3"
- gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
- assert_equal 4, gems.uniq.size
- end
-
- def test_gem_load_frozen
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_A_VERSION
- end
-
- def test_gem_load_frozen_specific_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_B_VERSION
- assert_equal '0.4.0', DUMMY_GEM_B_VERSION
- end
-
- def test_gem_load_frozen_minimum_version
- dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_C_VERSION
- assert_equal '0.6.0', DUMMY_GEM_C_VERSION
- end
-
- def test_gem_load_missing_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-d"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_D_VERSION
- assert_equal '1.0.0', DUMMY_GEM_D_VERSION
- assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files
- end
-
- def test_gem_load_bad_specification
- dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_not_nil DUMMY_GEM_E_VERSION
- assert_equal '1.0.0', DUMMY_GEM_E_VERSION
- end
-
- def test_gem_handle_missing_dependencies
- dummy_gem = Rails::GemDependency.new "dummy-gem-g"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_equal 1, dummy_gem.dependencies.size
- assert_equal 1, dummy_gem.dependencies.first.dependencies.size
- assert_nothing_raised do
- dummy_gem.dependencies.each do |g|
- g.dependencies
- end
- end
- end
-
- def test_gem_ignores_development_dependencies
- dummy_gem = Rails::GemDependency.new "dummy-gem-k"
- dummy_gem.add_load_paths
- dummy_gem.load
- assert_equal 1, dummy_gem.dependencies.size
- end
-
- def test_gem_guards_against_duplicate_unpacks
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.stubs(:frozen?).returns(true)
- dummy_gem.expects(:unpack_base).never
- dummy_gem.unpack
- end
-
- def test_gem_does_not_unpack_framework_gems
- dummy_gem = Rails::GemDependency.new "dummy-gem-a"
- dummy_gem.stubs(:framework_gem?).returns(true)
- dummy_gem.expects(:unpack_base).never
- dummy_gem.unpack
- end
-
- def test_gem_from_directory_name_attempts_to_load_specification
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1')
- end
- end
-
- def test_gem_from_directory_name
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1', false)
- assert_equal 'dummy-gem', dummy_gem.name
- assert_equal '= 1.1', dummy_gem.version_requirements.to_s
- end
-
- def test_gem_from_directory_name_loads_specification_successfully
- assert_nothing_raised do
- dummy_gem = Rails::GemDependency.from_directory_name(File.join(Rails::GemDependency.unpacked_path, 'dummy-gem-g-1.0.0'))
- assert_not_nil dummy_gem.specification
- end
- end
-
- def test_gem_from_invalid_directory_name
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem')
- end
- assert_raises RuntimeError do
- dummy_gem = Rails::GemDependency.from_directory_name('dummy')
- end
- end
-
- def test_gem_determines_build_status
- assert_equal true, Rails::GemDependency.new("dummy-gem-a").built?
- assert_equal true, Rails::GemDependency.new("dummy-gem-i").built?
- assert_equal false, Rails::GemDependency.new("dummy-gem-j").built?
- end
-
- def test_gem_determines_build_status_only_on_vendor_gems
- framework_gem = Rails::GemDependency.new('dummy-framework-gem')
- framework_gem.stubs(:framework_gem?).returns(true) # already loaded
- framework_gem.stubs(:vendor_rails?).returns(false) # but not in vendor/rails
- framework_gem.stubs(:vendor_gem?).returns(false) # and not in vendor/gems
- framework_gem.add_load_paths # freeze framework gem early
- assert framework_gem.built?
- end
-
- def test_gem_build_passes_options_to_dependencies
- start_gem = Rails::GemDependency.new("dummy-gem-g")
- dep_gem = Rails::GemDependency.new("dummy-gem-f")
- start_gem.stubs(:dependencies).returns([dep_gem])
- dep_gem.expects(:build).with({ :force => true }).once
- start_gem.build(:force => true)
- end
-
-end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index f226e184d1..7d03a37f2a 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -54,44 +54,44 @@ class ActionsTest < GeneratorsTestCase
action :plugin, 'rest_auth', {}
end
- def test_gem_should_put_gem_dependency_in_enviroment
+ def test_add_source_adds_source_to_gemfile
run_generator
- action :gem, 'will-paginate'
- assert_file 'config/environment.rb', /config\.gem 'will\-paginate'/
+ action :add_source, 'http://gems.github.com'
+ assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/
end
- def test_gem_with_options_should_include_options_in_gem_dependency_in_environment
+ def test_gem_should_put_gem_dependency_in_gemfile
run_generator
- action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'
-
- regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/
- assert_file 'config/environment.rb', regexp
+ action :gem, 'will-paginate'
+ assert_file 'Gemfile', /gem "will\-paginate"/
end
- def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment
+ def test_gem_with_options_should_include_all_options_in_gemfile
run_generator
- action :gem, 'rspec', :env => 'test'
- assert_file 'config/environments/test.rb', /config\.gem 'rspec'/
- end
- def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments
- run_generator
- action :gem, 'quietbacktrace', :env => %w[ development test ]
- assert_file 'config/environments/development.rb', /config\.gem 'quietbacktrace'/
- assert_file 'config/environments/test.rb', /config\.gem 'quietbacktrace'/
+ assert_deprecated do
+ action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'
+ end
+
+ assert_file 'Gemfile', /gem "mislav\-will\-paginate", :require_as => "will\-paginate"/
+ assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/
end
- def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly
+ def test_gem_with_env_should_include_all_dependencies_in_gemfile
run_generator
- action :gem, 'mislav-will-paginate', :lib => false
- assert_file 'config/environment.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/
+
+ assert_deprecated do
+ action :gem, 'rspec', :env => %w(development test)
+ end
+
+ assert_file 'Gemfile', /gem "rspec", :only => \["development", "test"\]/
end
def test_environment_should_include_data_in_environment_initializer_block
run_generator
- load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]'
+ load_paths = 'config.load_paths += %w["#{Rails.root}/app/extras"]'
action :environment, load_paths
- assert_file 'config/environment.rb', /#{Regexp.escape(load_paths)}/
+ assert_file 'config/application.rb', /#{Regexp.escape(load_paths)}/
end
def test_environment_with_block_should_include_block_contents_in_environment_initializer_block
@@ -102,7 +102,7 @@ class ActionsTest < GeneratorsTestCase
'# This will be added'
end
- assert_file 'config/environment.rb' do |content|
+ assert_file 'config/application.rb' do |content|
assert_match /# This will be added/, content
assert_no_match /# This wont be added/, content
end
@@ -163,9 +163,10 @@ class ActionsTest < GeneratorsTestCase
action :capify!
end
- def test_freeze_should_freeze_rails_edge
- generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false)
- action :freeze!
+ def test_freeze_is_deprecated
+ assert_deprecated do
+ action :freeze!
+ end
end
def test_route_should_add_data_to_the_routes_block_in_config_routes
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 6e46c4ddc0..10d0bc6bc2 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -65,7 +65,7 @@ class AppGeneratorTest < GeneratorsTestCase
def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given
run_generator ["--skip-activerecord"]
- assert_file "config/environment.rb", /config\.frameworks \-= \[ :active_record \]/
+ assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/
end
def test_prototype_and_test_unit_are_added_by_default
@@ -110,15 +110,8 @@ class AppGeneratorTest < GeneratorsTestCase
).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ }
end
- def test_rails_is_frozen
- generator(:freeze => true, :database => "sqlite3").expects(:run).
- with("rake rails:freeze:edge", :verbose => false)
- silence(:stdout){ generator.invoke }
- assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/
- end
-
def test_template_from_dir_pwd
- FileUtils.cd(RAILS_ROOT)
+ FileUtils.cd(Rails.root)
assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
end
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index d917812383..4ce48a453b 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -1,31 +1,27 @@
-require 'test/unit'
-require 'fileutils'
-
-fixtures = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
-if defined?(RAILS_ROOT)
- RAILS_ROOT.replace fixtures
-else
- RAILS_ROOT = fixtures
+# TODO: Fix this RAILS_ENV stuff
+RAILS_ENV = 'test' unless defined?(RAILS_ENV)
+require 'abstract_unit'
+
+module Rails
+ def self.root
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
+ end
end
+Rails.application.config.root = Rails.root
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
require 'rails/generators'
-
require 'rubygems'
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
require 'active_record'
require 'action_dispatch'
CURRENT_PATH = File.expand_path(Dir.pwd)
Rails::Generators.no_color!
-class GeneratorsTestCase < Test::Unit::TestCase
+class GeneratorsTestCase < ActiveSupport::TestCase
include FileUtils
def destination_root
- @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
- '..', 'fixtures', 'tmp'))
+ File.join(Rails.root, "tmp")
end
def setup
diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb
index dcae81c204..886af01b22 100644
--- a/railties/test/generators/resource_generator_test.rb
+++ b/railties/test/generators/resource_generator_test.rb
@@ -75,7 +75,7 @@ class ResourceGeneratorTest < GeneratorsTestCase
end
def test_plural_names_are_singularized
- content = run_generator ["accounts"]
+ content = run_generator ["accounts".freeze]
assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/
assert_file "test/unit/account_test.rb", /class AccountTest/
assert_match /Plural version of the model detected, using singularized version. Override with --force-plural./, content
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index f555725eb8..02155c295c 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -2,6 +2,11 @@ require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
+module Unknown
+ module Generators
+ end
+end
+
class ScaffoldControllerGeneratorTest < GeneratorsTestCase
def test_controller_skeleton_is_created
@@ -97,10 +102,38 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
assert_no_file "app/views/layouts/users.html.erb"
end
- def test_error_is_shown_if_orm_does_not_provide_interface
- error = capture(:stderr){ run_generator ["User", "--orm=unknown"] }
- assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " <<
- "Error: no such file to load -- rails/generators/unknown.\n", error
+ def test_default_orm_is_used
+ run_generator ["User", "--orm=unknown"]
+
+ assert_file "app/controllers/users_controller.rb" do |content|
+ assert_match /class UsersController < ApplicationController/, content
+
+ assert_instance_method content, :index do |m|
+ assert_match /@users = User\.all/, m
+ end
+ end
+ end
+
+ def test_customized_orm_is_used
+ klass = Class.new(Rails::Generators::ActiveModel) do
+ def self.all(klass)
+ "#{klass}.find(:all)"
+ end
+ end
+
+ Unknown::Generators.const_set(:ActiveModel, klass)
+ run_generator ["User", "--orm=unknown"]
+
+ assert_file "app/controllers/users_controller.rb" do |content|
+ assert_match /class UsersController < ApplicationController/, content
+
+ assert_instance_method content, :index do |m|
+ assert_match /@users = User\.find\(:all\)/, m
+ assert_no_match /@users = User\.all/, m
+ end
+ end
+ ensure
+ Unknown::Generators.send :remove_const, :ActiveModel
end
protected
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 7e6b7b183c..a8716d9992 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'generators', 'generators_test_helper')
+require 'generators/generators_test_helper'
require 'rails/generators/rails/model/model_generator'
require 'rails/generators/test_unit/model/model_generator'
require 'mocha'
@@ -45,6 +45,12 @@ class GeneratorsTest < GeneratorsTestCase
assert_equal "test_unit:generators:model", klass.namespace
end
+ def test_find_by_namespace_with_duplicated_name
+ klass = Rails::Generators.find_by_namespace(:foobar)
+ assert klass
+ assert_equal "foobar:foobar", klass.namespace
+ end
+
def test_find_by_namespace_add_generators_to_raw_lookups
klass = Rails::Generators.find_by_namespace("test_unit:model")
assert klass
@@ -80,7 +86,7 @@ class GeneratorsTest < GeneratorsTestCase
Rails::Generators.instance_variable_set(:@load_paths, nil)
spec = Gem::Specification.new
- spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec'))
+ spec.expects(:full_gem_path).returns(File.join(Rails.root, 'vendor', 'another_gem_path', 'xspec'))
Gem.expects(:respond_to?).with(:loaded_specs).returns(true)
Gem.expects(:loaded_specs).returns(:spec => spec)
@@ -101,13 +107,15 @@ class GeneratorsTest < GeneratorsTestCase
def test_rails_generators_with_others_information
output = capture(:stdout){ Rails::Generators.help }.split("\n").last
- assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts, wrong.", output
+ assert_equal "Others: active_record:fixjour, fixjour, foobar, mspec, rails:javascripts.", output
end
def test_warning_is_shown_if_generator_cant_be_loaded
+ Rails::Generators.load_paths << File.join(Rails.root, "vendor", "gems", "gems", "wrong")
output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) }
+
assert_match /\[WARNING\] Could not load generator at/, output
- assert_match /Error: uninitialized constant Rails::Generator/, output
+ assert_match /Rails 2\.x generator/, output
end
def test_no_color_sets_proper_shell
@@ -118,7 +126,7 @@ class GeneratorsTest < GeneratorsTestCase
end
def test_rails_root_templates
- template = File.join(RAILS_ROOT, "lib", "templates", "active_record", "model", "model.rb")
+ template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb")
# Create template
mkdir_p(File.dirname(template))
@@ -158,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
@@ -170,6 +175,6 @@ class GeneratorsTest < GeneratorsTestCase
def test_source_paths_for_not_namespaced_generators
mspec = Rails::Generators.find_by_namespace :mspec
- assert mspec.source_paths.include?(File.join(RAILS_ROOT, "lib", "templates", "mspec"))
+ assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "mspec"))
end
end
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index 7c8aed00c9..a9e60680ac 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -4,65 +4,196 @@ require 'rails/initializable'
module InitializableTests
class Foo
- extend Rails::Initializable
+ include Rails::Initializable
class << self
attr_accessor :foo, :bar
end
- initializer :omg do
+ initializer :omg, :global => true do
@foo ||= 0
@foo += 1
end
end
class Bar < Foo
- initializer :bar do
+ initializer :bar, :global => true do
@bar ||= 0
@bar += 1
end
end
module Word
- extend Rails::Initializable
+ include Rails::Initializable
- initializer :word do
+ initializer :word, :global => true do
$word = "bird"
end
end
+ class Parent
+ include Rails::Initializable
+
+ initializer :one, :global => true do
+ $arr << 1
+ end
+
+ initializer :two, :global => true do
+ $arr << 2
+ end
+ end
+
+ class Child < Parent
+ include Rails::Initializable
+
+ initializer :three, :before => :one, :global => true do
+ $arr << 3
+ end
+
+ initializer :four, :after => :one, :global => true do
+ $arr << 4
+ end
+ end
+
+ class Parent
+ initializer :five, :before => :one, :global => true do
+ $arr << 5
+ end
+ end
+
+ class Instance
+ include Rails::Initializable
+
+ initializer :one do
+ $arr << 1
+ end
+
+ initializer :two do
+ $arr << 2
+ end
+
+ initializer :three, :global => true do
+ $arr << 3
+ end
+
+ initializer :four, :global => true do
+ $arr << 4
+ end
+ end
+
+ class WithArgs
+ include Rails::Initializable
+
+ initializer :foo do |arg|
+ $with_arg = arg
+ end
+ end
+
+ class OverriddenInitializer
+ class MoreInitializers
+ include Rails::Initializable
+
+ initializer :startup, :before => :last do
+ $arr << 3
+ end
+
+ initializer :terminate, :after => :first do
+ $arr << two
+ end
+
+ def two
+ 2
+ end
+ end
+
+ include Rails::Initializable
+
+ initializer :first do
+ $arr << 1
+ end
+
+ initializer :last do
+ $arr << 4
+ end
+
+ def self.initializers
+ super + MoreInitializers.new.initializers
+ end
+ end
+
class Basic < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
test "initializers run" do
- Foo.initializers.run
+ Foo.run_initializers
assert_equal 1, Foo.foo
end
test "initializers are inherited" do
- Bar.initializers.run
+ Bar.run_initializers
assert_equal [1, 1], [Bar.foo, Bar.bar]
end
test "initializers only get run once" do
- Foo.initializers.run
- Foo.initializers.run
+ Foo.run_initializers
+ Foo.run_initializers
assert_equal 1, Foo.foo
end
test "running initializers on children does not effect the parent" do
- Bar.initializers.run
+ Bar.run_initializers
assert_nil Foo.foo
assert_nil Foo.bar
end
- test "inherited initializers are the same objects" do
- assert Foo.initializers[:foo].eql?(Bar.initializers[:foo])
- end
-
test "initializing with modules" do
- Word.initializers.run
+ Word.run_initializers
assert_equal "bird", $word
end
end
+
+ class BeforeAfter < ActiveSupport::TestCase
+ test "running on parent" do
+ $arr = []
+ Parent.run_initializers
+ assert_equal [5, 1, 2], $arr
+ end
+
+ test "running on child" do
+ $arr = []
+ Child.run_initializers
+ assert_equal [5, 3, 1, 4, 2], $arr
+ end
+ end
+
+ class InstanceTest < ActiveSupport::TestCase
+ test "running locals" do
+ $arr = []
+ instance = Instance.new
+ instance.run_initializers
+ assert_equal [1, 2], $arr
+ end
+
+ test "running globals" do
+ $arr = []
+ Instance.run_initializers
+ assert_equal [3, 4], $arr
+ end
+ end
+
+ class WithArgsTest < ActiveSupport::TestCase
+ test "running initializers with args" do
+ $with_arg = nil
+ WithArgs.new.run_initializers('foo')
+ assert_equal 'foo', $with_arg
+ end
+ end
+
+ class OverriddenInitializerTest < ActiveSupport::TestCase
+ test "merges in the initializers from the parent in the right order" do
+ $arr = []
+ OverriddenInitializer.new.run_initializers
+ assert_equal [1, 2, 3, 4], $arr
+ end
+ end
end \ No newline at end of file
diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb
index 1852fea4df..97d884e1be 100644
--- a/railties/test/initializer/check_ruby_version_test.rb
+++ b/railties/test/initializer/check_ruby_version_test.rb
@@ -7,30 +7,39 @@ module InitializerTests
def setup
build_app
boot_rails
+ require "rails"
end
test "rails does not initialize with ruby version 1.8.1" do
assert_rails_does_not_boot "1.8.1"
end
- test "rails initializes with ruby version 1.8.2" do
- assert_rails_boots "1.8.2"
+ test "rails does not initialize with ruby version 1.8.2" do
+ assert_rails_does_not_boot "1.8.2"
end
test "rails does not initialize with ruby version 1.8.3" do
assert_rails_does_not_boot "1.8.3"
end
- test "rails initializes with ruby version 1.8.4" do
- assert_rails_boots "1.8.4"
+ test "rails does not initialize with ruby version 1.8.4" do
+ assert_rails_does_not_boot "1.8.4"
end
- test "rails initializes with ruby version 1.8.5" do
- assert_rails_boots "1.8.5"
+ test "rails does not initializes with ruby version 1.8.5" do
+ assert_rails_does_not_boot "1.8.5"
end
- test "rails initializes with ruby version 1.8.6" do
- assert_rails_boots "1.8.6"
+ test "rails does not initialize with ruby version 1.8.6" do
+ assert_rails_does_not_boot "1.8.6"
+ end
+
+ test "rails initializes with ruby version 1.8.7" do
+ assert_rails_boots "1.8.7"
+ end
+
+ test "rails initializes with the current version of Ruby" do
+ assert_rails_boots
end
def set_ruby_version(version)
@@ -38,10 +47,11 @@ module InitializerTests
Object.const_set(:RUBY_VERSION, version.freeze)
end
- def assert_rails_boots(version)
- set_ruby_version(version)
+ def assert_rails_boots(version = nil)
+ set_ruby_version(version) if version
assert_nothing_raised "It appears that rails does not boot" do
Rails::Initializer.run { |c| c.frameworks = [] }
+ Rails.initialize!
end
end
@@ -50,6 +60,7 @@ module InitializerTests
$stderr = File.open("/dev/null", "w")
assert_raises(SystemExit) do
Rails::Initializer.run { |c| c.frameworks = [] }
+ Rails.initialize!
end
end
end
diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb
index e909688817..076816d73b 100644
--- a/railties/test/initializer/initialize_i18n_test.rb
+++ b/railties/test/initializer/initialize_i18n_test.rb
@@ -7,13 +7,16 @@ module InitializerTests
def setup
build_app
boot_rails
+ require "rails"
end
# test_config_defaults_and_settings_should_be_added_to_i18n_defaults
test "i18n config defaults and settings should be added to i18n defaults" do
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(
@@ -23,29 +26,31 @@ module InitializerTests
#{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml
#{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml
my/other/locale.yml
- ), I18n.load_path
+ ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) }
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.i18n.load_path << "my/other/locale.yml"
- end
-
- #{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
- ), I18n.load_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/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index 72ff8d88e0..1b58a58555 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -6,12 +6,15 @@ class PathsTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ require "rails"
Rails::Initializer.run do |config|
+ config.root = app_path
config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
config.after_initialize do
ActionController::Base.session_store = nil
end
end
+ Rails.initialize!
@paths = Rails.application.config.paths
end
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
deleted file mode 100644
index 80e774b7b7..0000000000
--- a/railties/test/initializer_test.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require 'abstract_unit'
-require 'rails/initializer'
-require 'rails/generators'
-
-require 'action_view'
-require 'action_mailer'
-require 'active_record'
-
-require 'plugin_test_helper'
-
-class RailsRootTest < Test::Unit::TestCase
- def test_rails_dot_root_equals_rails_root
- assert_equal RAILS_ROOT, Rails.root.to_s
- end
-
- 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
-
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index f83e0151a4..ba8b35d5cc 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -6,7 +6,6 @@
#
# It is also good to know what is the bare minimum to get
# Rails booted up.
-
require 'fileutils'
# TODO: Remove rubygems when possible
@@ -25,8 +24,10 @@ module TestHelpers
module Paths
module_function
+ TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp]))
+
def tmp_path(*args)
- File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args))
+ File.join(TMP_PATH, *args)
end
def app_path(*args)
@@ -88,10 +89,48 @@ module TestHelpers
end
end
- environment = File.read("#{app_path}/config/environment.rb")
+ 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}`
+ end
+ end
+
+ def add_to_config(str)
+ environment = File.read("#{app_path}/config/application.rb")
if environment =~ /(\n\s*end\s*)\Z/
- File.open("#{app_path}/config/environment.rb", 'w') do |f|
- f.puts $` + %'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n' + $1
+ File.open("#{app_path}/config/application.rb", 'w') do |f|
+ f.puts $` + "\n#{str}\n" + $1
end
end
end
@@ -108,16 +147,23 @@ module TestHelpers
end
def boot_rails
- # TMP mega hax to prevent boot.rb from actually booting
- Object.class_eval <<-RUBY, __FILE__, __LINE__+1
- module Rails
- Initializer = 'lol'
- require "#{app_path}/config/boot"
- remove_const(:Initializer)
- booter = VendorBoot.new
- booter.run
+ root = File.expand_path('../../../..', __FILE__)
+ begin
+ require "#{root}/vendor/gems/environment"
+ rescue LoadError
+ %w(
+ actionmailer/lib
+ actionpack/lib
+ activemodel/lib
+ activerecord/lib
+ activeresource/lib
+ activesupport/lib
+ railties/lib
+ railties
+ ).reverse_each do |path|
+ $:.unshift "#{root}/#{path}"
end
- RUBY
+ end
end
end
end
@@ -136,7 +182,16 @@ Module.new do
if File.exist?(tmp_path)
FileUtils.rm_rf(tmp_path)
end
-
FileUtils.mkdir(tmp_path)
- `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
+
+ environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
+ if File.exist?("#{environment}.rb")
+ require_environment = "-r #{environment}"
+ end
+
+ `#{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}'" if require_environment
+ f.puts "require 'rails'"
+ end
end
diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb
index 6864254e4c..2256b191e2 100644
--- a/railties/test/metal_test.rb
+++ b/railties/test/metal_test.rb
@@ -85,7 +85,7 @@ class MetalTest < Test::Unit::TestCase
private
def app
- lambda{[402,{},["End of the Line"]]}
+ lambda{|env|[402,{},["End of the Line"]]}
end
def use_appdir(root)
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index d50882110f..c724799d64 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -12,11 +12,32 @@ class PathsTest < ActiveSupport::TestCase
assert_equal "/fiz/baz", root.path
end
+ test "the paths object can be initialized with nil" do
+ assert_nothing_raised do
+ Rails::Application::Root.new(nil)
+ end
+ end
+
+ test "a paths object initialized with nil can be updated" do
+ root = Rails::Application::Root.new(nil)
+ root.app = "app"
+ root.path = "/root"
+ assert_equal ["/root/app"], root.app.to_a
+ end
+
test "creating a root level path" do
@root.app = "/foo/bar"
assert_equal ["/foo/bar"], @root.app.to_a
end
+ test "raises exception if root path never set" do
+ root = Rails::Application::Root.new(nil)
+ root.app = "app"
+ assert_raises RuntimeError do
+ root.app.to_a
+ end
+ end
+
test "creating a root level path without assignment" do
@root.app "/foo/bar"
assert_equal ["/foo/bar"], @root.app.to_a
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
new file mode 100644
index 0000000000..9a2d40cad8
--- /dev/null
+++ b/railties/test/plugins/vendored_test.rb
@@ -0,0 +1,195 @@
+require "isolation/abstract_unit"
+
+module PluginsTest
+ class VendoredTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+
+ @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_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 99cf9168e1..a0484c0868 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -4,10 +4,6 @@ require 'action_controller'
require 'rails/info'
require 'rails/info_controller'
-ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
-end
-
module ActionController
class Base
include ActionController::Testing
@@ -18,9 +14,17 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
+ ActionController::Routing.use_controllers!(['rails/info'])
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
@controller.stubs(:consider_all_requests_local => false, :local_request? => true)
end
+ def teardown
+ ActionController::Routing.use_controllers! nil
+ end
+
test "info controller does not allow remote requests" do
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
get :properties
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