diff options
Diffstat (limited to 'railties')
108 files changed, 693 insertions, 1744 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 0ba5ca10c2..3a87a88ddc 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -6,7 +6,12 @@ require 'rake/gempackagetask' require 'date' require 'rbconfig' -require File.join(File.dirname(__FILE__), 'lib/rails', 'version') +begin + require File.expand_path('../../vendor/gems/environment', __FILE__) +rescue LoadError +end +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib" +require 'rails' PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = ENV['PKG_NAME'] || 'rails' @@ -81,7 +86,6 @@ end # Run application generator ------------------------------------------------------------- task :create_rails do - $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib" require 'rails/generators' require 'rails/generators/rails/app/app_generator' Rails::Generators::AppGenerator.start [ File.basename(PKG_DESTINATION), "--quiet" ], 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/application.rb b/railties/lib/rails/application.rb index a0e5d6a5a5..26a55a73e1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -3,6 +3,11 @@ module Rails extend Initializable class << self + # Stub out App initialize + def initialize! + new + end + def config @config ||= Configuration.new end @@ -36,13 +41,13 @@ module Rails end def new - initializers.run + run_initializers self end end initializer :initialize_rails do - Rails.initializers.run + Rails.run_initializers end # Set the <tt>$LOAD_PATH</tt> based on the value of @@ -52,13 +57,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. @@ -128,15 +126,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. @@ -322,31 +311,6 @@ 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 @@ -367,49 +331,19 @@ module Rails 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}/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 @@ -451,7 +385,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 @@ -487,5 +421,16 @@ module Rails Rails::Generators.options.deep_merge! config.generators.options end end + + # 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 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 9a05c47390..d4c30bbeb2 100644 --- a/railties/lib/rails/commands/about.rb +++ b/railties/lib/rails/commands/about.rb @@ -1,4 +1,2 @@ -require "#{RAILS_ROOT}/config/application" -Rails.application.new 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 860c03e01e..1270fdd033 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,5 +1,4 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators')) -require "#{RAILS_ROOT}/config/application" if ARGV.size == 0 Rails::Generators.help diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index cfa6a51d94..d91dcf9788 100755 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,5 +1,4 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators')) -Rails.application.new 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 5039c5408c..dfba4bf034 100644 --- a/railties/lib/rails/commands/performance/benchmarker.rb +++ b/railties/lib/rails/commands/performance/benchmarker.rb @@ -12,7 +12,6 @@ end require 'benchmark' include Benchmark -Rails.application.new # Don't include compilation in the benchmark ARGV.each { |expression| eval(expression) } @@ -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 7274e2dfb7..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...' -Rails.application.new # Initialize the application - # 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 d24f36dd63..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) -Rails.application.new - 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..29359e49a4 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -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 } @@ -46,7 +46,7 @@ puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]} 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/configuration.rb b/railties/lib/rails/configuration.rb index 322590f108..0a545f23de 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,10 +1,11 @@ require 'rails/plugin/loader' require 'rails/plugin/locator' +require 'active_support/ordered_options' module Rails class Configuration attr_accessor :cache_classes, :load_paths, - :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks, + :load_once_paths, :after_initialize_blocks, :frameworks, :framework_root_path, :root, :plugin_paths, :plugins, :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins, :i18n, :gems, :whiny_nils, :consider_all_requests_local, @@ -23,9 +24,9 @@ module Rails @serve_static_assets = true for framework in frameworks - self.send("#{framework}=", Rails::OrderedOptions.new) + self.send("#{framework}=", ActiveSupport::OrderedOptions.new) end - self.active_support = Rails::OrderedOptions.new + self.active_support = ActiveSupport::OrderedOptions.new end def after_initialize(&blk) @@ -34,37 +35,25 @@ module Rails def root @root ||= begin - if defined?(RAILS_ROOT) - root = RAILS_ROOT - else - 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) - - 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 + 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) - Object.class_eval("RAILS_ROOT = ''") - - root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd + 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 - root = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? - Pathname.new(root).expand_path.to_s : - Pathname.new(root).realpath.to_s + root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd - # TODO: Remove RAILS_ROOT - RAILS_ROOT.replace(root) - root + RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? + Pathname.new(root).expand_path : + Pathname.new(root).realpath end end def root=(root) - Object.class_eval("RAILS_ROOT = ''") unless defined?(RAILS_ROOT) - RAILS_ROOT.replace(root) - @root = root + @root = Pathname.new(root).expand_path end def paths @@ -230,7 +219,7 @@ module Rails def i18n @i18n ||= begin - i18n = Rails::OrderedOptions.new + i18n = ActiveSupport::OrderedOptions.new i18n.load_path = [] if File.exist?(File.join(root, 'config', 'locales')) @@ -242,25 +231,6 @@ module Rails end 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 gems - @gems ||= [] - end - def environment_path "#{root}/config/environments/#{RAILS_ENV}.rb" end @@ -290,6 +260,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 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 471eb45ee6..49f32aa0db 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -9,7 +9,7 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/string/inflections' # TODO: Do not always push on vendored thor -$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.6/lib") +$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.8/lib") require 'rails/generators/base' require 'rails/generators/named_base' @@ -92,8 +92,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 +100,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 +141,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 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..babad33db3 100644 --- a/railties/lib/rails/generators/active_record.rb +++ b/railties/lib/rails/generators/active_record.rb @@ -18,39 +18,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..7af99797ea 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -203,8 +203,8 @@ module Rails super base.source_root # Cache source root - if defined?(RAILS_ROOT) && base.name !~ /Base$/ - path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates')) + if Rails.root && base.name !~ /Base$/ + 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 diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 49b13cae2b..93d9ac553d 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) diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index bcbaa432b7..3966c0f70d 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,10 +1,21 @@ # Gemfile is where you list all of your application's dependencies # -gem "rails", "<%= Rails::VERSION::STRING %>" +<%= "# " if options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>" # # Bundling edge rails: -# gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git" +<%= "# " unless options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git" -# You can list more dependencies here -# gem "nokogiri" -# gem "merb" # ;)
\ No newline at end of file +# Specify gemcutter as a gem source +# source "http://gemcutter.org" + +# Specify gems that this application depends on and have them installed with rake gems:install +# gem "bj" +# gem "hpricot", "0.6" +# gem "sqlite3-ruby", :require_as => "sqlite3" +# gem "aws-s3", :require_as => "aws/s3" + +# Specify gems that should only be required 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 1dce9863f2..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.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment')) +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 3702ad0466..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.expand_path('../config/application', __FILE__) +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 index bff74a7786..8008c6ba07 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -1,5 +1,4 @@ -# Bootstrap the Rails environment, frameworks, and default configuration -require File.expand_path(File.join(File.dirname(__FILE__), 'boot')) +require File.expand_path('../boot', __FILE__) Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. @@ -7,13 +6,7 @@ Rails::Initializer.run do |config| # -- 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" + # 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 @@ -45,4 +38,4 @@ Rails::Initializer.run do |config| # g.template_engine :erb # g.test_framework :test_unit, :fixture => true # end -end
\ No newline at end of file +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 fcf4eddb00..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,9 +1,5 @@ -# Be sure to restart your server when you modify this 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 - # Load the rails application -require File.expand_path(File.join(File.dirname(__FILE__), 'application')) +require File.expand_path('../application', __FILE__) + # Initialize the rails application -Rails.application.new +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.tt index 90a320297e..7639d4040f 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/about.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/about.tt @@ -1,4 +1,4 @@ <%= shebang %> -require File.expand_path('../../config/application', __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/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate.tt index 2a9d219531..26f029c6a6 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/generate.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rails/commands/generate' diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt index 90aca9b4e9..9ebc4c92fc 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/environment', __FILE__) require 'rails/commands/performance/benchmarker' diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt index 39569b4e70..5f4c763f9d 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/environment', __FILE__) require 'rails/commands/performance/profiler' diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner.tt b/railties/lib/rails/generators/rails/app/templates/script/runner.tt index 872ec07a1e..34ad7c18eb 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/runner.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/runner.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rails/commands/runner' diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index d4b0d4b945..0385581083 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -1,3 +1,5 @@ +require 'rails/generators/active_model' + module Rails module Generators # Deal with controller names on scaffold and add some helpers to deal with @@ -47,20 +49,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/initializable.rb b/railties/lib/rails/initializable.rb index 4bd5088207..c491d5e012 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -1,78 +1,86 @@ module Rails module Initializable - - # A collection of initializers - class Collection - def initialize(context) - @context = context - @keys = [] - @values = {} - @ran = false + def self.included(klass) + klass.instance_eval do + extend Rails::Initializable + extend Rails::Initializable::ClassMethodsWhenIncluded + include Rails::Initializable::InstanceMethodsWhenIncluded end + end - def run - return self if @ran - each do |key, initializer| - @context.class_eval(&initializer.block) - end - @ran = true - self - end + def self.extended(klass) + klass.extend Initializer + end - def [](key) - keys, values = merge_with_parent - values[key.to_sym] + class Collection < Array + def initialize(klasses) + klasses.each do |klass| + (klass.added_initializers || []).each do |initializer| + index = if initializer.before + index_for(initializer.before) + elsif initializer.after + index_for(initializer.after) + 1 + else + length + end + + insert(index, initializer) + end + end end - def []=(key, value) - key = key.to_sym - @keys |= [key] - @values[key] = value + def index_for(name) + inst = find {|i| i.name == name } + inst && index(inst) end - def each - keys, values = merge_with_parent - keys.each { |k| yield k, values[k] } - self - end + end - protected + attr_reader :added_initializers - attr_reader :keys, :values + # When you include Rails::Initializable, this method will be on instances + # of the class included into. When you extend it, it will be on the + # class or module itself. + # + # The #initializers method is set up to return the right list of + # initializers for the context in question. + def run_initializers + return if @_initialized - private + initializers.each {|initializer| instance_eval(&initializer.block) } - def merge_with_parent - keys, values = [], {} + @_initialized = true + end - if @context.is_a?(Class) && @context.superclass.is_a?(Initializable) - parent = @context.superclass.initializers - keys, values = parent.keys, parent.values - end + module Initializer + Initializer = Struct.new(:name, :before, :after, :block, :global) - values = values.merge(@values) - return keys | @keys, values + def all_initializers + klasses = ancestors.select {|klass| klass.is_a?(Initializable) }.reverse + initializers = Collection.new(klasses) end - end - - class Initializer - attr_reader :name, :options, :block + alias initializers all_initializers - def initialize(name, options = {}, &block) - @name, @options, @block = name, options, block + def initializer(name, options = {}, &block) + @added_initializers ||= [] + @added_initializers << + Initializer.new(name, options[:before], options[:after], block, options[:global]) end end - def initializer(name, options = {}, &block) - @initializers ||= Collection.new(self) - @initializers[name] = Initializer.new(name, options, &block) - end + module ClassMethodsWhenIncluded + def initializers + all_initializers.select {|i| i.global == true } + end - def initializers - @initializers ||= Collection.new(self) end + module InstanceMethodsWhenIncluded + def initializers + self.class.all_initializers.reject {|i| i.global == true } + end + end end extend Initializable diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index bb86f70da6..2ad1e52746 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -4,11 +4,11 @@ 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/deprecation' RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 0d16cbd7c3..4808c6ad57 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -147,7 +147,7 @@ module Rails end def application_lib_index - $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0 + $LOAD_PATH.index(File.join(Rails.root, 'lib')) || 0 end def enabled?(plugin) diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb index 1057c004e0..56cbaf37c6 100644 --- a/railties/lib/rails/plugin/locator.rb +++ b/railties/lib/rails/plugin/locator.rb @@ -78,7 +78,7 @@ module Rails # 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 } + gem_index = {} specs = gem_index.keys specs += Gem.loaded_specs.values.select do |spec| spec.loaded_from && # prune stubs 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.11.8/CHANGELOG.rdoc index dba25b7205..dba25b7205 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc +++ b/railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc diff --git a/railties/lib/rails/vendor/thor-0.11.6/LICENSE b/railties/lib/rails/vendor/thor-0.11.8/LICENSE index 98722da459..98722da459 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/LICENSE +++ b/railties/lib/rails/vendor/thor-0.11.8/LICENSE diff --git a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc b/railties/lib/rails/vendor/thor-0.11.8/README.rdoc index f1106f02b6..f1106f02b6 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc +++ b/railties/lib/rails/vendor/thor-0.11.8/README.rdoc diff --git a/railties/lib/rails/vendor/thor-0.11.8/Thorfile b/railties/lib/rails/vendor/thor-0.11.8/Thorfile new file mode 100644 index 0000000000..f71a1e57e2 --- /dev/null +++ b/railties/lib/rails/vendor/thor-0.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/lib/thor/actions/create_file.rb index 8f6badee27..8f6badee27 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb index be5eb822ac..063ac57406 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb @@ -73,7 +73,9 @@ class Thor 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) else diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb index 03c1fe4af1..03c1fe4af1 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb b/railties/lib/rails/vendor/thor-0.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/lib/thor/group.rb index 1e59df2313..1e59df2313 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb b/railties/lib/rails/vendor/thor-0.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/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.11.8/lib/thor/version.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb new file mode 100644 index 0000000000..885230fac4 --- /dev/null +++ b/railties/lib/rails/vendor/thor-0.11.8/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 551468b3e8..47013d7797 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,28 +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 index d90582d3db..a3e1916494 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -7,12 +7,11 @@ module ApplicationTests def setup build_app boot_rails - Object.send(:remove_const, :RAILS_ROOT) end test "the application root is set correctly" do require "#{app_path}/config/environment" - assert_equal app_path, Rails.application.root + assert_equal Pathname.new(app_path), Rails.application.root end test "the application root can be set" do @@ -22,7 +21,7 @@ module ApplicationTests config.root = '#{app_path}/hello' RUBY require "#{app_path}/config/environment" - assert_equal "#{app_path}/hello", Rails.application.root + assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root end test "the application root is detected as where config.ru is located" do @@ -31,7 +30,7 @@ module ApplicationTests RUBY FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru" require "#{app_path}/config/environment" - assert_equal "#{app_path}/config", Rails.application.root + 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 @@ -42,7 +41,7 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_equal "#{app_path}/app", Rails.application.root + assert_equal Pathname.new("#{app_path}/app"), Rails.application.root end end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index c664b61137..445a867c85 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -7,6 +7,7 @@ module ApplicationTests def setup build_app boot_rails + require "rails" require "rails/generators" end @@ -37,12 +38,13 @@ 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.application.new + Rails.initialize! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -50,10 +52,11 @@ 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.application.new + Rails.initialize! assert_equal Thor::Base.shell, Thor::Shell::Basic end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 76486d8f2c..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,10 +55,11 @@ module ApplicationTests ZOO Rails::Initializer.run do |config| + config.root = app_path config.eager_load_paths = "#{app_path}/lib" end - Rails.application.new + Rails.initialize! assert Zoo end @@ -60,44 +67,28 @@ module ApplicationTests 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.application.new + 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.application.new + 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 - Rails.application.new - - 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 - Rails.application.new - - 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.application.new + Rails.initialize! assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -105,11 +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.application.new + Rails.initialize! assert_equal "success", $test_after_initialize_block1 assert_equal "congratulations", $test_after_initialize_block2 @@ -118,9 +110,10 @@ 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.application.new + Rails.initialize! assert_equal :de, I18n.default_locale end @@ -128,18 +121,21 @@ module ApplicationTests 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 @@ -151,15 +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.application.new + 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 @@ -167,9 +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.application.new + Rails.initialize! expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] middleware = Rails.application.config.middleware.map { |m| m.klass } @@ -178,10 +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.application.new + Rails.initialize! assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end @@ -189,20 +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.application.new + 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 index a4cf322139..80a19856d7 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -11,63 +11,68 @@ module ApplicationTests def setup build_app boot_rails + require "rails" @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" # Tmp hax to get tests working FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor" end test "all plugins are loaded when registered plugin list is untouched" do - Rails::Initializer.run { } - Rails.application.new + Rails::Initializer.run { |c| c.root = app_path } + Rails.initialize! assert_plugins [ :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby ], Rails.application.config.loaded_plugins, @failure_tip end test "no plugins are loaded if the configuration has an empty plugin list" do - Rails::Initializer.run { |c| c.plugins = [] } + Rails::Initializer.run { |c| c.root = app_path; c.plugins = [] } assert_plugins [], Rails.application.config.loaded_plugins end test "only the specified plugins are located in the order listed" do plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] - Rails::Initializer.run { |c| c.plugins = plugin_names } - Rails.application.new + Rails::Initializer.run { |c| c.root = app_path; c.plugins = plugin_names } + Rails.initialize! assert_plugins plugin_names, Rails.application.config.loaded_plugins end test "all plugins loaded after all" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :all, :acts_as_chunky_bacon] end - Rails.application.new + Rails.initialize! assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip end test "plugin names may be strings" do plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] Rails::Initializer.run do |config| + config.root = app_path config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] end - Rails.application.new + Rails.initialize! assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip end test "all plugins loaded when all is used" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :all] end - Rails.application.new - + Rails.initialize! + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip end test "all loaded plugins are added to the load paths" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon] end - Rails.application.new + Rails.initialize! assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib") assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib") @@ -75,11 +80,12 @@ module ApplicationTests test "registering a plugin name that does not exist raises a load error" do Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_a_non_existant_plugin] end assert_raise(LoadError) do - Rails.application.new + Rails.initialize! end end @@ -89,9 +95,10 @@ module ApplicationTests begin Rails::Initializer.run do |config| + config.root = app_path config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] end - Rails.application.new + Rails.initialize! flunk "Expected a LoadError but did not get one" rescue LoadError => e assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index c3e4f970fe..4e273852e0 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 @@ -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/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 adc61f6d8a..199b5fa8b4 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -89,7 +89,7 @@ class ActionsTest < GeneratorsTestCase 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/application.rb', /#{Regexp.escape(load_paths)}/ end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 5d6a9f6de9..20f2a24e6d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -114,11 +114,18 @@ class AppGeneratorTest < GeneratorsTestCase 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/ + + assert_file 'Gemfile' do |content| + flag = %(gem "rails", "#{Rails::VERSION::STRING}", :git => "git://github.com/rails/rails.git") + assert_match /^#{Regexp.escape(flag)}$/, content + + flag = %(# gem "rails", "#{Rails::VERSION::STRING}") + assert_match /^#{Regexp.escape(flag)}$/, content + end 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 7599bda8a2..ccf08c347c 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,24 +1,10 @@ -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 -end - -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activemodel/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" # TODO: Fix this RAILS_ENV stuff RAILS_ENV = 'test' -require "rails/core" -require 'rails/generators' +require 'abstract_unit' +Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) +require 'rails/generators' require 'rubygems' - require 'active_record' require 'action_dispatch' 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..178b5ef6de 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -80,7 +80,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,10 +101,11 @@ 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, mspec, rails:javascripts.", output end def test_warning_is_shown_if_generator_cant_be_loaded + Rails::Generators.load_paths << File.expand_path("../fixtures/vendor/gems/gems/wrong", __FILE__) 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 @@ -118,7 +119,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)) @@ -170,6 +171,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..f7237e69cc 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -31,38 +31,113 @@ module InitializableTests end end + class Parent + extend Rails::Initializable + + initializer :one do + $arr << 1 + end + + initializer :two do + $arr << 2 + end + end + + class Child < Parent + extend Rails::Initializable + + initializer :three, :before => :one do + $arr << 3 + end + + initializer :four, :after => :one do + $arr << 4 + end + end + + class Parent + initializer :five, :before => :one 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 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 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 6c32f5635b..cf956e68fb 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -7,6 +7,7 @@ module InitializerTests def setup build_app boot_rails + require "rails" end test "rails does not initialize with ruby version 1.8.1" do @@ -42,7 +43,7 @@ module InitializerTests set_ruby_version(version) assert_nothing_raised "It appears that rails does not boot" do Rails::Initializer.run { |c| c.frameworks = [] } - Rails.application.new + Rails.initialize! end end @@ -51,7 +52,7 @@ module InitializerTests $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do Rails::Initializer.run { |c| c.frameworks = [] } - Rails.application.new + Rails.initialize! end end end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index f952d06f94..d664f96ad1 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -7,14 +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.application.new + Rails.initialize! #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml assert_equal %W( @@ -24,7 +26,7 @@ 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 @@ -34,9 +36,10 @@ module InitializerTests 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.application.new + Rails.initialize! #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml assert_equal %W( @@ -47,7 +50,7 @@ module InitializerTests #{app_path}/config/locales/en.yml my/other/locale.yml #{app_path}/vendor/plugins/engine/config/locales/en.yml - ), I18n.load_path + ).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 ce8fc4b8b0..1b58a58555 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -6,13 +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.application.new + 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 5bc878b3be..462a4d8dea 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 @@ -93,6 +92,12 @@ module TestHelpers add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' 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/ @@ -114,16 +119,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 @@ -142,7 +154,12 @@ 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__) + + `#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` + File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f| + f.puts "require '#{environment}' ; require 'rails'" + end end diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb new file mode 100644 index 0000000000..71de542ff7 --- /dev/null +++ b/railties/test/plugins/vendored_test.rb @@ -0,0 +1,19 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class PluginTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + test "generates the plugin" do + script "generate plugin my_plugin" + File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f| + f.puts "OMG = 'hello'" + end + require "#{app_path}/config/environment" + 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 |