From 2df1810cf3cde71fb15594eac022cab27d6497a1 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 21 Jan 2010 23:30:17 +0700 Subject: Add test case for load initializers before routing behavior. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/application/routing_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'railties') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 725dd06929..50cb9e3acc 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -176,5 +176,33 @@ module ApplicationTests get '/foo' assert_equal 'baz', last_response.body end + + test 'resource routing with irrigular inflection' do + app_file 'config/initializers/inflection.rb', <<-RUBY + ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'yazi', 'yazilar' + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + resources :yazilar + end + RUBY + + controller 'yazilar', <<-RUBY + class YazilarController < ActionController::Base + def index + render :text => 'yazilar#index' + end + end + RUBY + + get '/yazilars' + assert_equal 404, last_response.status + + get '/yazilar' + assert_equal 200, last_response.status + end end end -- cgit v1.2.3 From 7fcf8590e788cef8b64cc266f75931c418902ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 21 Jan 2010 23:14:20 +0100 Subject: Massive cleanup in Railties and load stack. --- railties/lib/rails.rb | 3 +- railties/lib/rails/application.rb | 64 +++++----- railties/lib/rails/bootstrap.rb | 62 +++------- railties/lib/rails/configuration.rb | 233 ++++++++++++++++++++---------------- railties/lib/rails/engine.rb | 107 +++++++++++++++++ railties/lib/rails/plugin.rb | 1 - railties/lib/rails/railtie.rb | 68 ++++++----- 7 files changed, 322 insertions(+), 216 deletions(-) create mode 100644 railties/lib/rails/engine.rb (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 0bc7160815..93cf77ffd3 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -5,9 +5,10 @@ require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/logger' require 'rails/initializable' -require 'rails/application' require 'rails/railtie' require 'rails/plugin' +require 'rails/engine' +require 'rails/application' require 'rails/railties_path' require 'rails/version' require 'rails/rack' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 5c9892c630..898dd0ad9b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,14 +1,12 @@ require "fileutils" -require 'active_support/core_ext/module/delegation' module Rails - class Application + class Application < Engine include Initializable class << self - attr_writer :config - alias configure class_eval - delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance + alias :configure :class_eval + delegate :initialize!, :load_tasks, :load_generators, :to => :instance private :new def instance @@ -16,7 +14,16 @@ module Rails end def config - @config ||= Configuration.new(Plugin::Configuration.default) + @config ||= Configuration.new(root) + end + + def root + @root ||= find_root_with_file_flag("config.ru", Dir.pwd) + end + + def inherited(base) + super + Railtie.plugins.delete(base) end def routes @@ -24,8 +31,7 @@ module Rails end end - delegate :config, :routes, :to => :'self.class' - delegate :root, :middleware, :to => :config + delegate :routes, :to => :'self.class' attr_reader :route_configuration_files def initialize @@ -38,12 +44,7 @@ module Rails run_initializers(self) self end - - def require_environment - require config.environment_path - rescue LoadError - end - + def routes_changed_at routes_changed_at = nil @@ -59,6 +60,7 @@ module Rails end def reload_routes! + routes = Rails::Application.routes routes.disable_clear_and_finalize = true routes.clear! @@ -70,6 +72,12 @@ module Rails routes.disable_clear_and_finalize = false end + + def require_environment + require config.environment_path + rescue LoadError + end + def load_tasks require "rails/tasks" plugins.each { |p| p.load_tasks } @@ -114,37 +122,23 @@ module Rails app.call(env) end - initializer :load_application_initializers do - Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| - load(initializer) - end + initializer :build_middleware_stack, :after => :load_application_initializers do + app end - initializer :build_middleware_stack do - app + initializer :add_builtin_route do |app| + if Rails.env.development? + app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + end end # Fires the user-supplied after_initialize block (Configuration#after_initialize) - initializer :after_initialize do + initializer :after_initialize, :after => :build_middleware_stack do config.after_initialize_blocks.each do |block| block.call end end - # Eager load application classes - initializer :load_application_classes do - next if $rails_rake_task - - if config.cache_classes - config.eager_load_paths.each do |load_path| - matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ - Dir.glob("#{load_path}/**/*.rb").sort.each do |file| - require_dependency file.sub(matcher, '\1') - end - end - end - end - # Disable dependency loading during request cycle initializer :disable_dependency_loading do if config.cache_classes && !config.dependency_loading diff --git a/railties/lib/rails/bootstrap.rb b/railties/lib/rails/bootstrap.rb index 5db663f9ef..688ab2f4b0 100644 --- a/railties/lib/rails/bootstrap.rb +++ b/railties/lib/rails/bootstrap.rb @@ -12,30 +12,25 @@ module Rails require "active_support/all" unless config.active_support.bare end - # Set the $LOAD_PATH based on the value of - # Configuration#load_paths. Duplicates are removed. - initializer :set_load_path do - config.paths.add_to_load_path - $LOAD_PATH.uniq! - end - - # Set the paths from which Rails will automatically load source files, and - # the load_once paths. - initializer :set_autoload_paths do - require 'active_support/dependencies' - ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) - ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) - - extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths - unless extra.empty? - abort <<-end_error - load_once_paths must be a subset of the load_paths. - Extra items in load_once_paths: #{extra * ','} - end_error + initializer :initialize_logger do + Rails.logger ||= config.logger || begin + logger = ActiveSupport::BufferedLogger.new(config.paths.log.to_a.first) + logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) + logger.auto_flushing = false if Rails.env.production? + logger + rescue StandardError => e + logger = ActiveSupport::BufferedLogger.new(STDERR) + logger.level = ActiveSupport::BufferedLogger::WARN + logger.warn( + "Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. " + + "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." + ) + logger end + end - # Freeze the arrays so future modifications will fail rather than do nothing mysteriously - config.load_once_paths.freeze + initializer :container do + # FIXME This is just a dumb initializer used as hook end # Create tmp directories @@ -63,29 +58,6 @@ module Rails end end - initializer :initialize_logger do - Rails.logger ||= config.logger || begin - logger = ActiveSupport::BufferedLogger.new(config.log_path) - logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) - logger.auto_flushing = false if Rails.env.production? - logger - rescue StandardError => e - logger = ActiveSupport::BufferedLogger.new(STDERR) - logger.level = ActiveSupport::BufferedLogger::WARN - logger.warn( - "Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. " + - "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." - ) - logger - end - end - - # Sets the logger for dependencies and cache store. - initializer :initialize_framework_logging do - ActiveSupport::Dependencies.logger ||= Rails.logger - Rails.cache.logger ||= Rails.logger - end - # Sets the dependency loading mechanism based on the value of # Configuration#cache_classes. initializer :initialize_dependency_mechanism do diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 7f1783a6b9..77248f2611 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,15 +1,9 @@ require 'active_support/ordered_options' module Rails - # Temporarily separate the plugin configuration class from the main - # configuration class while this bit is being cleaned up. - class Railtie::Configuration - def self.default - @default ||= new - end - - def self.default_middleware_stack - ActionDispatch::MiddlewareStack.new.tap do |middleware| + module SharedConfiguration + def self.middleware_stack + @default_middleware_stack ||= ActionDispatch::MiddlewareStack.new.tap do |middleware| middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets }) middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency }) middleware.use('::Rack::Runtime') @@ -26,16 +20,23 @@ module Rails end end + def self.options + @options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } + end + end + + # Temporarily separate the plugin configuration class from the main + # configuration class while this bit is being cleaned up. + class Railtie::Configuration + def self.default + @default ||= new + end + attr_reader :middleware - def initialize(base = nil) - if base - @options = base.options.dup - @middleware = base.middleware.dup - else - @options = Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } - @middleware = self.class.default_middleware_stack - end + def initialize + @options = SharedConfiguration.options + @middleware = SharedConfiguration.middleware_stack end def respond_to?(name) @@ -61,27 +62,65 @@ module Rails /^(#{bits})(?:=)?$/ end + # TODO Remove :active_support as special case by adding a railtie + # for it and for I18n def config_keys - ([ :active_support, :action_view ] + - Railtie.plugin_names).map { |n| n.to_s }.uniq + ([:active_support] + Railtie.plugin_names).map { |n| n.to_s }.uniq end end - class Configuration < Railtie::Configuration + class Engine::Configuration < Railtie::Configuration + attr_reader :root + + def initialize(root) + @root = root + super() + end + + def paths + @paths ||= begin + paths = Rails::Application::Root.new(root) + paths.app "app", :load_path => true + paths.app_glob "app/*", :load_path => true, :eager_load => true + paths.app.controllers "app/controllers" + paths.app.metals "app/metal" + paths.app.views "app/views" + paths.lib "lib", :load_path => true + paths.config "config" + paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" + paths.config.initializers "config/initializers" + paths.config.locales "config/locales" + paths.config.routes "config/routes.rb" + paths + end + end + + def eager_load_paths + @eager_load_paths ||= paths.eager_load + end + + def load_once_paths + @eager_load_paths ||= paths.load_once + end + + def load_paths + @load_paths ||= paths.load_paths + end + end + + class Configuration < Engine::Configuration attr_accessor :after_initialize_blocks, :cache_classes, :colorize_logging, :consider_all_requests_local, :dependency_loading, :filter_parameters, - :load_once_paths, :logger, :metals, :plugins, + :logger, :metals, :plugins, :preload_frameworks, :reload_plugins, :serve_static_assets, :time_zone, :whiny_nils attr_writer :cache_store, :controller_paths, - :database_configuration_file, :eager_load_paths, - :i18n, :load_paths, :log_level, :log_path, :paths, - :routes_configuration_file, :view_path + :database_configuration_file, + :i18n, :log_level, :log_path - def initialize(base = nil) + def initialize(*) super - @load_once_paths = [] @after_initialize_blocks = [] @filter_parameters = [] @dependency_loading = true @@ -92,46 +131,23 @@ module Rails @after_initialize_blocks << blk if blk end - def root - @root ||= begin - call_stack = caller.map { |p| p.split(':').first } - root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] } - 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 - - root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd - - RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? - Pathname.new(root).expand_path : - Pathname.new(root).realpath - end - end - - def root=(root) - @root = Pathname.new(root).expand_path - end - def paths @paths ||= begin - paths = Rails::Application::Root.new(root) - paths.app "app", :load_path => true - paths.app.metals "app/metal", :eager_load => true - paths.app.models "app/models", :eager_load => true - paths.app.controllers "app/controllers", builtin_directories, :eager_load => true - paths.app.helpers "app/helpers", :eager_load => true - paths.app.services "app/services", :load_path => true - paths.lib "lib", :load_path => true - paths.vendor "vendor", :load_path => true - paths.vendor.plugins "vendor/plugins" - paths.tmp "tmp" - paths.tmp.cache "tmp/cache" - paths.config "config" - paths.config.locales "config/locales" - paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" + paths = super + paths.builtin_controller builtin_directories, :eager_load => true + paths.config.database "config/database.yml" + paths.log "log/#{Rails.env}.log" + paths.tmp "tmp" + paths.tmp.cache "tmp/cache" + paths.vendor "vendor", :load_path => true + paths.vendor.plugins "vendor/plugins" + + if File.exists?("#{root}/test/mocks/#{Rails.env}") + ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " << + "automatically to load paths anymore in next releases." + paths.mocks_path "test/mocks/#{Rails.env}", :load_path => true + end + paths end end @@ -163,17 +179,61 @@ module Rails # YAML::load. def database_configuration require 'erb' - YAML::load(ERB.new(IO.read(database_configuration_file)).result) + YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result) + end + + def view_path=(value) + ActiveSupport::Deprecation.warn "config.view_path= is deprecated, " << + "please do config.paths.app.views= instead", caller + paths.app.views = value + end + + def view_path + ActiveSupport::Deprecation.warn "config.view_path is deprecated, " << + "please do config.paths.app.views instead", caller + paths.app.views.to_a.first + end + + def routes_configuration_file=(value) + ActiveSupport::Deprecation.warn "config.routes_configuration_file= is deprecated, " << + "please do config.paths.config.routes= instead", caller + paths.config.routes = value end def routes_configuration_file - @routes_configuration_file ||= File.join(root, 'config', 'routes.rb') + ActiveSupport::Deprecation.warn "config.routes_configuration_file is deprecated, " << + "please do config.paths.config.routes instead", caller + paths.config.routes.to_a.first + end + + def database_configuration_file=(value) + ActiveSupport::Deprecation.warn "config.database_configuration_file= is deprecated, " << + "please do config.paths.config.database= instead", caller + paths.config.database = value + end + + def database_configuration_file + ActiveSupport::Deprecation.warn "config.database_configuration_file is deprecated, " << + "please do config.paths.config.database instead", caller + paths.config.database.to_a.first + end + + def log_path=(value) + ActiveSupport::Deprecation.warn "config.log_path= is deprecated, " << + "please do config.paths.log= instead", caller + paths.config.log = value end - def builtin_routes_configuration_file - @builtin_routes_configuration_file ||= File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + def log_path + ActiveSupport::Deprecation.warn "config.log_path is deprecated, " << + "please do config.paths.log instead", caller + paths.config.log.to_a.first end + + + # TODO Router needs this, but this wouldn't work with engines. + # There is a high chance of plugins routes to be broken. def controller_paths @controller_paths ||= begin paths = [File.join(root, 'app', 'controllers')] @@ -192,46 +252,11 @@ module Rails end end - def database_configuration_file - @database_configuration_file ||= File.join(root, 'config', 'database.yml') - end - - def view_path - @view_path ||= File.join(root, 'app', 'views') - end - - def eager_load_paths - @eager_load_paths ||= ["#{root}/app/*"] - end - - def load_paths - @load_paths ||= begin - paths = [] - - # Add the old mock paths only if the directories exists - paths.concat(Dir["#{root}/test/mocks/#{Rails.env}"]) if File.exists?("#{root}/test/mocks/#{Rails.env}") - - # Followed by the standard includes. - paths.concat %w( - app - app/* - lib - vendor - ).map { |dir| "#{root}/#{dir}" } - - paths.concat builtin_directories - end - end - + # Include builtins only in the development environment. def builtin_directories - # Include builtins only in the development environment. Rails.env.development? ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] end - def log_path - @log_path ||= File.join(root, 'log', "#{Rails.env}.log") - end - def log_level @log_level ||= Rails.env.production? ? :info : :debug end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb new file mode 100644 index 0000000000..21c78036bd --- /dev/null +++ b/railties/lib/rails/engine.rb @@ -0,0 +1,107 @@ +require 'active_support/core_ext/module/delegation' + +module Rails + # TODO Move I18n and views path setup + class Engine < Railtie + + class << self + attr_accessor :called_from + + def root + @root ||= find_root_with_file_flag("lib") + end + + def config + @config ||= Configuration.new(root) + end + + def inherited(base) + base.called_from = begin + call_stack = caller.map { |p| p.split(':').first } + File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + end + super + end + + protected + + def find_root_with_file_flag(flag, default=nil) + root_path = self.called_from + + while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") + parent = File.dirname(root_path) + root_path = parent != root_path && parent + end + + root = File.exist?("#{root_path}/flag") ? root_path : default + + raise "Could not find root path for #{self}" unless root + + RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? + Pathname.new(root).expand_path : + Pathname.new(root).realpath + end + end + + delegate :root, :config, :to => :'self.class' + delegate :middleware, :to => :config + + # Add configured load paths to ruby load paths and remove duplicates. + initializer :set_load_path, :before => :container do + config.paths.add_to_load_path + $LOAD_PATH.uniq! + end + + # Set the paths from which Rails will automatically load source files, + # and the load_once paths. + initializer :set_autoload_paths, :before => :container do + require 'active_support/dependencies' + + ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) + ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) + + extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths + + unless extra.empty? + abort <<-end_error + load_once_paths must be a subset of the load_paths. + Extra items in load_once_paths: #{extra * ','} + end_error + end + + # Freeze the arrays so future modifications will fail rather than do nothing mysteriously + config.load_once_paths.freeze + end + + initializer :load_application_initializers do + Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| + load(initializer) + end + end + + # Routing must be initialized after plugins to allow the former to extend the routes + initializer :initialize_routing do |app| + app.route_configuration_files.concat(config.paths.config.routes.to_a) + end + + # Eager load application classes + initializer :load_application_classes do |app| + next if $rails_rake_task + + if app.config.cache_classes + config.eager_load_paths.each do |load_path| + matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ + Dir.glob("#{load_path}/**/*.rb").sort.each do |file| + require_dependency file.sub(matcher, '\1') + end + end + end + end + + private + + def expand_load_path(load_paths) + load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index c3b81bcd3e..dde06bfcbd 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -57,7 +57,6 @@ module Rails end end - # TODO Isn't it supposed to be :after => "action_controller.initialize_routing" ? initializer :add_routing_file, :after => :initialize_routing do |app| routing_file = "#{path}/config/routes.rb" if File.exist?(routing_file) diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index e3297148e5..a7f52b25e4 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -2,43 +2,51 @@ module Rails class Railtie include Initializable - def self.plugin_name(plugin_name = nil) - @plugin_name ||= name.demodulize.underscore - @plugin_name = plugin_name if plugin_name - @plugin_name - end + ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application) - def self.inherited(klass) - @plugins ||= [] - @plugins << klass unless klass == Plugin - end + class << self + def abstract_railtie?(base) + ABSTRACT_RAILTIES.include?(base.name) + end - def self.plugins - @plugins - end + def inherited(base) + @@plugins ||= [] + @@plugins << base unless abstract_railtie?(base) + end - def self.plugin_names - plugins.map { |p| p.plugin_name } - end + def plugin_name(plugin_name = nil) + @plugin_name ||= name.demodulize.underscore + @plugin_name = plugin_name if plugin_name + @plugin_name + end - def self.config - Configuration.default - end + def plugins + @@plugins + end - def self.subscriber(subscriber) - Rails::Subscriber.add(plugin_name, subscriber) - end + def plugin_names + plugins.map { |p| p.plugin_name } + end - def self.rake_tasks(&blk) - @rake_tasks ||= [] - @rake_tasks << blk if blk - @rake_tasks - end + def config + Configuration.default + end + + def subscriber(subscriber) + Rails::Subscriber.add(plugin_name, subscriber) + end + + def rake_tasks(&blk) + @rake_tasks ||= [] + @rake_tasks << blk if blk + @rake_tasks + end - def self.generators(&blk) - @generators ||= [] - @generators << blk if blk - @generators + def generators(&blk) + @generators ||= [] + @generators << blk if blk + @generators + end end def rake_tasks -- cgit v1.2.3 From 02c5137eadbb3530033d919b7aebeb6f4f389b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 01:10:31 +0100 Subject: Add view paths to Engine setup. --- railties/lib/rails/application.rb | 18 +++++----- railties/lib/rails/configuration.rb | 36 +++++++++---------- railties/lib/rails/engine.rb | 48 ++++++++++++++++--------- railties/lib/rails/railtie.rb | 1 + railties/test/application/configuration_test.rb | 4 +-- 5 files changed, 60 insertions(+), 47 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 898dd0ad9b..9be9584873 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,4 +1,4 @@ -require "fileutils" +require 'fileutils' module Rails class Application < Engine @@ -6,7 +6,7 @@ module Rails class << self alias :configure :class_eval - delegate :initialize!, :load_tasks, :load_generators, :to => :instance + delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance private :new def instance @@ -14,11 +14,11 @@ module Rails end def config - @config ||= Configuration.new(root) + @config ||= Configuration.new(original_root) end - def root - @root ||= find_root_with_file_flag("config.ru", Dir.pwd) + def original_root + @original_root ||= find_root_with_file_flag("config.ru", Dir.pwd) end def inherited(base) @@ -122,16 +122,16 @@ module Rails app.call(env) end - initializer :build_middleware_stack, :after => :load_application_initializers do - app - end - initializer :add_builtin_route do |app| if Rails.env.development? app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end + initializer :build_middleware_stack, :after => :load_application_initializers do + app + end + # Fires the user-supplied after_initialize block (Configuration#after_initialize) initializer :after_initialize, :after => :build_middleware_stack do config.after_initialize_blocks.each do |block| diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 77248f2611..9176809dbd 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -70,7 +70,8 @@ module Rails end class Engine::Configuration < Railtie::Configuration - attr_reader :root + attr_reader :root + attr_accessor :eager_load_paths, :load_once_paths, :load_paths def initialize(root) @root = root @@ -79,14 +80,15 @@ module Rails def paths @paths ||= begin - paths = Rails::Application::Root.new(root) + paths = Rails::Application::Root.new(@root) paths.app "app", :load_path => true paths.app_glob "app/*", :load_path => true, :eager_load => true - paths.app.controllers "app/controllers" + paths.app.controllers "app/controllers", :eager_load => true paths.app.metals "app/metal" paths.app.views "app/views" paths.lib "lib", :load_path => true paths.config "config" + paths.config.environment "config/environments/#{Rails.env}.rb" paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" paths.config.initializers "config/initializers" paths.config.locales "config/locales" @@ -95,6 +97,10 @@ module Rails end end + def root=(value) + @root = paths.path = Pathname.new(value).expand_path + end + def eager_load_paths @eager_load_paths ||= paths.eager_load end @@ -106,6 +112,10 @@ module Rails def load_paths @load_paths ||= paths.load_paths end + + def controller_paths + paths.app.controllers.to_a.uniq + end end class Configuration < Engine::Configuration @@ -115,9 +125,7 @@ module Rails :preload_frameworks, :reload_plugins, :serve_static_assets, :time_zone, :whiny_nils - attr_writer :cache_store, :controller_paths, - :database_configuration_file, - :i18n, :log_level, :log_path + attr_writer :cache_store, :controller_paths, :i18n, :log_level def initialize(*) super @@ -134,7 +142,7 @@ module Rails def paths @paths ||= begin paths = super - paths.builtin_controller builtin_directories, :eager_load => true + paths.app.controllers << builtin_directories paths.config.database "config/database.yml" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" @@ -144,7 +152,7 @@ module Rails if File.exists?("#{root}/test/mocks/#{Rails.env}") ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " << - "automatically to load paths anymore in next releases." + "automatically to load paths anymore in future releases" paths.mocks_path "test/mocks/#{Rails.env}", :load_path => true end @@ -230,18 +238,6 @@ module Rails paths.config.log.to_a.first end - - - # TODO Router needs this, but this wouldn't work with engines. - # There is a high chance of plugins routes to be broken. - def controller_paths - @controller_paths ||= begin - paths = [File.join(root, 'app', 'controllers')] - paths.concat builtin_directories - paths - end - end - def cache_store @cache_store ||= begin if File.exist?("#{root}/tmp/cache/") diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 21c78036bd..a0139f9983 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,18 +1,19 @@ require 'active_support/core_ext/module/delegation' module Rails - # TODO Move I18n and views path setup + # TODO Move I18n here + # TODO Set routes namespaces class Engine < Railtie class << self attr_accessor :called_from - def root - @root ||= find_root_with_file_flag("lib") + def original_root + @original_root ||= find_root_with_file_flag("lib") end def config - @config ||= Configuration.new(root) + @config ||= Configuration.new(original_root) end def inherited(base) @@ -20,6 +21,7 @@ module Rails call_stack = caller.map { |p| p.split(':').first } File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) end + super end @@ -33,7 +35,7 @@ module Rails root_path = parent != root_path && parent end - root = File.exist?("#{root_path}/flag") ? root_path : default + root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root @@ -43,8 +45,8 @@ module Rails end end - delegate :root, :config, :to => :'self.class' - delegate :middleware, :to => :config + delegate :config, :to => :'self.class' + delegate :middleware, :root, :to => :config # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :container do @@ -57,10 +59,11 @@ module Rails initializer :set_autoload_paths, :before => :container do require 'active_support/dependencies' - ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) + ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) - extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths + extra = ActiveSupport::Dependencies.load_once_paths - + ActiveSupport::Dependencies.load_paths unless extra.empty? abort <<-end_error @@ -73,15 +76,24 @@ module Rails config.load_once_paths.freeze end - initializer :load_application_initializers do - Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| - load(initializer) - end + # Routing must be initialized after plugins to allow the former to extend the routes + initializer :add_routing_files do |app| + routes = select_existing(config.paths.config.routes) + app.route_configuration_files.concat(routes) end - # Routing must be initialized after plugins to allow the former to extend the routes - initializer :initialize_routing do |app| - app.route_configuration_files.concat(config.paths.config.routes.to_a) + initializer :add_view_paths do + views = select_existing(config.paths.app.views) + ActionController::Base.view_paths.concat(views) if defined? ActionController + ActionMailer::Base.view_paths.concat(views) if defined? ActionMailer + end + + initializer :load_application_initializers do + select_existing(config.paths.config.initializers).each do |initializers| + Dir["#{initializers}/**/*.rb"].sort.each do |initializer| + load(initializer) + end + end end # Eager load application classes @@ -100,6 +112,10 @@ module Rails private + def select_existing(paths) + paths.to_a.select { |path| File.exists?(path) }.uniq + end + def expand_load_path(load_paths) load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index a7f52b25e4..5b97fabe40 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -14,6 +14,7 @@ module Rails @@plugins << base unless abstract_railtie?(base) end + # This should be called railtie_name and engine_name def plugin_name(plugin_name = nil) @plugin_name ||= name.demodulize.underscore @plugin_name = plugin_name if plugin_name diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6968e87986..2c842eb096 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -34,9 +34,9 @@ module ApplicationTests add_to_config <<-RUBY config.root = '#{new_app}' RUBY - + use_frameworks [] - + require "#{app_path}/config/environment" assert_equal Pathname.new(new_app), Rails.application.root end -- cgit v1.2.3 From c9dc1ac95bc97800dd3deb82fe1cf6f98e27413d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Fri, 22 Jan 2010 13:32:16 +1100 Subject: Updating functional tests to not compare equality with encoded, Mail::Message has an == operator --- railties/lib/generators/test_unit/mailer/templates/functional_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb index 4de94076e9..d7366fea5f 100644 --- a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb @@ -7,7 +7,7 @@ class <%= class_name %>Test < ActionMailer::TestCase @expected.body = read_fixture('<%= action %>') @expected.date = Time.now - assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded + assert_equal @expected, <%= class_name %>.create_<%= action %>(@expected.date) end <% end -%> -- cgit v1.2.3 From 6fd7d1fc128f1d6d7bddaa6770739d7e936dd049 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Fri, 22 Jan 2010 19:38:50 +1100 Subject: Fixing typo in config.frameworks error --- railties/lib/rails/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 7f1783a6b9..21736a28eb 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -137,7 +137,7 @@ module Rails end def frameworks(*args) - raise "config.frameworks in no longer supported. See the generated " \ + raise "config.frameworks is no longer supported. See the generated " \ "config/boot.rb for steps on how to limit the frameworks that " \ "will be loaded" end -- cgit v1.2.3 From 4ae79367277954bf6616151b03cbe0660808f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 16:24:44 +0100 Subject: Got tests working once again. --- railties/lib/rails/application.rb | 4 +--- railties/lib/rails/configuration.rb | 28 +++++++++++++++---------- railties/lib/rails/engine.rb | 4 +++- railties/lib/rails/paths.rb | 18 +++++++--------- railties/test/application/configuration_test.rb | 4 ++-- railties/test/initializer/path_test.rb | 23 +++++++------------- railties/test/paths_test.rb | 7 +------ 7 files changed, 40 insertions(+), 48 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9be9584873..db1f62f381 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,8 +2,6 @@ require 'fileutils' module Rails class Application < Engine - include Initializable - class << self alias :configure :class_eval delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance @@ -122,7 +120,7 @@ module Rails app.call(env) end - initializer :add_builtin_route do |app| + initializer :add_builtin_route, :before => :build_middleware_stack do |app| if Rails.env.development? app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 9176809dbd..01fab1e474 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -81,15 +81,13 @@ module Rails def paths @paths ||= begin paths = Rails::Application::Root.new(@root) - paths.app "app", :load_path => true - paths.app_glob "app/*", :load_path => true, :eager_load => true - paths.app.controllers "app/controllers", :eager_load => true - paths.app.metals "app/metal" + paths.app "app", :eager_load => true, :glob => "*" + paths.app.controllers "app/controllers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true paths.app.views "app/views" paths.lib "lib", :load_path => true paths.config "config" - paths.config.environment "config/environments/#{Rails.env}.rb" - paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" + paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" paths.config.initializers "config/initializers" paths.config.locales "config/locales" paths.config.routes "config/routes.rb" @@ -112,10 +110,6 @@ module Rails def load_paths @load_paths ||= paths.load_paths end - - def controller_paths - paths.app.controllers.to_a.uniq - end end class Configuration < Engine::Configuration @@ -142,7 +136,7 @@ module Rails def paths @paths ||= begin paths = super - paths.app.controllers << builtin_directories + paths.app.controllers.concat(builtin_directories) paths.config.database "config/database.yml" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" @@ -238,6 +232,18 @@ module Rails paths.config.log.to_a.first end + def controller_paths=(value) + ActiveSupport::Deprecation.warn "config.controller_paths= is deprecated, " << + "please do config.paths.app.controllers= instead", caller + paths.app.controllers = value + end + + def controller_paths + ActiveSupport::Deprecation.warn "config.controller_paths is deprecated, " << + "please do config.paths.app.controllers instead", caller + paths.app.controllers.to_a.uniq + end + def cache_store @cache_store ||= begin if File.exist?("#{root}/tmp/cache/") diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index a0139f9983..effbfee6c1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -50,7 +50,9 @@ module Rails # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :container do - config.paths.add_to_load_path + expand_load_path(config.load_paths).reverse_each do |path| + $LOAD_PATH.unshift(path) if File.directory?(path) + end $LOAD_PATH.uniq! end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index b3d105d8c7..d81af3c709 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -39,6 +39,7 @@ module Rails all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq end + # TODO Discover why do we need to call uniq! here def all_paths @all_paths.uniq! @all_paths @@ -48,12 +49,6 @@ module Rails all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq end - def add_to_load_path - load_paths.reverse_each do |path| - $LOAD_PATH.unshift(path) if File.directory?(path) - end - end - def push(*) raise "Application root can only have one physical path" end @@ -74,7 +69,7 @@ module Rails @children = {} @root = root @paths = paths.flatten - @glob = @options[:glob] || "**/*.rb" + @glob = @options.delete(:glob) @load_once = @options[:load_once] @eager_load = @options[:eager_load] @@ -128,10 +123,13 @@ module Rails def paths raise "You need to set a path root" unless @root.path - - @paths.map do |path| - path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path)) + result = @paths.map do |p| + path = File.expand_path(p, @root.path) + @glob ? Dir[File.join(path, @glob)] : path end + result.flatten! + result.uniq! + result end alias to_a paths diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 2c842eb096..6968e87986 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -34,9 +34,9 @@ module ApplicationTests add_to_config <<-RUBY config.root = '#{new_app}' RUBY - + use_frameworks [] - + require "#{app_path}/config/environment" assert_equal Pathname.new(new_app), Rails.application.root end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 328dda6d2c..76eb29bdf4 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -8,6 +8,7 @@ module InitializerTests build_app boot_rails FileUtils.rm_rf("#{app_path}/config/environments") + app_file "config/environments/development.rb", "" add_to_config <<-RUBY config.root = "#{app_path}" config.after_initialize do @@ -36,11 +37,8 @@ module InitializerTests end test "booting up Rails yields a valid paths object" do - assert_path @paths.app, "app" assert_path @paths.app.metals, "app", "metal" - assert_path @paths.app.models, "app", "models" - assert_path @paths.app.helpers, "app", "helpers" - assert_path @paths.app.services, "app", "services" + assert_path @paths.app.views, "app", "views" assert_path @paths.lib, "lib" assert_path @paths.vendor, "vendor" assert_path @paths.vendor.plugins, "vendor", "plugins" @@ -48,7 +46,7 @@ module InitializerTests assert_path @paths.tmp.cache, "tmp", "cache" assert_path @paths.config, "config" assert_path @paths.config.locales, "config", "locales" - assert_path @paths.config.environments, "config", "environments" + assert_path @paths.config.environment, "config", "environments", "development.rb" assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, @@ -56,27 +54,22 @@ module InitializerTests end test "booting up Rails yields a list of paths that are eager" do - assert @paths.app.models.eager_load? + assert @paths.app.eager_load? assert @paths.app.controllers.eager_load? - assert @paths.app.helpers.eager_load? assert @paths.app.metals.eager_load? end test "environments has a glob equal to the current environment" do - assert_equal "#{Rails.env}.rb", @paths.config.environments.glob + assert_equal "#{Rails.env}.rb", @paths.config.environment.glob end test "load path includes each of the paths in config.paths as long as the directories exist" do - assert_in_load_path "app" assert_in_load_path "app", "controllers" assert_in_load_path "app", "models" assert_in_load_path "app", "helpers" assert_in_load_path "lib" assert_in_load_path "vendor" - assert_not_in_load_path "app", "views" - assert_not_in_load_path "app", "metal" - assert_not_in_load_path "app", "services" assert_not_in_load_path "config" assert_not_in_load_path "config", "locales" assert_not_in_load_path "config", "environments" @@ -86,17 +79,17 @@ module InitializerTests test "controller paths include builtin in development mode" do Rails.env.replace "development" - assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end test "controller paths does not have builtin_directories in test mode" do Rails.env.replace "test" - assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end test "controller paths does not have builtin_directories in production mode" do Rails.env.replace "production" - assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end end diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index d60d6177f6..001282bb0d 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -193,12 +193,7 @@ class PathsTest < ActiveSupport::TestCase assert_equal 2, @root.eager_load.size end - test "a path should have a glob that defaults to **/*.rb" do - @root.app = "/app" - assert_equal "**/*.rb", @root.app.glob - end - - test "it should be possible to override a path's default glob" do + test "it should be possible to add a path's default glob" do @root.app = "/app" @root.app.glob = "*.rb" assert_equal "*.rb", @root.app.glob -- cgit v1.2.3 From c8cc8a987213bf90fe6922517d52befb7c0587a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 20:44:29 +0100 Subject: Moved more configuration away from bootstrap. --- railties/lib/rails/all.rb | 1 + railties/lib/rails/application.rb | 39 ++++++++++++++++++++ railties/lib/rails/bootstrap.rb | 72 ------------------------------------- railties/lib/rails/configuration.rb | 4 +-- 4 files changed, 41 insertions(+), 75 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 7dfe2b8b63..b8292a9b7e 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -1,6 +1,7 @@ require "rails" %w( + active_support active_model active_record action_controller diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index db1f62f381..5c4112e1d7 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -137,6 +137,45 @@ module Rails end end + # Set the i18n configuration from config.i18n but special-case for the load_path which should be + # appended to what's already set instead of overwritten. + initializer :initialize_i18n do + require 'active_support/i18n' + + config.i18n.each do |setting, value| + if setting == :load_path + I18n.load_path += value + else + I18n.send("#{setting}=", value) + end + end + + ActionDispatch::Callbacks.to_prepare do + I18n.reload! + end + end + + initializer :set_clear_dependencies_hook do + unless config.cache_classes + ActionDispatch::Callbacks.after do + ActiveSupport::Dependencies.clear + end + end + end + + initializer :initialize_notifications do + require 'active_support/notifications' + + if config.colorize_logging == false + Rails::Subscriber.colorize_logging = false + config.generators.colorize_logging = false + end + + ActiveSupport::Notifications.subscribe do |*args| + Rails::Subscriber.dispatch(args) + end + end + # Disable dependency loading during request cycle initializer :disable_dependency_loading do if config.cache_classes && !config.dependency_loading diff --git a/railties/lib/rails/bootstrap.rb b/railties/lib/rails/bootstrap.rb index 688ab2f4b0..3473f2fcaa 100644 --- a/railties/lib/rails/bootstrap.rb +++ b/railties/lib/rails/bootstrap.rb @@ -33,13 +33,6 @@ module Rails # FIXME This is just a dumb initializer used as hook end - # Create tmp directories - initializer :ensure_tmp_directories_exist do - %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(File.join(root, 'tmp', dir_to_make)) - 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. @@ -64,70 +57,5 @@ module Rails # TODO: Remove files from the $" and always use require ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end - - # Loads support for "whiny nil" (noisy warnings when methods are invoked - # on +nil+ values) if Configuration#whiny_nils is true. - initializer :initialize_whiny_nils do - require 'active_support/whiny_nil' if config.whiny_nils - end - - # Sets the default value for Time.zone - # If assigned value cannot be matched to a TimeZone, an exception will be raised. - initializer :initialize_time_zone do - require 'active_support/core_ext/time/zones' - zone_default = Time.__send__(:get_zone, config.time_zone) - - unless zone_default - raise \ - 'Value assigned to config.time_zone not recognized.' + - 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.' - end - - Time.zone_default = zone_default - end - - # Set the i18n configuration from config.i18n but special-case for the load_path which should be - # appended to what's already set instead of overwritten. - initializer :initialize_i18n do - require 'active_support/i18n' - - config.i18n.each do |setting, value| - if setting == :load_path - I18n.load_path += value - else - I18n.send("#{setting}=", value) - end - end - - ActionDispatch::Callbacks.to_prepare do - I18n.reload! - end - end - - initializer :set_clear_dependencies_hook do - unless config.cache_classes - ActionDispatch::Callbacks.after do - ActiveSupport::Dependencies.clear - end - end - end - - initializer :initialize_notifications do - require 'active_support/notifications' - - if config.colorize_logging == false - Rails::Subscriber.colorize_logging = false - config.generators.colorize_logging = false - end - - ActiveSupport::Notifications.subscribe do |*args| - Rails::Subscriber.dispatch(args) - end - end - - private - def expand_load_path(load_paths) - load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq - end end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 01fab1e474..3ba27d79a7 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -62,10 +62,8 @@ module Rails /^(#{bits})(?:=)?$/ end - # TODO Remove :active_support as special case by adding a railtie - # for it and for I18n def config_keys - ([:active_support] + Railtie.plugin_names).map { |n| n.to_s }.uniq + Railtie.plugin_names.map { |n| n.to_s }.uniq end end -- cgit v1.2.3 From 98240c49b05093d6d14b9384a9bd695b58eefb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 01:29:29 +0100 Subject: Get rid of initializers global and create i18n railtie. --- .../generators/rails/app/templates/config/boot.rb | 4 +- railties/lib/rails.rb | 3 +- railties/lib/rails/application.rb | 76 ++---- railties/lib/rails/bootstrap.rb | 51 ++-- railties/lib/rails/configuration.rb | 285 +++++++++------------ railties/lib/rails/engine.rb | 48 ++-- railties/lib/rails/initializable.rb | 19 +- railties/test/application/initializer_test.rb | 4 +- railties/test/application/notifications_test.rb | 27 -- railties/test/initializable_test.rb | 28 +- railties/test/initializer/initialize_i18n_test.rb | 3 +- railties/test/initializer/path_test.rb | 2 +- 12 files changed, 225 insertions(+), 325 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/rails/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb index 466e1e50ec..cbfa5ca3e9 100644 --- a/railties/lib/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/generators/rails/app/templates/config/boot.rb @@ -19,7 +19,7 @@ require 'rails/all' # To pick the frameworks you want, remove 'require "rails/all"' # and list the framework railties that you want: # -# require "active_model/railtie" +# require "active_support/railtie" # require "active_record/railtie" # require "action_controller/railtie" # require "action_view/railtie" @@ -28,7 +28,7 @@ require 'rails/all' <% else -%> # Pick the frameworks you want: # require "active_record/railtie" -require "active_model/railtie" +require "active_support/railtie" require "action_controller/railtie" require "action_view/railtie" require "action_mailer/railtie" diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 93cf77ffd3..e3aa9e4c97 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -8,6 +8,7 @@ require 'rails/initializable' require 'rails/railtie' require 'rails/plugin' require 'rails/engine' +require 'rails/bootstrap' require 'rails/application' require 'rails/railties_path' require 'rails/version' @@ -33,8 +34,6 @@ else end module Rails - autoload :Bootstrap, 'rails/bootstrap' - class << self def application @@application ||= nil diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 5c4112e1d7..9b0f39feb1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,6 +2,11 @@ require 'fileutils' module Rails class Application < Engine + + # TODO Clear up 2 way delegation flow between App class and instance. + # Infact just add a method_missing on the class. + # + # TODO I'd like to track the "default app" different using an inherited hook. class << self alias :configure :class_eval delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance @@ -70,10 +75,9 @@ module Rails routes.disable_clear_and_finalize = false end - def require_environment - require config.environment_path - rescue LoadError + environment = config.paths.config.environment.to_a.first + require environment if environment end def load_tasks @@ -92,13 +96,6 @@ module Rails plugins.each { |p| p.load_generators } end - def initializers - initializers = Bootstrap.new(self).initializers - plugins.each { |p| initializers += p.initializers } - initializers += super - initializers - end - # TODO: Fix this method. It loads all railties independent if :all is given # or not, otherwise frameworks are never loaded. def plugins @@ -120,59 +117,30 @@ module Rails app.call(env) end - initializer :add_builtin_route, :before => :build_middleware_stack do |app| + def initializers + my = super + hook = my.index { |i| i.name == :set_autoload_paths } + 1 + initializers = Bootstrap.new(self).initializers + initializers += my[0...hook] + plugins.each { |p| initializers += p.initializers } + initializers += my[hook..-1] + initializers + end + + initializer :add_builtin_route do |app| if Rails.env.development? app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end - initializer :build_middleware_stack, :after => :load_application_initializers do + initializer :build_middleware_stack do app end - # Fires the user-supplied after_initialize block (Configuration#after_initialize) - initializer :after_initialize, :after => :build_middleware_stack do + # Fires the user-supplied after_initialize block (config#after_initialize) + initializer :after_initialize do config.after_initialize_blocks.each do |block| - block.call - end - end - - # Set the i18n configuration from config.i18n but special-case for the load_path which should be - # appended to what's already set instead of overwritten. - initializer :initialize_i18n do - require 'active_support/i18n' - - config.i18n.each do |setting, value| - if setting == :load_path - I18n.load_path += value - else - I18n.send("#{setting}=", value) - end - end - - ActionDispatch::Callbacks.to_prepare do - I18n.reload! - end - end - - initializer :set_clear_dependencies_hook do - unless config.cache_classes - ActionDispatch::Callbacks.after do - ActiveSupport::Dependencies.clear - end - end - end - - initializer :initialize_notifications do - require 'active_support/notifications' - - if config.colorize_logging == false - Rails::Subscriber.colorize_logging = false - config.generators.colorize_logging = false - end - - ActiveSupport::Notifications.subscribe do |*args| - Rails::Subscriber.dispatch(args) + block.call(self) end end diff --git a/railties/lib/rails/bootstrap.rb b/railties/lib/rails/bootstrap.rb index 3473f2fcaa..7c33955b2b 100644 --- a/railties/lib/rails/bootstrap.rb +++ b/railties/lib/rails/bootstrap.rb @@ -1,5 +1,5 @@ module Rails - class Bootstrap #< Railtie + class Bootstrap include Initializable def initialize(application) @@ -12,6 +12,15 @@ module Rails require "active_support/all" unless config.active_support.bare 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. + initializer :preload_frameworks do + require 'active_support/dependencies' + ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks + end + + # Initialize the logger early in the stack in case we need to log some deprecation. initializer :initialize_logger do Rails.logger ||= config.logger || begin logger = ActiveSupport::BufferedLogger.new(config.paths.log.to_a.first) @@ -29,32 +38,42 @@ module Rails end end - initializer :container do - # FIXME This is just a dumb initializer used as hook - 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. - initializer :preload_frameworks do - ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks - end - + # Initialize cache early in the stack so railties can make use of it. initializer :initialize_cache do unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) } if RAILS_CACHE.respond_to?(:middleware) - # Insert middleware to setup and teardown local cache for each request config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) end end end - # Sets the dependency loading mechanism based on the value of - # Configuration#cache_classes. + # Initialize rails subscriber on top of notifications. + initializer :initialize_subscriber do |app| + require 'active_support/notifications' + + if app.config.colorize_logging == false + Rails::Subscriber.colorize_logging = false + app.config.generators.colorize_logging = false + end + + ActiveSupport::Notifications.subscribe do |*args| + Rails::Subscriber.dispatch(args) + end + end + + initializer :set_clear_dependencies_hook do + unless config.cache_classes + ActionDispatch::Callbacks.after do + ActiveSupport::Dependencies.clear + end + end + end + + # Sets the dependency loading mechanism. + # TODO: Remove files from the $" and always use require. initializer :initialize_dependency_mechanism do - # TODO: Remove files from the $" and always use require ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 3ba27d79a7..76ca52867b 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,59 +1,112 @@ require 'active_support/ordered_options' module Rails - module SharedConfiguration - def self.middleware_stack - @default_middleware_stack ||= ActionDispatch::MiddlewareStack.new.tap do |middleware| - middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets }) - middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency }) - middleware.use('::Rack::Runtime') - middleware.use('::Rails::Rack::Logger') - middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local }) - middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes }) - middleware.use('::ActionDispatch::Cookies') - middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) - middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) - middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) }) - middleware.use('ActionDispatch::ParamsParser') - middleware.use('::Rack::MethodOverride') - middleware.use('::ActionDispatch::Head') + module Shared + # Those configuration values are shared between railtie, engines and so forth. + module Configuration + def middleware + @@default_middleware_stack ||= ActionDispatch::MiddlewareStack.new.tap do |middleware| + middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets }) + middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency }) + middleware.use('::Rack::Runtime') + middleware.use('::Rails::Rack::Logger') + middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local }) + middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes }) + middleware.use('::ActionDispatch::Cookies') + middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) + middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) + middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) }) + middleware.use('ActionDispatch::ParamsParser') + middleware.use('::Rack::MethodOverride') + middleware.use('::ActionDispatch::Head') + end + end + + # Holds generators configuration: + # + # config.generators do |g| + # g.orm :datamapper, :migration => true + # g.template_engine :haml + # g.test_framework :rspec + # end + # + # If you want to disable color in console, do: + # + # config.generators.colorize_logging = false + # + def generators + @@generators ||= GeneratorsConfiguration.new + if block_given? + yield @@generators + else + @@generators + end + end + + def after_initialize_blocks + @@after_initialize_blocks ||= [] + end + + def after_initialize(&blk) + after_initialize_blocks << blk if blk + end + + protected + + def options + @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } end end - def self.options - @options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } + class GeneratorsConfiguration #:nodoc: + attr_accessor :aliases, :options, :colorize_logging + + def initialize + @aliases = Hash.new { |h,k| h[k] = {} } + @options = Hash.new { |h,k| h[k] = {} } + @colorize_logging = true + end + + def method_missing(method, *args) + method = method.to_s.sub(/=$/, '').to_sym + + if method == :rails + namespace, configuration = :rails, args.shift + elsif args.first.is_a?(Hash) + namespace, configuration = method, args.shift + else + namespace, configuration = args.shift, args.shift + @options[:rails][method] = namespace + end + + if configuration + aliases = configuration.delete(:aliases) + @aliases[namespace].merge!(aliases) if aliases + @options[namespace].merge!(configuration) + end + end end end - # Temporarily separate the plugin configuration class from the main - # configuration class while this bit is being cleaned up. + # Holds Railtie basic configuration. It does not include configuration values + # related with load paths and the application specifics. class Railtie::Configuration + include Shared::Configuration + def self.default @default ||= new end - attr_reader :middleware - - def initialize - @options = SharedConfiguration.options - @middleware = SharedConfiguration.middleware_stack - end - def respond_to?(name) super || name.to_s =~ config_key_regexp end - protected - - attr_reader :options - private def method_missing(name, *args, &blk) if name.to_s =~ config_key_regexp - return $2 == '=' ? @options[$1] = args.first : @options[$1] + return $2 == '=' ? options[$1] = args.first : options[$1] end - super end @@ -68,8 +121,8 @@ module Rails end class Engine::Configuration < Railtie::Configuration - attr_reader :root - attr_accessor :eager_load_paths, :load_once_paths, :load_paths + attr_reader :root + attr_writer :eager_load_paths, :load_once_paths, :load_paths def initialize(root) @root = root @@ -86,8 +139,8 @@ module Rails paths.lib "lib", :load_path => true paths.config "config" paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" - paths.config.initializers "config/initializers" - paths.config.locales "config/locales" + paths.config.initializers "config/initializers", :glob => "**/*.rb" + paths.config.locales "config/locales", :glob => "*.{rb,yml}" paths.config.routes "config/routes.rb" paths end @@ -111,41 +164,35 @@ module Rails end class Configuration < Engine::Configuration - attr_accessor :after_initialize_blocks, :cache_classes, :colorize_logging, - :consider_all_requests_local, :dependency_loading, :filter_parameters, - :logger, :metals, :plugins, - :preload_frameworks, :reload_plugins, :serve_static_assets, - :time_zone, :whiny_nils + attr_accessor :cache_classes, :cache_store, :colorize_logging, + :consider_all_requests_local, :dependency_loading, + :filter_parameters, :log_level, :logger, :metals, + :plugins, :preload_frameworks, :reload_plugins, + :serve_static_assets, :time_zone, :whiny_nils - attr_writer :cache_store, :controller_paths, :i18n, :log_level - def initialize(*) + def initialize(*) super - @after_initialize_blocks = [] - @filter_parameters = [] - @dependency_loading = true - @serve_static_assets = true - end - - def after_initialize(&blk) - @after_initialize_blocks << blk if blk - end + @filter_parameters = [] + @dependency_loading = true + @serve_static_assets = true + end def paths @paths ||= begin paths = super - paths.app.controllers.concat(builtin_directories) + paths.app.controllers << builtin_controller if builtin_controller paths.config.database "config/database.yml" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" paths.tmp.cache "tmp/cache" - paths.vendor "vendor", :load_path => true + paths.vendor "vendor", :load_path => true paths.vendor.plugins "vendor/plugins" if File.exists?("#{root}/test/mocks/#{Rails.env}") ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " << "automatically to load paths anymore in future releases" - paths.mocks_path "test/mocks/#{Rails.env}", :load_path => true + paths.mocks_path "test/mocks", :load_path => true, :glob => Rails.env end paths @@ -182,6 +229,29 @@ module Rails YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result) end + def cache_store + @cache_store ||= begin + if File.exist?("#{root}/tmp/cache/") + [ :file_store, "#{root}/tmp/cache/" ] + else + :memory_store + end + end + end + + def builtin_controller + File.join(RAILTIES_PATH, "builtin", "rails_info") if Rails.env.development? + end + + def log_level + @log_level ||= Rails.env.production? ? :info : :debug + end + + def time_zone + @time_zone ||= "UTC" + end + + # Deprecated paths def view_path=(value) ActiveSupport::Deprecation.warn "config.view_path= is deprecated, " << "please do config.paths.app.views= instead", caller @@ -241,108 +311,5 @@ module Rails "please do config.paths.app.controllers instead", caller paths.app.controllers.to_a.uniq end - - def cache_store - @cache_store ||= begin - if File.exist?("#{root}/tmp/cache/") - [ :file_store, "#{root}/tmp/cache/" ] - else - :memory_store - end - end - end - - # Include builtins only in the development environment. - def builtin_directories - Rails.env.development? ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] - end - - def log_level - @log_level ||= Rails.env.production? ? :info : :debug - end - - def time_zone - @time_zone ||= "UTC" - end - - def i18n - @i18n ||= begin - i18n = ActiveSupport::OrderedOptions.new - i18n.load_path = [] - - if File.exist?(File.join(root, 'config', 'locales')) - i18n.load_path << Dir[File.join(root, 'config', 'locales', '*.{rb,yml}')] - i18n.load_path.flatten! - end - - i18n - end - end - - def environment_path - "#{root}/config/environments/#{Rails.env}.rb" - end - - # Holds generators configuration: - # - # config.generators do |g| - # g.orm :datamapper, :migration => true - # g.template_engine :haml - # g.test_framework :rspec - # end - # - # If you want to disable color in console, do: - # - # config.generators.colorize_logging = false - # - def generators - @generators ||= Generators.new - if block_given? - yield @generators - else - @generators - end - end - - # Allow Notifications queue to be modified or add subscriptions: - # - # config.notifications.queue = MyNewQueue.new - # - # config.notifications.subscribe /action_dispatch.show_exception/ do |*args| - # ExceptionDeliver.deliver_exception(args) - # end - # - def notifications - ActiveSupport::Notifications - end - - class Generators #:nodoc: - attr_accessor :aliases, :options, :colorize_logging - - def initialize - @aliases = Hash.new { |h,k| h[k] = {} } - @options = Hash.new { |h,k| h[k] = {} } - @colorize_logging = true - end - - def method_missing(method, *args) - method = method.to_s.sub(/=$/, '').to_sym - - if method == :rails - namespace, configuration = :rails, args.shift - elsif args.first.is_a?(Hash) - namespace, configuration = method, args.shift - else - namespace, configuration = args.shift, args.shift - @options[:rails][method] = namespace - end - - if configuration - aliases = configuration.delete(:aliases) - @aliases[namespace].merge!(aliases) if aliases - @options[namespace].merge!(configuration) - end - end - end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index effbfee6c1..93f39f176c 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -4,7 +4,6 @@ module Rails # TODO Move I18n here # TODO Set routes namespaces class Engine < Railtie - class << self attr_accessor :called_from @@ -49,8 +48,8 @@ module Rails delegate :middleware, :root, :to => :config # Add configured load paths to ruby load paths and remove duplicates. - initializer :set_load_path, :before => :container do - expand_load_path(config.load_paths).reverse_each do |path| + initializer :set_load_path do + config.load_paths.reverse_each do |path| $LOAD_PATH.unshift(path) if File.directory?(path) end $LOAD_PATH.uniq! @@ -58,11 +57,9 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths, :before => :container do - require 'active_support/dependencies' - - ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) - ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) + initializer :set_autoload_paths do + ActiveSupport::Dependencies.load_paths.concat(config.load_paths) + ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths @@ -74,31 +71,32 @@ module Rails end_error end - # Freeze the arrays so future modifications will fail rather than do nothing mysteriously + # Freeze so future modifications will fail rather than do nothing mysteriously config.load_once_paths.freeze end - # Routing must be initialized after plugins to allow the former to extend the routes initializer :add_routing_files do |app| - routes = select_existing(config.paths.config.routes) - app.route_configuration_files.concat(routes) + config.paths.config.routes.to_a.each do |route| + app.route_configuration_files << route if File.exists?(route) + end + end + + initializer :add_locales do + config.i18n.load_path.concat(config.paths.config.locales.to_a) end initializer :add_view_paths do - views = select_existing(config.paths.app.views) - ActionController::Base.view_paths.concat(views) if defined? ActionController - ActionMailer::Base.view_paths.concat(views) if defined? ActionMailer + views = config.paths.app.views.to_a + ActionController::Base.view_paths.concat(views) if defined?(ActionController) + ActionMailer::Base.view_paths.concat(views) if defined?(ActionMailer) end initializer :load_application_initializers do - select_existing(config.paths.config.initializers).each do |initializers| - Dir["#{initializers}/**/*.rb"].sort.each do |initializer| - load(initializer) - end + config.paths.config.initializers.each do |initializer| + load(initializer) end end - # Eager load application classes initializer :load_application_classes do |app| next if $rails_rake_task @@ -111,15 +109,5 @@ module Rails end end end - - private - - def select_existing(paths) - paths.to_a.select { |path| File.exists?(path) }.uniq - end - - def expand_load_path(load_paths) - load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq - end end end \ No newline at end of file diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 8fcb254590..cea4a0fdf7 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -19,12 +19,6 @@ module Rails @options[:after] end - def global - @options[:global] - end - - alias global? global - def run(*args) @context.instance_exec(*args, &block) end @@ -71,7 +65,7 @@ module Rails def initializers @initializers ||= begin - initializers = self.class.initializers_for(:instance) + initializers = self.class.initializers_chain Collection.new(initializers.map { |i| i.bind(self) }) end end @@ -81,26 +75,23 @@ module Rails @initializers ||= [] end - def initializers_for(scope = :global) + def initializers_chain initializers = Collection.new ancestors.reverse_each do |klass| next unless klass.respond_to?(:initializers) - initializers = initializers + klass.initializers.select { |i| - (scope == :global) == !!i.global? - } + initializers = initializers + klass.initializers end initializers end def initializer(name, opts = {}, &blk) raise ArgumentError, "A block must be passed when defining an initializer" unless blk - @initializers ||= [] - @initializers << Initializer.new(name, nil, opts, &blk) + initializers << Initializer.new(name, nil, opts, &blk) end def run_initializers(*args) return if @ran - initializers_for(:global).each do |initializer| + initializers_chain.each do |initializer| instance_exec(*args, &initializer.block) end @ran = true diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 754c0f1839..205840360c 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -29,7 +29,7 @@ module ApplicationTests add_to_config <<-RUBY config.root = "#{app_path}" - config.eager_load_paths = "#{app_path}/lib" + config.eager_load_paths << "#{app_path}/lib" RUBY require "#{app_path}/config/environment" @@ -132,7 +132,7 @@ module ApplicationTests require "#{app_path}/config/environment" assert_equal [ - "#{app_path}/config/locales/en.yml", "my/other/locale.yml" + "my/other/locale.yml", "#{app_path}/config/locales/en.yml" ], Rails.application.config.i18n.load_path end diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index db8605edbe..061bb34c19 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -1,17 +1,6 @@ require "isolation/abstract_unit" module ApplicationTests - class MyQueue - def publish(name, *args) - raise name - end - - # Not a full queue implementation - def method_missing(name, *args, &blk) - self - end - end - class MockLogger def method_missing(*args) @logged ||= [] @@ -39,22 +28,6 @@ module ApplicationTests ActiveSupport::Notifications.notifier.wait end - test "new queue is set" do - # We don't want to load all frameworks, so remove them and clean up environments. - use_frameworks [] - FileUtils.rm_rf("#{app_path}/config/environments") - - add_to_config <<-RUBY - config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new) - RUBY - - require "#{app_path}/config/environment" - - assert_raise RuntimeError do - ActiveSupport::Notifications.publish('foo') - end - end - test "rails subscribers are added" do add_to_config <<-RUBY config.colorize_logging = false diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index e308cbcb0e..0c7378cb64 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -10,14 +10,14 @@ module InitializableTests attr_accessor :foo, :bar end - initializer :omg, :global => true do + initializer :omg do @foo ||= 0 @foo += 1 end end class Bar < Foo - initializer :bar, :global => true do + initializer :bar do @bar ||= 0 @bar += 1 end @@ -26,7 +26,7 @@ module InitializableTests module Word include Rails::Initializable - initializer :word, :global => true do + initializer :word do $word = "bird" end end @@ -34,11 +34,11 @@ module InitializableTests class Parent include Rails::Initializable - initializer :one, :global => true do + initializer :one do $arr << 1 end - initializer :two, :global => true do + initializer :two do $arr << 2 end end @@ -46,17 +46,17 @@ module InitializableTests class Child < Parent include Rails::Initializable - initializer :three, :before => :one, :global => true do + initializer :three, :before => :one do $arr << 3 end - initializer :four, :after => :one, :global => true do + initializer :four, :after => :one do $arr << 4 end end class Parent - initializer :five, :before => :one, :global => true do + initializer :five, :before => :one do $arr << 5 end end @@ -72,11 +72,11 @@ module InitializableTests $arr << 2 end - initializer :three, :global => true do + initializer :three do $arr << 3 end - initializer :four, :global => true do + initializer :four do $arr << 4 end end @@ -181,13 +181,7 @@ module InitializableTests $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 + assert_equal [1, 2, 3, 4], $arr end end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 472566378d..904d2a6566 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -15,6 +15,7 @@ module InitializerTests config.root = "#{app_path}" config.i18n.load_path << "my/other/locale.yml" RUBY + require "#{app_path}/config/environment" #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml @@ -23,8 +24,8 @@ module InitializerTests #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml my/other/locale.yml + #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 76eb29bdf4..4f475fae11 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -45,7 +45,7 @@ module InitializerTests assert_path @paths.tmp, "tmp" assert_path @paths.tmp.cache, "tmp", "cache" assert_path @paths.config, "config" - assert_path @paths.config.locales, "config", "locales" + assert_path @paths.config.locales, "config", "locales", "en.yml" assert_path @paths.config.environment, "config", "environments", "development.rb" assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first -- cgit v1.2.3 From 4eab3aad8d256b868390b739b075bd38661339b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 02:03:11 +0100 Subject: Ensure user set load paths have higher preference and move Bootstrap inside Application. --- railties/lib/rails.rb | 1 - railties/lib/rails/application.rb | 121 ++++++++++++++++++---- railties/lib/rails/bootstrap.rb | 80 -------------- railties/lib/rails/configuration.rb | 3 +- railties/lib/rails/engine.rb | 4 +- railties/test/application/initializer_test.rb | 2 +- railties/test/initializer/initialize_i18n_test.rb | 2 +- 7 files changed, 105 insertions(+), 108 deletions(-) delete mode 100644 railties/lib/rails/bootstrap.rb (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index e3aa9e4c97..29afb672b6 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -8,7 +8,6 @@ require 'rails/initializable' require 'rails/railtie' require 'rails/plugin' require 'rails/engine' -require 'rails/bootstrap' require 'rails/application' require 'rails/railties_path' require 'rails/version' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9b0f39feb1..305d1c73e0 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,11 +2,14 @@ require 'fileutils' module Rails class Application < Engine - # TODO Clear up 2 way delegation flow between App class and instance. # Infact just add a method_missing on the class. # # TODO I'd like to track the "default app" different using an inherited hook. + # + # TODO Check helpers works as expected + # + # TODO Check routes namespaces class << self alias :configure :class_eval delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance @@ -118,36 +121,112 @@ module Rails end def initializers - my = super - hook = my.index { |i| i.name == :set_autoload_paths } + 1 - initializers = Bootstrap.new(self).initializers - initializers += my[0...hook] + initializers = Bootstrap.initializers + initializers += super plugins.each { |p| initializers += p.initializers } - initializers += my[hook..-1] + initializers += Finisher.initializers initializers end - initializer :add_builtin_route do |app| - if Rails.env.development? - app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + module Bootstrap + include Initializable + + initializer :load_all_active_support do |app| + require "active_support/all" unless app.config.active_support.bare end - end - initializer :build_middleware_stack do - app - 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. + initializer :preload_frameworks do |app| + require 'active_support/dependencies' + ActiveSupport::Autoload.eager_autoload! if app.config.preload_frameworks + end + + # Initialize the logger early in the stack in case we need to log some deprecation. + initializer :initialize_logger do |app| + Rails.logger ||= app.config.logger || begin + path = app.config.paths.log.to_a.first + logger = ActiveSupport::BufferedLogger.new(path) + logger.level = ActiveSupport::BufferedLogger.const_get(app.config.log_level.to_s.upcase) + logger.auto_flushing = false if Rails.env.production? + logger + rescue StandardError => e + logger = ActiveSupport::BufferedLogger.new(STDERR) + logger.level = ActiveSupport::BufferedLogger::WARN + logger.warn( + "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + + "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." + ) + logger + end + end + + # Initialize cache early in the stack so railties can make use of it. + initializer :initialize_cache do |app| + unless defined?(RAILS_CACHE) + silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(app.config.cache_store) } + + if RAILS_CACHE.respond_to?(:middleware) + app.config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) + end + end + end + + # Initialize rails subscriber on top of notifications. + initializer :initialize_subscriber do |app| + require 'active_support/notifications' + + if app.config.colorize_logging == false + Rails::Subscriber.colorize_logging = false + app.config.generators.colorize_logging = false + end - # Fires the user-supplied after_initialize block (config#after_initialize) - initializer :after_initialize do - config.after_initialize_blocks.each do |block| - block.call(self) + ActiveSupport::Notifications.subscribe do |*args| + Rails::Subscriber.dispatch(args) + end + end + + initializer :set_clear_dependencies_hook do |app| + unless app.config.cache_classes + ActionDispatch::Callbacks.after do + ActiveSupport::Dependencies.clear + end + end + end + + # Sets the dependency loading mechanism. + # TODO: Remove files from the $" and always use require. + initializer :initialize_dependency_mechanism do |app| + ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load end end - # Disable dependency loading during request cycle - initializer :disable_dependency_loading do - if config.cache_classes && !config.dependency_loading - ActiveSupport::Dependencies.unhook! + module Finisher + include Initializable + + initializer :add_builtin_route do |app| + if Rails.env.development? + app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + end + end + + initializer :build_middleware_stack do |app| + app.app + end + + # Fires the user-supplied after_initialize block (config#after_initialize) + initializer :after_initialize do |app| + app.config.after_initialize_blocks.each do |block| + block.call(app) + end + end + + # Disable dependency loading during request cycle + initializer :disable_dependency_loading do |app| + if app.config.cache_classes && !app.config.dependency_loading + ActiveSupport::Dependencies.unhook! + end end end end diff --git a/railties/lib/rails/bootstrap.rb b/railties/lib/rails/bootstrap.rb deleted file mode 100644 index 7c33955b2b..0000000000 --- a/railties/lib/rails/bootstrap.rb +++ /dev/null @@ -1,80 +0,0 @@ -module Rails - class Bootstrap - include Initializable - - def initialize(application) - @application = application - end - - delegate :config, :root, :to => :'@application' - - initializer :load_all_active_support do - require "active_support/all" unless config.active_support.bare - 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. - initializer :preload_frameworks do - require 'active_support/dependencies' - ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks - end - - # Initialize the logger early in the stack in case we need to log some deprecation. - initializer :initialize_logger do - Rails.logger ||= config.logger || begin - logger = ActiveSupport::BufferedLogger.new(config.paths.log.to_a.first) - logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) - logger.auto_flushing = false if Rails.env.production? - logger - rescue StandardError => e - logger = ActiveSupport::BufferedLogger.new(STDERR) - logger.level = ActiveSupport::BufferedLogger::WARN - logger.warn( - "Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. " + - "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." - ) - logger - end - end - - # Initialize cache early in the stack so railties can make use of it. - initializer :initialize_cache do - unless defined?(RAILS_CACHE) - silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) } - - if RAILS_CACHE.respond_to?(:middleware) - config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) - end - end - end - - # Initialize rails subscriber on top of notifications. - initializer :initialize_subscriber do |app| - require 'active_support/notifications' - - if app.config.colorize_logging == false - Rails::Subscriber.colorize_logging = false - app.config.generators.colorize_logging = false - end - - ActiveSupport::Notifications.subscribe do |*args| - Rails::Subscriber.dispatch(args) - end - end - - initializer :set_clear_dependencies_hook do - unless config.cache_classes - ActionDispatch::Callbacks.after do - ActiveSupport::Dependencies.clear - end - end - end - - # Sets the dependency loading mechanism. - # TODO: Remove files from the $" and always use require. - initializer :initialize_dependency_mechanism do - ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load - end - end -end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 76ca52867b..da2206d6a2 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -170,13 +170,12 @@ module Rails :plugins, :preload_frameworks, :reload_plugins, :serve_static_assets, :time_zone, :whiny_nils - def initialize(*) super @filter_parameters = [] @dependency_loading = true @serve_static_assets = true - end + end def paths @paths ||= begin diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 93f39f176c..03c78b6d4b 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -77,12 +77,12 @@ module Rails initializer :add_routing_files do |app| config.paths.config.routes.to_a.each do |route| - app.route_configuration_files << route if File.exists?(route) + app.route_configuration_files.unshift(route) if File.exists?(route) end end initializer :add_locales do - config.i18n.load_path.concat(config.paths.config.locales.to_a) + config.i18n.load_path.unshift(*config.paths.config.locales.to_a) end initializer :add_view_paths do diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 205840360c..6686d82f19 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -132,7 +132,7 @@ module ApplicationTests require "#{app_path}/config/environment" assert_equal [ - "my/other/locale.yml", "#{app_path}/config/locales/en.yml" + "#{app_path}/config/locales/en.yml", "my/other/locale.yml" ], Rails.application.config.i18n.load_path end diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 904d2a6566..64396bddb4 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -24,8 +24,8 @@ module InitializerTests #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - my/other/locale.yml #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml + my/other/locale.yml ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } end -- cgit v1.2.3 From 80130d1201c3bf9dc17b0e1fcd81c6b22e893b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 15:05:13 +0100 Subject: Extract routes reloading responsibilities from application and load them just upon a request. --- railties/lib/rails/application.rb | 67 +++++++---------------- railties/lib/rails/application/routes_reloader.rb | 46 ++++++++++++++++ railties/lib/rails/configuration.rb | 5 +- railties/lib/rails/console_app.rb | 3 +- railties/lib/rails/engine.rb | 6 +- railties/lib/rails/plugin.rb | 3 +- 6 files changed, 72 insertions(+), 58 deletions(-) create mode 100644 railties/lib/rails/application/routes_reloader.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 305d1c73e0..46d6bb4e7c 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,25 +2,20 @@ require 'fileutils' module Rails class Application < Engine - # TODO Clear up 2 way delegation flow between App class and instance. - # Infact just add a method_missing on the class. - # - # TODO I'd like to track the "default app" different using an inherited hook. - # + autoload :RoutesReloader, 'rails/application/routes_reloader' + # TODO Check helpers works as expected - # # TODO Check routes namespaces class << self - alias :configure :class_eval - delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance - private :new + alias :configure :class_eval + def instance @instance ||= new end def config - @config ||= Configuration.new(original_root) + @config ||= Configuration.new(self.original_root) end def original_root @@ -30,52 +25,35 @@ module Rails def inherited(base) super Railtie.plugins.delete(base) + Rails.application = base.instance end - def routes - ActionController::Routing::Routes + protected + + def method_missing(*args, &block) + instance.send(*args, &block) end end - delegate :routes, :to => :'self.class' - attr_reader :route_configuration_files - def initialize require_environment - Rails.application ||= self - @route_configuration_files = [] end - def initialize! - run_initializers(self) - self + def routes + ActionController::Routing::Routes end - - def routes_changed_at - routes_changed_at = nil - - route_configuration_files.each do |config| - config_changed_at = File.stat(config).mtime - if routes_changed_at.nil? || config_changed_at > routes_changed_at - routes_changed_at = config_changed_at - end - end - - routes_changed_at + def routes_reloader + @routes_reloader ||= RoutesReloader.new(config) end def reload_routes! - routes = Rails::Application.routes - routes.disable_clear_and_finalize = true - - routes.clear! - route_configuration_files.each { |config| load(config) } - routes.finalize! + routes_reloader.reload! + end - nil - ensure - routes.disable_clear_and_finalize = false + def initialize! + run_initializers(self) + self end def require_environment @@ -109,10 +87,7 @@ module Rails end def app - @app ||= begin - reload_routes! - middleware.build(routes) - end + @app ||= middleware.build(routes) end def call(env) @@ -207,7 +182,7 @@ module Rails initializer :add_builtin_route do |app| if Rails.env.development? - app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb new file mode 100644 index 0000000000..621bb1ccbd --- /dev/null +++ b/railties/lib/rails/application/routes_reloader.rb @@ -0,0 +1,46 @@ +module Rails + class Application + class RoutesReloader + attr_reader :config + + def initialize(config) + @config, @last_change_at = config, nil + end + + def changed_at + routes_changed_at = nil + + config.action_dispatch.route_files.each do |config| + config_changed_at = File.stat(config).mtime + + if routes_changed_at.nil? || config_changed_at > routes_changed_at + routes_changed_at = config_changed_at + end + end + + routes_changed_at + end + + def reload! + routes = Rails::Application.routes + routes.disable_clear_and_finalize = true + + routes.clear! + config.action_dispatch.route_files.each { |config| load(config) } + routes.finalize! + + nil + ensure + routes.disable_clear_and_finalize = false + end + + def reload_if_changed + current_change_at = changed_at + if @last_change_at != current_change_at + @last_change_at = current_change_at + reload! + end + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index da2206d6a2..5d0c7fd4b4 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -213,10 +213,7 @@ module Rails self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false - - if respond_to?(:action_controller) - action_controller.allow_concurrency = true - end + action_controller.allow_concurrency = true if respond_to?(:action_controller) self end diff --git a/railties/lib/rails/console_app.rb b/railties/lib/rails/console_app.rb index 2c4a7a51e8..98f7f774a9 100644 --- a/railties/lib/rails/console_app.rb +++ b/railties/lib/rails/console_app.rb @@ -26,7 +26,6 @@ end #reloads the environment def reload! puts "Reloading..." - ActionDispatch::Callbacks.new(lambda {}, true) - Rails.application.reload_routes! + ActionDispatch::Callbacks.new(lambda {}, true).call({}) true end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 03c78b6d4b..aaa669ef32 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,8 +1,6 @@ require 'active_support/core_ext/module/delegation' module Rails - # TODO Move I18n here - # TODO Set routes namespaces class Engine < Railtie class << self attr_accessor :called_from @@ -75,9 +73,9 @@ module Rails config.load_once_paths.freeze end - initializer :add_routing_files do |app| + initializer :add_routing_files do config.paths.config.routes.to_a.each do |route| - app.route_configuration_files.unshift(route) if File.exists?(route) + config.action_dispatch.route_files.unshift(route) if File.exists?(route) end end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index dde06bfcbd..43632127fc 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -60,8 +60,7 @@ module Rails initializer :add_routing_file, :after => :initialize_routing do |app| routing_file = "#{path}/config/routes.rb" if File.exist?(routing_file) - app.route_configuration_files << routing_file - app.reload_routes! + app.config.action_dispatch.route_files.unshift(routing_file) end end end -- cgit v1.2.3 From 4f036032152518791d379f47260236f619713fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 16:07:20 +0100 Subject: Break application.rb file in smaller chunks. --- railties/lib/rails/application.rb | 104 +--------------------------- railties/lib/rails/application/bootstrap.rb | 77 ++++++++++++++++++++ railties/lib/rails/application/finisher.rb | 31 +++++++++ 3 files changed, 110 insertions(+), 102 deletions(-) create mode 100644 railties/lib/rails/application/bootstrap.rb create mode 100644 railties/lib/rails/application/finisher.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 46d6bb4e7c..81606d09e4 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,6 +2,8 @@ require 'fileutils' module Rails class Application < Engine + autoload :Bootstrap, 'rails/application/bootstrap' + autoload :Finisher, 'rails/application/finisher' autoload :RoutesReloader, 'rails/application/routes_reloader' # TODO Check helpers works as expected @@ -102,107 +104,5 @@ module Rails initializers += Finisher.initializers initializers end - - module Bootstrap - include Initializable - - initializer :load_all_active_support do |app| - require "active_support/all" unless app.config.active_support.bare - 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. - initializer :preload_frameworks do |app| - require 'active_support/dependencies' - ActiveSupport::Autoload.eager_autoload! if app.config.preload_frameworks - end - - # Initialize the logger early in the stack in case we need to log some deprecation. - initializer :initialize_logger do |app| - Rails.logger ||= app.config.logger || begin - path = app.config.paths.log.to_a.first - logger = ActiveSupport::BufferedLogger.new(path) - logger.level = ActiveSupport::BufferedLogger.const_get(app.config.log_level.to_s.upcase) - logger.auto_flushing = false if Rails.env.production? - logger - rescue StandardError => e - logger = ActiveSupport::BufferedLogger.new(STDERR) - logger.level = ActiveSupport::BufferedLogger::WARN - logger.warn( - "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + - "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." - ) - logger - end - end - - # Initialize cache early in the stack so railties can make use of it. - initializer :initialize_cache do |app| - unless defined?(RAILS_CACHE) - silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(app.config.cache_store) } - - if RAILS_CACHE.respond_to?(:middleware) - app.config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) - end - end - end - - # Initialize rails subscriber on top of notifications. - initializer :initialize_subscriber do |app| - require 'active_support/notifications' - - if app.config.colorize_logging == false - Rails::Subscriber.colorize_logging = false - app.config.generators.colorize_logging = false - end - - ActiveSupport::Notifications.subscribe do |*args| - Rails::Subscriber.dispatch(args) - end - end - - initializer :set_clear_dependencies_hook do |app| - unless app.config.cache_classes - ActionDispatch::Callbacks.after do - ActiveSupport::Dependencies.clear - end - end - end - - # Sets the dependency loading mechanism. - # TODO: Remove files from the $" and always use require. - initializer :initialize_dependency_mechanism do |app| - ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load - end - end - - module Finisher - include Initializable - - initializer :add_builtin_route do |app| - if Rails.env.development? - app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') - end - end - - initializer :build_middleware_stack do |app| - app.app - end - - # Fires the user-supplied after_initialize block (config#after_initialize) - initializer :after_initialize do |app| - app.config.after_initialize_blocks.each do |block| - block.call(app) - end - end - - # Disable dependency loading during request cycle - initializer :disable_dependency_loading do |app| - if app.config.cache_classes && !app.config.dependency_loading - ActiveSupport::Dependencies.unhook! - end - end - end end end diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb new file mode 100644 index 0000000000..819d00be4e --- /dev/null +++ b/railties/lib/rails/application/bootstrap.rb @@ -0,0 +1,77 @@ +module Rails + class Application + module Bootstrap + include Initializable + + initializer :load_all_active_support do |app| + require "active_support/all" unless app.config.active_support.bare + 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. + initializer :preload_frameworks do |app| + require 'active_support/dependencies' + ActiveSupport::Autoload.eager_autoload! if app.config.preload_frameworks + end + + # Initialize the logger early in the stack in case we need to log some deprecation. + initializer :initialize_logger do |app| + Rails.logger ||= app.config.logger || begin + path = app.config.paths.log.to_a.first + logger = ActiveSupport::BufferedLogger.new(path) + logger.level = ActiveSupport::BufferedLogger.const_get(app.config.log_level.to_s.upcase) + logger.auto_flushing = false if Rails.env.production? + logger + rescue StandardError => e + logger = ActiveSupport::BufferedLogger.new(STDERR) + logger.level = ActiveSupport::BufferedLogger::WARN + logger.warn( + "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + + "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." + ) + logger + end + end + + # Initialize cache early in the stack so railties can make use of it. + initializer :initialize_cache do |app| + unless defined?(RAILS_CACHE) + silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(app.config.cache_store) } + + if RAILS_CACHE.respond_to?(:middleware) + app.config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) + end + end + end + + # Initialize rails subscriber on top of notifications. + initializer :initialize_subscriber do |app| + require 'active_support/notifications' + + if app.config.colorize_logging == false + Rails::Subscriber.colorize_logging = false + app.config.generators.colorize_logging = false + end + + ActiveSupport::Notifications.subscribe do |*args| + Rails::Subscriber.dispatch(args) + end + end + + initializer :set_clear_dependencies_hook do |app| + unless app.config.cache_classes + ActionDispatch::Callbacks.after do + ActiveSupport::Dependencies.clear + end + end + end + + # Sets the dependency loading mechanism. + # TODO: Remove files from the $" and always use require. + initializer :initialize_dependency_mechanism do |app| + ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb new file mode 100644 index 0000000000..4e7fffd0b3 --- /dev/null +++ b/railties/lib/rails/application/finisher.rb @@ -0,0 +1,31 @@ +module Rails + class Application + module Finisher + include Initializable + + initializer :add_builtin_route do |app| + if Rails.env.development? + app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + end + end + + initializer :build_middleware_stack do |app| + app.app + end + + # Fires the user-supplied after_initialize block (config#after_initialize) + initializer :after_initialize do |app| + app.config.after_initialize_blocks.each do |block| + block.call(app) + end + end + + # Disable dependency loading during request cycle + initializer :disable_dependency_loading do |app| + if app.config.cache_classes && !app.config.dependency_loading + ActiveSupport::Dependencies.unhook! + end + end + end + end +end \ No newline at end of file -- cgit v1.2.3 From 13d66cdf2544af0d465d596383743b16b5005996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 16:59:32 +0100 Subject: Extract Railtie load from application. --- railties/lib/rails/application.rb | 59 ++++++++++++----------- railties/lib/rails/application/railties.rb | 31 ++++++++++++ railties/lib/rails/application/routes_reloader.rb | 14 ++++-- railties/lib/rails/configuration.rb | 2 + railties/lib/rails/engine.rb | 9 ++-- railties/lib/rails/railtie.rb | 14 +++--- 6 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 railties/lib/rails/application/railties.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 81606d09e4..8f562350b4 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -4,6 +4,7 @@ module Rails class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Finisher, 'rails/application/finisher' + autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' # TODO Check helpers works as expected @@ -25,9 +26,22 @@ module Rails end def inherited(base) + # TODO Add this check + # raise "You cannot have more than one Rails::Application" if Rails.application super - Railtie.plugins.delete(base) - Rails.application = base.instance + + # TODO Add a test which ensures me + # Railtie.plugins.delete(base) + Rails.application ||= base.instance + + base.rake_tasks do + require "rails/tasks" + paths.lib.tasks.to_a.sort.each { |r| load(rake) } + task :environment do + $rails_rake_task = true + initialize! + end + end end protected @@ -38,11 +52,16 @@ module Rails end def initialize - require_environment + environment = config.paths.config.environment.to_a.first + require environment if environment end def routes - ActionController::Routing::Routes + ::ActionController::Routing::Routes + end + + def railties + @railties ||= Railties.new(config) end def routes_reloader @@ -58,34 +77,16 @@ module Rails self end - def require_environment - environment = config.paths.config.environment.to_a.first - require environment if environment - end - def load_tasks - require "rails/tasks" - plugins.each { |p| p.load_tasks } - # Load all application tasks - # TODO: extract out the path to the rake tasks - Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } - task :environment do - $rails_rake_task = true - initialize! - end + super + railties.all { |r| r.load_tasks } + self end def load_generators - plugins.each { |p| p.load_generators } - end - - # TODO: Fix this method. It loads all railties independent if :all is given - # or not, otherwise frameworks are never loaded. - def plugins - @plugins ||= begin - plugin_names = (config.plugins || [:all]).map { |p| p.to_sym } - Railtie.plugins.map(&:new) + Plugin.all(plugin_names, config.paths.vendor.plugins) - end + super + railties.all { |r| r.load_generators } + self end def app @@ -100,7 +101,7 @@ module Rails def initializers initializers = Bootstrap.initializers initializers += super - plugins.each { |p| initializers += p.initializers } + railties.all { |r| initializers += r.initializers } initializers += Finisher.initializers initializers end diff --git a/railties/lib/rails/application/railties.rb b/railties/lib/rails/application/railties.rb new file mode 100644 index 0000000000..d167d9bf4f --- /dev/null +++ b/railties/lib/rails/application/railties.rb @@ -0,0 +1,31 @@ +module Rails + class Application + class Railties + # TODO Write tests + def initialize(config) + @config = config + end + + def all(&block) + @all ||= railties + engines + plugins + @all.each(&block) if block + @all + end + + def railties + @railties ||= ::Rails::Railtie.subclasses.map(&:new) + end + + def engines + @engines ||= ::Rails::Engine.subclasses.map(&:new) + end + + def plugins + @plugins ||= begin + plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym } + Plugin.all(plugin_names, @config.paths.vendor.plugins) + end + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 621bb1ccbd..6d61de2320 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,8 +1,8 @@ module Rails class Application class RoutesReloader - attr_reader :config - + # TODO Change config.action_dispatch.route_files to config.action_dispatch.routes_path + # TODO Write tests def initialize(config) @config, @last_change_at = config, nil end @@ -10,8 +10,8 @@ module Rails def changed_at routes_changed_at = nil - config.action_dispatch.route_files.each do |config| - config_changed_at = File.stat(config).mtime + files.each do |file| + config_changed_at = File.stat(file).mtime if routes_changed_at.nil? || config_changed_at > routes_changed_at routes_changed_at = config_changed_at @@ -26,7 +26,7 @@ module Rails routes.disable_clear_and_finalize = true routes.clear! - config.action_dispatch.route_files.each { |config| load(config) } + files.each { |file| load(file) } routes.finalize! nil @@ -41,6 +41,10 @@ module Rails reload! end end + + def files + @config.action_dispatch.route_files + end end end end \ No newline at end of file diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 5d0c7fd4b4..b8bed01cdc 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -115,6 +115,7 @@ module Rails /^(#{bits})(?:=)?$/ end + # TODO Fix me def config_keys Railtie.plugin_names.map { |n| n.to_s }.uniq end @@ -182,6 +183,7 @@ module Rails paths = super paths.app.controllers << builtin_controller if builtin_controller paths.config.database "config/database.yml" + paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" paths.tmp.cache "tmp/cache" diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index aaa669ef32..cf6ca7c3f5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -4,6 +4,7 @@ module Rails class Engine < Railtie class << self attr_accessor :called_from + delegate :middleware, :root, :paths, :to => :config def original_root @original_root ||= find_root_with_file_flag("lib") @@ -18,7 +19,6 @@ module Rails call_stack = caller.map { |p| p.split(':').first } File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) end - super end @@ -33,17 +33,14 @@ module Rails end root = File.exist?("#{root_path}/#{flag}") ? root_path : default - raise "Could not find root path for #{self}" unless root RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? - Pathname.new(root).expand_path : - Pathname.new(root).realpath + Pathname.new(root).expand_path : Pathname.new(root).realpath end end - delegate :config, :to => :'self.class' - delegate :middleware, :root, :to => :config + delegate :middleware, :paths, :root, :config, :to => :'self.class' # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 5b97fabe40..84f7a86946 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -5,26 +5,30 @@ module Rails ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application) class << self + attr_reader :subclasses + def abstract_railtie?(base) ABSTRACT_RAILTIES.include?(base.name) end def inherited(base) - @@plugins ||= [] - @@plugins << base unless abstract_railtie?(base) + @subclasses ||= [] + @subclasses << base unless abstract_railtie?(base) end - # This should be called railtie_name and engine_name + # TODO This should be called railtie_name and engine_name def plugin_name(plugin_name = nil) @plugin_name ||= name.demodulize.underscore @plugin_name = plugin_name if plugin_name @plugin_name end + # TODO Deprecate me def plugins - @@plugins + @subclasses end + # TODO Deprecate me def plugin_names plugins.map { |p| p.plugin_name } end @@ -59,12 +63,10 @@ module Rails end def load_tasks - return unless rake_tasks rake_tasks.each { |blk| blk.call } end def load_generators - return unless generators generators.each { |blk| blk.call } end end -- cgit v1.2.3 From 924fa084e81b8b2f5ae9eab93d6b711c2b6b89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:13:25 +0100 Subject: First steps into making Plugin < Engine. --- railties/lib/rails/application.rb | 5 +++++ railties/lib/rails/application/finisher.rb | 12 ++++++++++++ railties/lib/rails/engine.rb | 20 ++++++++++---------- railties/lib/rails/paths.rb | 3 ++- railties/test/paths_test.rb | 7 +++++++ 5 files changed, 36 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 8f562350b4..1286d437c7 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -51,6 +51,11 @@ module Rails end end + # Application is always reloadable when config.cache_classes is false. + def reloadable?(app) + true + end + def initialize environment = config.paths.config.environment.to_a.first require environment if environment diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 4e7fffd0b3..2ac881ac11 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -3,6 +3,18 @@ module Rails module Finisher include Initializable + initializer :ensure_load_once_paths_as_subset do + extra = ActiveSupport::Dependencies.load_once_paths - + ActiveSupport::Dependencies.load_paths + + unless extra.empty? + abort <<-end_error + load_once_paths must be a subset of the load_paths. + Extra items in load_once_paths: #{extra * ','} + end_error + end + end + initializer :add_builtin_route do |app| if Rails.env.development? app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index cf6ca7c3f5..b11c1ac73e 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -42,6 +42,10 @@ module Rails delegate :middleware, :paths, :root, :config, :to => :'self.class' + def reloadable?(app) + app.config.reload_plugins + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do config.load_paths.reverse_each do |path| @@ -52,21 +56,17 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths do + initializer :set_autoload_paths do |app| ActiveSupport::Dependencies.load_paths.concat(config.load_paths) - ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) - - extra = ActiveSupport::Dependencies.load_once_paths - - ActiveSupport::Dependencies.load_paths - unless extra.empty? - abort <<-end_error - load_once_paths must be a subset of the load_paths. - Extra items in load_once_paths: #{extra * ','} - end_error + if reloadable?(app) + ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) + else + ActiveSupport::Dependencies.load_once_paths.concat(config.load_paths) end # Freeze so future modifications will fail rather than do nothing mysteriously + config.load_paths.freeze config.load_once_paths.freeze end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index d81af3c709..069371aa9c 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -73,7 +73,7 @@ module Rails @load_once = @options[:load_once] @eager_load = @options[:eager_load] - @load_path = @options[:load_path] || @eager_load + @load_path = @options[:load_path] || @eager_load || @load_once @root.all_paths << self end @@ -98,6 +98,7 @@ module Rails def load_once! @load_once = true + @load_path = true end def load_once? diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 001282bb0d..343926340a 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -222,4 +222,11 @@ class PathsTest < ActiveSupport::TestCase @root.app.eager_load! assert_equal ["/foo/bar/app"], @root.load_paths end + + test "adding a path to the load once paths also adds it to the load path" do + @root.app = "app" + @root.app.load_once! + assert_equal ["/foo/bar/app"], @root.load_paths + end + end -- cgit v1.2.3 From 2b75b94ac0c329de12a0a94ba77f8aad5574514f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:51:48 +0100 Subject: Plugin is now an Engine. --- railties/lib/rails.rb | 2 +- railties/lib/rails/application.rb | 1 - railties/lib/rails/configuration.rb | 15 ++++--- railties/lib/rails/engine.rb | 11 +++++- railties/lib/rails/plugin.rb | 78 +++++++++++++------------------------ 5 files changed, 46 insertions(+), 61 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 29afb672b6..667587cdce 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -6,8 +6,8 @@ require 'active_support/core_ext/logger' require 'rails/initializable' require 'rails/railtie' -require 'rails/plugin' require 'rails/engine' +require 'rails/plugin' require 'rails/application' require 'rails/railties_path' require 'rails/version' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1286d437c7..6d1702bf93 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -36,7 +36,6 @@ module Rails base.rake_tasks do require "rails/tasks" - paths.lib.tasks.to_a.sort.each { |r| load(rake) } task :environment do $rails_rake_task = true initialize! diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index b8bed01cdc..900173abcc 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -125,19 +125,19 @@ module Rails attr_reader :root attr_writer :eager_load_paths, :load_once_paths, :load_paths - def initialize(root) + def initialize(root=nil) @root = root - super() end def paths @paths ||= begin paths = Rails::Application::Root.new(@root) - paths.app "app", :eager_load => true, :glob => "*" - paths.app.controllers "app/controllers", :eager_load => true - paths.app.metals "app/metal", :eager_load => true + paths.app "app", :eager_load => true, :glob => "*" + paths.app.controllers "app/controllers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true paths.app.views "app/views" - paths.lib "lib", :load_path => true + paths.lib "lib", :load_path => true + paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.config "config" paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" paths.config.initializers "config/initializers", :glob => "**/*.rb" @@ -183,7 +183,6 @@ module Rails paths = super paths.app.controllers << builtin_controller if builtin_controller paths.config.database "config/database.yml" - paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" paths.tmp.cache "tmp/cache" @@ -215,7 +214,7 @@ module Rails self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false - action_controller.allow_concurrency = true if respond_to?(:action_controller) + self.action_controller.allow_concurrency = true if respond_to?(:action_controller) self end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b11c1ac73e..39afac0604 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -40,12 +40,21 @@ module Rails end end - delegate :middleware, :paths, :root, :config, :to => :'self.class' + delegate :middleware, :paths, :root, :to => :config + + def config + self.class.config + end def reloadable?(app) app.config.reload_plugins end + def load_tasks + super + config.paths.lib.tasks.to_a.sort.each { |ext| load(ext) } + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do config.load_paths.reverse_each do |path| diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 43632127fc..b4fd503631 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,67 +1,45 @@ module Rails - class Plugin < Railtie - def self.all(list, paths) - plugins = [] - paths.each do |path| - Dir["#{path}/*"].each do |plugin_path| - plugin = new(plugin_path) - next unless list.include?(plugin.name) || list.include?(:all) - plugins << plugin - end + class Plugin < Engine + class << self + def inherited(base) + raise "You should not inherit from Rails::Plugin" end - plugins.sort_by do |p| - [list.index(p.name) || list.index(:all), p.name.to_s] + def config + raise "Plugins does not provide configuration at the class level" end - end - - attr_reader :name, :path - - def initialize(path) - @name = File.basename(path).to_sym - @path = path - end - - def load_paths - Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"] - end - - def load_tasks - Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext } - end - - initializer :add_to_load_path, :after => :set_autoload_paths do |app| - load_paths.each do |path| - $LOAD_PATH << path - require "active_support/dependencies" - ActiveSupport::Dependencies.load_paths << path + def all(list, paths) + plugins = [] + paths.each do |path| + Dir["#{path}/*"].each do |plugin_path| + plugin = new(plugin_path) + next unless list.include?(plugin.name) || list.include?(:all) + plugins << plugin + end + end - unless app.config.reload_plugins - ActiveSupport::Dependencies.load_once_paths << path + plugins.sort_by do |p| + [list.index(p.name) || list.index(:all), p.name.to_s] end end end - initializer :load_init_rb, :before => :load_application_initializers do |app| - file = "#{@path}/init.rb" - config = app.config - eval File.read(file), binding, file if File.file?(file) + attr_reader :name, :path + + def initialize(root) + @name = File.basename(root).to_sym + config.root = root end - initializer :add_view_paths, :after => :initialize_framework_views do - plugin_views = "#{path}/app/views" - if File.directory?(plugin_views) - ActionController::Base.view_paths.concat([plugin_views]) if defined? ActionController - ActionMailer::Base.view_paths.concat([plugin_views]) if defined? ActionMailer - end + def config + @config ||= Engine::Configuration.new end - initializer :add_routing_file, :after => :initialize_routing do |app| - routing_file = "#{path}/config/routes.rb" - if File.exist?(routing_file) - app.config.action_dispatch.route_files.unshift(routing_file) - end + initializer :load_init_rb do |app| + file = Dir["#{root}/{rails/init,init}.rb"].first + config = app.config + eval(File.read(file), binding, file) if file && File.file?(file) end end end -- cgit v1.2.3 From 788fce2550ed587d86d239d8fcd488f919d15b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 18:41:53 +0100 Subject: Create configurable modules and ensure that they are added only on direct children. --- railties/lib/rails/application.rb | 58 +++++++++++++++--------------- railties/lib/rails/engine.rb | 38 ++++++++------------ railties/lib/rails/engine/configurable.rb | 24 +++++++++++++ railties/lib/rails/plugin.rb | 32 +++++++---------- railties/lib/rails/railtie.rb | 34 ++++++++++++------ railties/lib/rails/railtie/configurable.rb | 23 ++++++++++++ 6 files changed, 128 insertions(+), 81 deletions(-) create mode 100644 railties/lib/rails/engine/configurable.rb create mode 100644 railties/lib/rails/railtie/configurable.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 6d1702bf93..676e395d39 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -9,6 +9,8 @@ module Rails # TODO Check helpers works as expected # TODO Check routes namespaces + # TODO raise "You cannot have more than one Rails::Application" if Rails.application + # TODO Ensure production settings are read properly class << self private :new alias :configure :class_eval @@ -17,30 +19,10 @@ module Rails @instance ||= new end - def config - @config ||= Configuration.new(self.original_root) - end - - def original_root - @original_root ||= find_root_with_file_flag("config.ru", Dir.pwd) - end - def inherited(base) - # TODO Add this check - # raise "You cannot have more than one Rails::Application" if Rails.application super - - # TODO Add a test which ensures me - # Railtie.plugins.delete(base) - Rails.application ||= base.instance - - base.rake_tasks do - require "rails/tasks" - task :environment do - $rails_rake_task = true - initialize! - end - end + Rails.application = base.instance + base.require_environment! end protected @@ -50,16 +32,15 @@ module Rails end end - # Application is always reloadable when config.cache_classes is false. - def reloadable?(app) - true - end - - def initialize + def require_environment! environment = config.paths.config.environment.to_a.first require environment if environment end + def config + @config ||= ::Rails::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) + end + def routes ::ActionController::Routing::Routes end @@ -82,12 +63,14 @@ module Rails end def load_tasks + initialize_tasks super railties.all { |r| r.load_tasks } self end def load_generators + initialize_generators super railties.all { |r| r.load_generators } self @@ -109,5 +92,24 @@ module Rails initializers += Finisher.initializers initializers end + + protected + + def initialize_tasks + require "rails/tasks" + task :environment do + $rails_rake_task = true + initialize! + end + end + + def initialize_generators + require "rails/generators" + end + + # Application is always reloadable when config.cache_classes is false. + def reloadable?(app) + true + end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 39afac0604..b373b931f9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -2,29 +2,23 @@ require 'active_support/core_ext/module/delegation' module Rails class Engine < Railtie + autoload :Configurable, "rails/engine/configurable" + class << self attr_accessor :called_from - delegate :middleware, :root, :paths, :to => :config - - def original_root - @original_root ||= find_root_with_file_flag("lib") - end - - def config - @config ||= Configuration.new(original_root) - end def inherited(base) - base.called_from = begin - call_stack = caller.map { |p| p.split(':').first } - File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + unless abstract_railtie?(base) + base.called_from = begin + call_stack = caller.map { |p| p.split(':').first } + File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + end end + super end - protected - - def find_root_with_file_flag(flag, default=nil) + def find_root_with_flag(flag, default=nil) root_path = self.called_from while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") @@ -42,14 +36,6 @@ module Rails delegate :middleware, :paths, :root, :to => :config - def config - self.class.config - end - - def reloadable?(app) - app.config.reload_plugins - end - def load_tasks super config.paths.lib.tasks.to_a.sort.each { |ext| load(ext) } @@ -113,5 +99,11 @@ module Rails end end end + + protected + + def reloadable?(app) + app.config.reload_plugins + end end end \ No newline at end of file diff --git a/railties/lib/rails/engine/configurable.rb b/railties/lib/rails/engine/configurable.rb new file mode 100644 index 0000000000..fb420e8a12 --- /dev/null +++ b/railties/lib/rails/engine/configurable.rb @@ -0,0 +1,24 @@ +module Rails + class Engine + module Configurable + def self.included(base) + base.extend ClassMethods + base.delegate :middleware, :root, :paths, :to => :config + end + + module ClassMethods + def config + @config ||= Configuration.new(find_root_with_flag("lib")) + end + + def inherited(base) + raise "You cannot inherit from a Rails::Engine child" + end + end + + def config + self.class.config + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index b4fd503631..cb3fdc8501 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,27 +1,21 @@ module Rails class Plugin < Engine - class << self - def inherited(base) - raise "You should not inherit from Rails::Plugin" - end - - def config - raise "Plugins does not provide configuration at the class level" - end + def self.inherited(base) + raise "You cannot inherit from Rails::Plugin" + end - def all(list, paths) - plugins = [] - paths.each do |path| - Dir["#{path}/*"].each do |plugin_path| - plugin = new(plugin_path) - next unless list.include?(plugin.name) || list.include?(:all) - plugins << plugin - end + def self.all(list, paths) + plugins = [] + paths.each do |path| + Dir["#{path}/*"].each do |plugin_path| + plugin = new(plugin_path) + next unless list.include?(plugin.name) || list.include?(:all) + plugins << plugin end + end - plugins.sort_by do |p| - [list.index(p.name) || list.index(:all), p.name.to_s] - end + plugins.sort_by do |p| + [list.index(p.name) || list.index(:all), p.name.to_s] end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 84f7a86946..208b017348 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,19 +1,21 @@ module Rails class Railtie + autoload :Configurable, "rails/railtie/configurable" + include Initializable ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application) class << self - attr_reader :subclasses - - def abstract_railtie?(base) - ABSTRACT_RAILTIES.include?(base.name) + def subclasses + @subclasses ||= [] end def inherited(base) - @subclasses ||= [] - @subclasses << base unless abstract_railtie?(base) + unless abstract_railtie?(base) + base.send(:include, self::Configurable) if add_configurable?(base) + subclasses << base + end end # TODO This should be called railtie_name and engine_name @@ -25,7 +27,7 @@ module Rails # TODO Deprecate me def plugins - @subclasses + subclasses end # TODO Deprecate me @@ -33,10 +35,6 @@ module Rails plugins.map { |p| p.plugin_name } end - def config - Configuration.default - end - def subscriber(subscriber) Rails::Subscriber.add(plugin_name, subscriber) end @@ -52,6 +50,20 @@ module Rails @generators << blk if blk @generators end + + protected + + def abstract_railtie?(base) + ABSTRACT_RAILTIES.include?(base.name) + end + + # Just add configurable behavior if a Configurable module is defined + # and the class is a direct child from self. This is required to avoid + # application or plugins getting class configuration method from Railties + # and/or Engines. + def add_configurable?(base) + defined?(self::Configurable) && base.ancestors[1] == self + end end def rake_tasks diff --git a/railties/lib/rails/railtie/configurable.rb b/railties/lib/rails/railtie/configurable.rb new file mode 100644 index 0000000000..3850efa4a7 --- /dev/null +++ b/railties/lib/rails/railtie/configurable.rb @@ -0,0 +1,23 @@ +module Rails + class Railtie + module Configurable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def config + @config ||= Configuration.new + end + + def inherited(base) + raise "You cannot inherit from a Rails::Railtie child" + end + end + + def config + self.class.config + end + end + end +end -- cgit v1.2.3 From b17e358e3df34c03019e357f693611618092e1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 22:30:17 +0100 Subject: Move configuration to subfolders. --- railties/lib/rails.rb | 8 - railties/lib/rails/application.rb | 7 +- railties/lib/rails/application/configuration.rb | 85 +++++++ railties/lib/rails/configuration.rb | 292 +++++++----------------- railties/lib/rails/engine.rb | 4 +- railties/lib/rails/engine/configurable.rb | 2 +- railties/lib/rails/engine/configuration.rb | 48 ++++ railties/lib/rails/paths.rb | 2 +- railties/lib/rails/plugin.rb | 4 + railties/lib/rails/railtie.rb | 6 +- railties/lib/rails/railtie/configurable.rb | 2 +- railties/lib/rails/railtie/configuration.rb | 9 + railties/test/initializer/path_test.rb | 6 +- railties/test/paths_test.rb | 12 +- 14 files changed, 252 insertions(+), 235 deletions(-) create mode 100644 railties/lib/rails/application/configuration.rb create mode 100644 railties/lib/rails/engine/configuration.rb create mode 100644 railties/lib/rails/railtie/configuration.rb (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 667587cdce..623555e7c1 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -4,16 +4,8 @@ require 'active_support' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/logger' -require 'rails/initializable' -require 'rails/railtie' -require 'rails/engine' -require 'rails/plugin' require 'rails/application' -require 'rails/railties_path' require 'rails/version' -require 'rails/rack' -require 'rails/paths' -require 'rails/configuration' require 'rails/deprecation' require 'rails/subscriber' require 'rails/ruby_version_check' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 676e395d39..504a241da8 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,8 +1,13 @@ require 'fileutils' +require 'rails/railties_path' +require 'rails/railtie' +require 'rails/engine' +require 'rails/plugin' module Rails class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' + autoload :Configuration, 'rails/application/configuration' autoload :Finisher, 'rails/application/finisher' autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' @@ -38,7 +43,7 @@ module Rails end def config - @config ||= ::Rails::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) + @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) end def routes diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb new file mode 100644 index 0000000000..aaf18b5f51 --- /dev/null +++ b/railties/lib/rails/application/configuration.rb @@ -0,0 +1,85 @@ +require 'rails/engine/configuration' + +module Rails + class Application + class Configuration < ::Rails::Engine::Configuration + include ::Rails::Configuration::Deprecated + + attr_accessor :cache_classes, :cache_store, :colorize_logging, + :consider_all_requests_local, :dependency_loading, + :filter_parameters, :log_level, :logger, :metals, + :plugins, :preload_frameworks, :reload_plugins, + :serve_static_assets, :time_zone, :whiny_nils + + def initialize(*) + super + @filter_parameters = [] + @dependency_loading = true + @serve_static_assets = true + end + + def paths + @paths ||= begin + paths = super + paths.app.controllers << builtin_controller if builtin_controller + paths.config.database "config/database.yml" + paths.log "log/#{Rails.env}.log" + paths.tmp "tmp" + paths.tmp.cache "tmp/cache" + paths.vendor "vendor", :load_path => true + paths.vendor.plugins "vendor/plugins" + + if File.exists?("#{root}/test/mocks/#{Rails.env}") + ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " << + "automatically to load paths anymore in future releases" + paths.mocks_path "test/mocks", :load_path => true, :glob => Rails.env + end + + paths + end + end + + # Enable threaded mode. Allows concurrent requests to controller actions and + # multiple database connections. Also disables automatic dependency loading + # after boot, and disables reloading code on every request, as these are + # fundamentally incompatible with thread safety. + def threadsafe! + self.preload_frameworks = true + self.cache_classes = true + self.dependency_loading = false + self.action_controller.allow_concurrency = true if respond_to?(:action_controller) + self + end + + # Loads and returns the contents of the #database_configuration_file. The + # contents of the file are processed via ERB before being sent through + # YAML::load. + def database_configuration + require 'erb' + YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result) + end + + def cache_store + @cache_store ||= begin + if File.exist?("#{root}/tmp/cache/") + [ :file_store, "#{root}/tmp/cache/" ] + else + :memory_store + end + end + end + + def builtin_controller + File.join(RAILTIES_PATH, "builtin", "rails_info") if Rails.env.development? + end + + def log_level + @log_level ||= Rails.env.production? ? :info : :debug + end + + def time_zone + @time_zone ||= "UTC" + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 900173abcc..e0bd12497f 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,9 +1,10 @@ require 'active_support/ordered_options' +require 'rails/paths' +require 'rails/rack' module Rails - module Shared - # Those configuration values are shared between railtie, engines and so forth. - module Configuration + module Configuration + module Shared def middleware @@default_middleware_stack ||= ActionDispatch::MiddlewareStack.new.tap do |middleware| middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets }) @@ -35,7 +36,7 @@ module Rails # config.generators.colorize_logging = false # def generators - @@generators ||= GeneratorsConfiguration.new + @@generators ||= Rails::Configuration::Generators.new if block_given? yield @@generators else @@ -51,14 +52,34 @@ module Rails after_initialize_blocks << blk if blk end - protected + def respond_to?(name) + super || name.to_s =~ config_key_regexp + end + + private + + def method_missing(name, *args, &blk) + if name.to_s =~ config_key_regexp + return $2 == '=' ? options[$1] = args.first : options[$1] + end + super + end + + def config_key_regexp + bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|') + /^(#{bits})(?:=)?$/ + end + + def config_keys + (Railtie.plugin_names + Engine.plugin_names).map { |n| n.to_s }.uniq + end def options @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } end end - class GeneratorsConfiguration #:nodoc: + class Generators #:nodoc: attr_accessor :aliases, :options, :colorize_logging def initialize @@ -86,227 +107,74 @@ module Rails end end end - end - # Holds Railtie basic configuration. It does not include configuration values - # related with load paths and the application specifics. - class Railtie::Configuration - include Shared::Configuration - - def self.default - @default ||= new - end - - def respond_to?(name) - super || name.to_s =~ config_key_regexp - end - - private - - def method_missing(name, *args, &blk) - if name.to_s =~ config_key_regexp - return $2 == '=' ? options[$1] = args.first : options[$1] + module Deprecated + def frameworks(*args) + raise "config.frameworks in no longer supported. See the generated " \ + "config/boot.rb for steps on how to limit the frameworks that " \ + "will be loaded" end - super - end - - def config_key_regexp - bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|') - /^(#{bits})(?:=)?$/ - end + alias :frameworks= :frameworks - # TODO Fix me - def config_keys - Railtie.plugin_names.map { |n| n.to_s }.uniq - end - end - - class Engine::Configuration < Railtie::Configuration - attr_reader :root - attr_writer :eager_load_paths, :load_once_paths, :load_paths - - def initialize(root=nil) - @root = root - end - - def paths - @paths ||= begin - paths = Rails::Application::Root.new(@root) - paths.app "app", :eager_load => true, :glob => "*" - paths.app.controllers "app/controllers", :eager_load => true - paths.app.metals "app/metal", :eager_load => true - paths.app.views "app/views" - paths.lib "lib", :load_path => true - paths.lib.tasks "lib/tasks", :glob => "**/*.rake" - paths.config "config" - paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" - paths.config.initializers "config/initializers", :glob => "**/*.rb" - paths.config.locales "config/locales", :glob => "*.{rb,yml}" - paths.config.routes "config/routes.rb" - paths + def view_path=(value) + ActiveSupport::Deprecation.warn "config.view_path= is deprecated, " << + "please do config.paths.app.views= instead", caller + paths.app.views = value end - end - - def root=(value) - @root = paths.path = Pathname.new(value).expand_path - end - - def eager_load_paths - @eager_load_paths ||= paths.eager_load - end - - def load_once_paths - @eager_load_paths ||= paths.load_once - end - - def load_paths - @load_paths ||= paths.load_paths - end - end - - class Configuration < Engine::Configuration - attr_accessor :cache_classes, :cache_store, :colorize_logging, - :consider_all_requests_local, :dependency_loading, - :filter_parameters, :log_level, :logger, :metals, - :plugins, :preload_frameworks, :reload_plugins, - :serve_static_assets, :time_zone, :whiny_nils - - def initialize(*) - super - @filter_parameters = [] - @dependency_loading = true - @serve_static_assets = true - end - def paths - @paths ||= begin - paths = super - paths.app.controllers << builtin_controller if builtin_controller - paths.config.database "config/database.yml" - paths.log "log/#{Rails.env}.log" - paths.tmp "tmp" - paths.tmp.cache "tmp/cache" - paths.vendor "vendor", :load_path => true - paths.vendor.plugins "vendor/plugins" - - if File.exists?("#{root}/test/mocks/#{Rails.env}") - ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " << - "automatically to load paths anymore in future releases" - paths.mocks_path "test/mocks", :load_path => true, :glob => Rails.env - end - - paths + def view_path + ActiveSupport::Deprecation.warn "config.view_path is deprecated, " << + "please do config.paths.app.views instead", caller + paths.app.views.to_a.first end - end - - def frameworks(*args) - raise "config.frameworks in no longer supported. See the generated " \ - "config/boot.rb for steps on how to limit the frameworks that " \ - "will be loaded" - end - alias frameworks= frameworks - - # Enable threaded mode. Allows concurrent requests to controller actions and - # multiple database connections. Also disables automatic dependency loading - # after boot, and disables reloading code on every request, as these are - # fundamentally incompatible with thread safety. - def threadsafe! - self.preload_frameworks = true - self.cache_classes = true - self.dependency_loading = false - self.action_controller.allow_concurrency = true if respond_to?(:action_controller) - self - end - - # Loads and returns the contents of the #database_configuration_file. The - # contents of the file are processed via ERB before being sent through - # YAML::load. - def database_configuration - require 'erb' - YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result) - end - def cache_store - @cache_store ||= begin - if File.exist?("#{root}/tmp/cache/") - [ :file_store, "#{root}/tmp/cache/" ] - else - :memory_store - end + def routes_configuration_file=(value) + ActiveSupport::Deprecation.warn "config.routes_configuration_file= is deprecated, " << + "please do config.paths.config.routes= instead", caller + paths.config.routes = value end - end - - def builtin_controller - File.join(RAILTIES_PATH, "builtin", "rails_info") if Rails.env.development? - end - - def log_level - @log_level ||= Rails.env.production? ? :info : :debug - end - - def time_zone - @time_zone ||= "UTC" - end - # Deprecated paths - def view_path=(value) - ActiveSupport::Deprecation.warn "config.view_path= is deprecated, " << - "please do config.paths.app.views= instead", caller - paths.app.views = value - end - - def view_path - ActiveSupport::Deprecation.warn "config.view_path is deprecated, " << - "please do config.paths.app.views instead", caller - paths.app.views.to_a.first - end - - def routes_configuration_file=(value) - ActiveSupport::Deprecation.warn "config.routes_configuration_file= is deprecated, " << - "please do config.paths.config.routes= instead", caller - paths.config.routes = value - end - - def routes_configuration_file - ActiveSupport::Deprecation.warn "config.routes_configuration_file is deprecated, " << - "please do config.paths.config.routes instead", caller - paths.config.routes.to_a.first - end + def routes_configuration_file + ActiveSupport::Deprecation.warn "config.routes_configuration_file is deprecated, " << + "please do config.paths.config.routes instead", caller + paths.config.routes.to_a.first + end - def database_configuration_file=(value) - ActiveSupport::Deprecation.warn "config.database_configuration_file= is deprecated, " << - "please do config.paths.config.database= instead", caller - paths.config.database = value - end + def database_configuration_file=(value) + ActiveSupport::Deprecation.warn "config.database_configuration_file= is deprecated, " << + "please do config.paths.config.database= instead", caller + paths.config.database = value + end - def database_configuration_file - ActiveSupport::Deprecation.warn "config.database_configuration_file is deprecated, " << - "please do config.paths.config.database instead", caller - paths.config.database.to_a.first - end + def database_configuration_file + ActiveSupport::Deprecation.warn "config.database_configuration_file is deprecated, " << + "please do config.paths.config.database instead", caller + paths.config.database.to_a.first + end - def log_path=(value) - ActiveSupport::Deprecation.warn "config.log_path= is deprecated, " << - "please do config.paths.log= instead", caller - paths.config.log = value - end + def log_path=(value) + ActiveSupport::Deprecation.warn "config.log_path= is deprecated, " << + "please do config.paths.log= instead", caller + paths.config.log = value + end - def log_path - ActiveSupport::Deprecation.warn "config.log_path is deprecated, " << - "please do config.paths.log instead", caller - paths.config.log.to_a.first - end + def log_path + ActiveSupport::Deprecation.warn "config.log_path is deprecated, " << + "please do config.paths.log instead", caller + paths.config.log.to_a.first + end - def controller_paths=(value) - ActiveSupport::Deprecation.warn "config.controller_paths= is deprecated, " << - "please do config.paths.app.controllers= instead", caller - paths.app.controllers = value - end + def controller_paths=(value) + ActiveSupport::Deprecation.warn "config.controller_paths= is deprecated, " << + "please do config.paths.app.controllers= instead", caller + paths.app.controllers = value + end - def controller_paths - ActiveSupport::Deprecation.warn "config.controller_paths is deprecated, " << - "please do config.paths.app.controllers instead", caller - paths.app.controllers.to_a.uniq + def controller_paths + ActiveSupport::Deprecation.warn "config.controller_paths is deprecated, " << + "please do config.paths.app.controllers instead", caller + paths.app.controllers.to_a.uniq + end end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b373b931f9..d972050dc9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,8 +1,10 @@ require 'active_support/core_ext/module/delegation' +require 'rails/railtie' module Rails class Engine < Railtie - autoload :Configurable, "rails/engine/configurable" + autoload :Configurable, "rails/engine/configurable" + autoload :Configuration, "rails/engine/configuration" class << self attr_accessor :called_from diff --git a/railties/lib/rails/engine/configurable.rb b/railties/lib/rails/engine/configurable.rb index fb420e8a12..d4b7ecc532 100644 --- a/railties/lib/rails/engine/configurable.rb +++ b/railties/lib/rails/engine/configurable.rb @@ -8,7 +8,7 @@ module Rails module ClassMethods def config - @config ||= Configuration.new(find_root_with_flag("lib")) + @config ||= Engine::Configuration.new(find_root_with_flag("lib")) end def inherited(base) diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb new file mode 100644 index 0000000000..e2fdf125d3 --- /dev/null +++ b/railties/lib/rails/engine/configuration.rb @@ -0,0 +1,48 @@ +require 'rails/railtie/configuration' + +module Rails + class Engine + class Configuration < ::Rails::Railtie::Configuration + attr_reader :root + attr_writer :eager_load_paths, :load_once_paths, :load_paths + + def initialize(root=nil) + @root = root + end + + def paths + @paths ||= begin + paths = Rails::Paths::Root.new(@root) + paths.app "app", :eager_load => true, :glob => "*" + paths.app.controllers "app/controllers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true + paths.app.views "app/views" + paths.lib "lib", :load_path => true + paths.lib.tasks "lib/tasks", :glob => "**/*.rake" + paths.config "config" + paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" + paths.config.initializers "config/initializers", :glob => "**/*.rb" + paths.config.locales "config/locales", :glob => "*.{rb,yml}" + paths.config.routes "config/routes.rb" + paths + end + end + + def root=(value) + @root = paths.path = Pathname.new(value).expand_path + end + + def eager_load_paths + @eager_load_paths ||= paths.eager_load + end + + def load_once_paths + @eager_load_paths ||= paths.load_once + end + + def load_paths + @load_paths ||= paths.load_paths + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 069371aa9c..88c0c1c68c 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -1,7 +1,7 @@ require 'set' module Rails - class Application + module Paths module PathParent def method_missing(id, *args) name = id.to_s diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index cb3fdc8501..394e634903 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,9 +1,13 @@ +require 'rails/engine' + module Rails class Plugin < Engine def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end + # TODO Right now, if a plugin has an Engine or a Railtie inside it, + # the initializers for this plugin will be executed twice. def self.all(list, paths) plugins = [] paths.each do |path| diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 208b017348..6424be5a55 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,6 +1,10 @@ +require 'rails/initializable' +require 'rails/configuration' + module Rails class Railtie - autoload :Configurable, "rails/railtie/configurable" + autoload :Configurable, "rails/railtie/configurable" + autoload :Configuration, "rails/railtie/configuration" include Initializable diff --git a/railties/lib/rails/railtie/configurable.rb b/railties/lib/rails/railtie/configurable.rb index 3850efa4a7..a2eb938c5a 100644 --- a/railties/lib/rails/railtie/configurable.rb +++ b/railties/lib/rails/railtie/configurable.rb @@ -7,7 +7,7 @@ module Rails module ClassMethods def config - @config ||= Configuration.new + @config ||= Railtie::Configuration.new end def inherited(base) diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb new file mode 100644 index 0000000000..bfb43f7041 --- /dev/null +++ b/railties/lib/rails/railtie/configuration.rb @@ -0,0 +1,9 @@ +require 'rails/configuration' + +module Rails + class Railtie + class Configuration + include Rails::Configuration::Shared + 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 4f475fae11..54bdddbdf2 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -79,17 +79,17 @@ module InitializerTests test "controller paths include builtin in development mode" do Rails.env.replace "development" - assert Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end test "controller paths does not have builtin_directories in test mode" do Rails.env.replace "test" - assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end test "controller paths does not have builtin_directories in production mode" do Rails.env.replace "production" - assert !Rails::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } end end diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 343926340a..eafe7a64e1 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -3,22 +3,22 @@ require 'rails/paths' class PathsTest < ActiveSupport::TestCase def setup - @root = Rails::Application::Root.new("/foo/bar") + @root = Rails::Paths::Root.new("/foo/bar") end test "the paths object is initialized with the root path" do - root = Rails::Application::Root.new("/fiz/baz") + root = Rails::Paths::Root.new("/fiz/baz") assert_equal "/fiz/baz", root.path end test "the paths object can be initialized with nil" do assert_nothing_raised do - Rails::Application::Root.new(nil) + Rails::Paths::Root.new(nil) end end test "a paths object initialized with nil can be updated" do - root = Rails::Application::Root.new(nil) + root = Rails::Paths::Root.new(nil) root.app = "app" root.path = "/root" assert_equal ["/root/app"], root.app.to_a @@ -30,7 +30,7 @@ class PathsTest < ActiveSupport::TestCase end test "raises exception if root path never set" do - root = Rails::Application::Root.new(nil) + root = Rails::Paths::Root.new(nil) root.app = "app" assert_raises RuntimeError do root.app.to_a @@ -110,7 +110,7 @@ class PathsTest < ActiveSupport::TestCase end test "the root can only have one physical path" do - assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } + assert_raise(RuntimeError) { Rails::Paths::Root.new(["/fiz", "/biz"]) } assert_raise(RuntimeError) { @root.push "/biz" } assert_raise(RuntimeError) { @root.unshift "/biz" } assert_raise(RuntimeError) { @root.concat ["/biz"]} -- cgit v1.2.3 From d3c40242a58a8863cd216f6639f93df5fdb0c075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 23:02:43 +0100 Subject: Move console stuff to its own directory. --- railties/lib/rails/commands/console.rb | 8 ++++---- railties/lib/rails/console/app.rb | 31 ++++++++++++++++++++++++++++++ railties/lib/rails/console/helpers.rb | 5 +++++ railties/lib/rails/console/sandbox.rb | 6 ++++++ railties/lib/rails/console_app.rb | 31 ------------------------------ railties/lib/rails/console_sandbox.rb | 6 ------ railties/lib/rails/console_with_helpers.rb | 5 ----- railties/test/application/console_test.rb | 4 ++-- 8 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 railties/lib/rails/console/app.rb create mode 100644 railties/lib/rails/console/helpers.rb create mode 100644 railties/lib/rails/console/sandbox.rb delete mode 100644 railties/lib/rails/console_app.rb delete mode 100644 railties/lib/rails/console_sandbox.rb delete mode 100644 railties/lib/rails/console_with_helpers.rb (limited to 'railties') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 27ac7fd20a..a984eff6e2 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -1,6 +1,6 @@ require 'optparse' require 'irb' -require "irb/completion" +require 'irb/completion' module Rails class Console @@ -24,9 +24,9 @@ module Rails end @app.initialize! - require "rails/console_app" - require "rails/console_sandbox" if options[:sandbox] - require "rails/console_with_helpers" + require "rails/console/app" + require "rails/console/sandbox" if options[:sandbox] + require "rails/console/helpers" if options[:debugger] begin diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb new file mode 100644 index 0000000000..98f7f774a9 --- /dev/null +++ b/railties/lib/rails/console/app.rb @@ -0,0 +1,31 @@ +require 'active_support/all' +require 'active_support/test_case' +require 'action_controller' + +# work around the at_exit hook in test/unit, which kills IRB +Test::Unit.run = true if Test::Unit.respond_to?(:run=) + +# reference the global "app" instance, created on demand. To recreate the +# instance, pass a non-false value as the parameter. +def app(create=false) + @app_integration_instance = nil if create + @app_integration_instance ||= new_session do |sess| + sess.host! "www.example.com" + end +end + +# create a new session. If a block is given, the new session will be yielded +# to the block before being returned. +def new_session + app = ActionController::Dispatcher.new + session = ActionController::Integration::Session.new(app) + yield session if block_given? + session +end + +#reloads the environment +def reload! + puts "Reloading..." + ActionDispatch::Callbacks.new(lambda {}, true).call({}) + true +end diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb new file mode 100644 index 0000000000..039db667c4 --- /dev/null +++ b/railties/lib/rails/console/helpers.rb @@ -0,0 +1,5 @@ +def helper + @helper ||= ApplicationController.helpers +end + +@controller = ApplicationController.new diff --git a/railties/lib/rails/console/sandbox.rb b/railties/lib/rails/console/sandbox.rb new file mode 100644 index 0000000000..65a3d68619 --- /dev/null +++ b/railties/lib/rails/console/sandbox.rb @@ -0,0 +1,6 @@ +ActiveRecord::Base.connection.increment_open_transactions +ActiveRecord::Base.connection.begin_db_transaction +at_exit do + ActiveRecord::Base.connection.rollback_db_transaction + ActiveRecord::Base.connection.decrement_open_transactions +end diff --git a/railties/lib/rails/console_app.rb b/railties/lib/rails/console_app.rb deleted file mode 100644 index 98f7f774a9..0000000000 --- a/railties/lib/rails/console_app.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'active_support/all' -require 'active_support/test_case' -require 'action_controller' - -# work around the at_exit hook in test/unit, which kills IRB -Test::Unit.run = true if Test::Unit.respond_to?(:run=) - -# reference the global "app" instance, created on demand. To recreate the -# instance, pass a non-false value as the parameter. -def app(create=false) - @app_integration_instance = nil if create - @app_integration_instance ||= new_session do |sess| - sess.host! "www.example.com" - end -end - -# create a new session. If a block is given, the new session will be yielded -# to the block before being returned. -def new_session - app = ActionController::Dispatcher.new - session = ActionController::Integration::Session.new(app) - yield session if block_given? - session -end - -#reloads the environment -def reload! - puts "Reloading..." - ActionDispatch::Callbacks.new(lambda {}, true).call({}) - true -end diff --git a/railties/lib/rails/console_sandbox.rb b/railties/lib/rails/console_sandbox.rb deleted file mode 100644 index 65a3d68619..0000000000 --- a/railties/lib/rails/console_sandbox.rb +++ /dev/null @@ -1,6 +0,0 @@ -ActiveRecord::Base.connection.increment_open_transactions -ActiveRecord::Base.connection.begin_db_transaction -at_exit do - ActiveRecord::Base.connection.rollback_db_transaction - ActiveRecord::Base.connection.decrement_open_transactions -end diff --git a/railties/lib/rails/console_with_helpers.rb b/railties/lib/rails/console_with_helpers.rb deleted file mode 100644 index 039db667c4..0000000000 --- a/railties/lib/rails/console_with_helpers.rb +++ /dev/null @@ -1,5 +0,0 @@ -def helper - @helper ||= ApplicationController.helpers -end - -@controller = ApplicationController.new diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index e8a4a4e158..22ab60f4a0 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -9,8 +9,8 @@ class ConsoleTest < Test::Unit::TestCase # Load steps taken from rails/commands/console.rb require "#{rails_root}/config/environment" - require 'rails/console_app' - require 'rails/console_with_helpers' + require 'rails/console/app' + require 'rails/console/helpers' end def test_app_method_should_return_integration_session -- cgit v1.2.3 From 2fde9d774b322fc708990675671231c64c691a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:00:18 +0100 Subject: Solve some pendencies. --- railties/lib/rails/application.rb | 5 ++--- railties/lib/rails/application/finisher.rb | 2 +- railties/lib/rails/application/railties.rb | 2 +- railties/lib/rails/application/routes_reloader.rb | 13 ++++++------- railties/lib/rails/engine.rb | 4 ++-- railties/lib/rails/paths.rb | 23 ++++++++++++++--------- railties/lib/rails/plugin.rb | 9 +++++++-- railties/test/paths_test.rb | 1 + railties/test/plugins/configuration_test.rb | 6 +++--- 9 files changed, 37 insertions(+), 28 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 504a241da8..a8ff125342 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,8 +1,7 @@ require 'fileutils' require 'rails/railties_path' -require 'rails/railtie' -require 'rails/engine' require 'rails/plugin' +require 'rails/engine' module Rails class Application < Engine @@ -14,7 +13,6 @@ module Rails # TODO Check helpers works as expected # TODO Check routes namespaces - # TODO raise "You cannot have more than one Rails::Application" if Rails.application # TODO Ensure production settings are read properly class << self private :new @@ -25,6 +23,7 @@ module Rails end def inherited(base) + raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance base.require_environment! diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 2ac881ac11..db19011b7f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -17,7 +17,7 @@ module Rails initializer :add_builtin_route do |app| if Rails.env.development? - app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + app.config.action_dispatch.route_paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/application/railties.rb b/railties/lib/rails/application/railties.rb index d167d9bf4f..b3e6693f89 100644 --- a/railties/lib/rails/application/railties.rb +++ b/railties/lib/rails/application/railties.rb @@ -1,7 +1,7 @@ module Rails class Application class Railties - # TODO Write tests + # TODO Write tests for this behavior extracted from Application def initialize(config) @config = config end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 6d61de2320..d861d27465 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,8 +1,7 @@ module Rails class Application class RoutesReloader - # TODO Change config.action_dispatch.route_files to config.action_dispatch.routes_path - # TODO Write tests + # TODO Write tests for this behavior extracted from Application def initialize(config) @config, @last_change_at = config, nil end @@ -10,8 +9,8 @@ module Rails def changed_at routes_changed_at = nil - files.each do |file| - config_changed_at = File.stat(file).mtime + paths.each do |path| + config_changed_at = File.stat(path).mtime if routes_changed_at.nil? || config_changed_at > routes_changed_at routes_changed_at = config_changed_at @@ -26,7 +25,7 @@ module Rails routes.disable_clear_and_finalize = true routes.clear! - files.each { |file| load(file) } + paths.each { |path| load(path) } routes.finalize! nil @@ -42,8 +41,8 @@ module Rails end end - def files - @config.action_dispatch.route_files + def paths + @config.action_dispatch.route_paths end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index d972050dc9..cc878ac8f2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -67,9 +67,9 @@ module Rails config.load_once_paths.freeze end - initializer :add_routing_files do + initializer :add_routing_paths do config.paths.config.routes.to_a.each do |route| - config.action_dispatch.route_files.unshift(route) if File.exists?(route) + config.action_dispatch.route_paths.unshift(route) if File.exists?(route) end end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 88c0c1c68c..55874813da 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -31,22 +31,21 @@ module Rails @all_paths = [] end - def load_once - all_paths.map { |path| path.paths if path.load_once? }.compact.flatten.uniq + def all_paths + @all_paths.uniq! + @all_paths end - def eager_load - all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq + def load_once + filter { |path| path.paths if path.load_once? } end - # TODO Discover why do we need to call uniq! here - def all_paths - @all_paths.uniq! - @all_paths + def eager_load + filter { |path| path.paths if path.eager_load? } end def load_paths - all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq + filter { |path| path.paths if path.load_path? } end def push(*) @@ -56,6 +55,12 @@ module Rails alias unshift push alias << push alias concat push + + protected + + def filter(&block) + all_paths.map(&block).compact.flatten.uniq.select { |p| File.exists?(p) } + end end class Path diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 394e634903..62dc7f30f8 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -6,8 +6,6 @@ module Rails raise "You cannot inherit from Rails::Plugin" end - # TODO Right now, if a plugin has an Engine or a Railtie inside it, - # the initializers for this plugin will be executed twice. def self.all(list, paths) plugins = [] paths.each do |path| @@ -39,5 +37,12 @@ module Rails config = app.config eval(File.read(file), binding, file) if file && File.file?(file) end + + # TODO Write tests for this sanity check + initializer :sanity_check_railties_collision do + if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s) + raise "The plugin #{name.inspect} is a Railtie or an Engine and cannot be installed as Plugin" + end + end end end diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index eafe7a64e1..92c7b2ba0e 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -3,6 +3,7 @@ require 'rails/paths' class PathsTest < ActiveSupport::TestCase def setup + File.stubs(:exists?).returns(true) @root = Rails::Paths::Root.new("/foo/bar") end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 09f8943af9..c59040c712 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -26,11 +26,11 @@ module PluginsTest test "plugin config merges are deep" do class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end - class MyApp < Rails::Application + class Bar < Rails::Railtie config.foo.bar = "bar" end - assert_equal "hello", MyApp.config.foo.greetings - assert_equal "bar", MyApp.config.foo.bar + assert_equal "hello", Bar.config.foo.greetings + assert_equal "bar", Bar.config.foo.bar end test "plugin can add subscribers" do -- cgit v1.2.3 From 5b26fa48755c461619f7d48f4cd28faa9db442f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:42:28 +0100 Subject: Make plugin generator compatible with new schema. --- railties/lib/generators/rails/plugin/plugin_generator.rb | 2 +- .../rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt | 4 ++++ .../generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt | 4 ---- railties/test/generators/plugin_generator_test.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 railties/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt delete mode 100644 railties/lib/generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt (limited to 'railties') diff --git a/railties/lib/generators/rails/plugin/plugin_generator.rb b/railties/lib/generators/rails/plugin/plugin_generator.rb index b68b8691db..8f01dcd589 100644 --- a/railties/lib/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/generators/rails/plugin/plugin_generator.rb @@ -17,7 +17,7 @@ module Rails def create_tasks_files return unless options[:tasks] - directory 'tasks', plugin_dir('tasks') + directory 'lib/tasks', plugin_dir('lib/tasks') end hook_for :generator do |generator| diff --git a/railties/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt b/railties/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt new file mode 100644 index 0000000000..72920a9d3a --- /dev/null +++ b/railties/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :<%= file_name %> do +# # Task goes here +# end diff --git a/railties/lib/generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt b/railties/lib/generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt deleted file mode 100644 index 72920a9d3a..0000000000 --- a/railties/lib/generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :<%= file_name %> do -# # Task goes here -# end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 0a79e2cfb8..065dbe1423 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -48,7 +48,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_creates_tasks_if_required run_generator ["plugin_fu", "--tasks"] - assert_file "vendor/plugins/plugin_fu/tasks/plugin_fu_tasks.rake" + assert_file "vendor/plugins/plugin_fu/lib/tasks/plugin_fu_tasks.rake" end def test_creates_generator_if_required -- cgit v1.2.3 From 25724c664d8af6c50903709da69a5871475383fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:47:55 +0100 Subject: Load deprecated tasks for plugins. --- railties/lib/rails/plugin.rb | 11 +++++++++++ railties/test/plugins/vendored_test.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 62dc7f30f8..b47679d140 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -23,6 +23,17 @@ module Rails attr_reader :name, :path + def load_tasks + super + extra_tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"] + + unless extra_tasks.empty? + ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " << + "PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead" + extra_tasks.sort.each { |ext| load(ext) } + end + end + def initialize(root) @name = File.basename(root).to_sym config.root = root diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index b3b85891b2..eae73ee5d8 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -145,6 +145,40 @@ module PluginsTest response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit")) assert_equal "I am a Sprokkit", response[2].join end + + test "tasks are loaded by default" do + $executed = false + @plugin.write "lib/tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + + test "deprecated tasks are also loaded" do + $executed = false + @plugin.write "tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From 5cd9aad4fdf55c591fe8e12657008e83315251d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 10:27:42 +0100 Subject: Add I18n tests to engines. --- railties/test/initializer/initialize_i18n_test.rb | 56 ----------------------- railties/test/plugins/vendored_test.rb | 38 +++++++++++++++ 2 files changed, 38 insertions(+), 56 deletions(-) delete mode 100644 railties/test/initializer/initialize_i18n_test.rb (limited to 'railties') diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb deleted file mode 100644 index 64396bddb4..0000000000 --- a/railties/test/initializer/initialize_i18n_test.rb +++ /dev/null @@ -1,56 +0,0 @@ -require "isolation/abstract_unit" - -module InitializerTests - class InitializeI18nTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_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 - add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.load_path << "my/other/locale.yml" - RUBY - - require "#{app_path}/config/environment" - - #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml - assert_equal %W( - #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml - my/other/locale.yml - ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } - end - - test "i18n finds locale files in engines" do - # app_file "vendor/plugins/engine/init.rb", "" - # app_file "vendor/plugins/engine/app/models/hellos.rb", "class Hello ; end" - # app_file "vendor/plugins/engine/lib/omg.rb", "puts 'omg'" - # app_file "vendor/plugins/engine/config/locales/en.yml", "hello:" - # - # Rails::Initializer.run do |c| - # c.root = app_path - # c.i18n.load_path << "my/other/locale.yml" - # end - # Rails.initialize! - # - # #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml - # assert_equal %W( - # #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml - # #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml - # #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml - # #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - # #{app_path}/config/locales/en.yml - # my/other/locale.yml - # #{app_path}/vendor/plugins/engine/config/locales/en.yml - # ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } - end - end -end \ No newline at end of file diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index eae73ee5d8..6207cd13c1 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -179,6 +179,44 @@ module PluginsTest Rake::Task[:foo].invoke assert $executed end + + test "i18n files are added with lower priority than application ones" do + add_to_config <<-RUBY + config.i18n.load_path << "#{app_path}/app/locales/en.yml" + RUBY + + app_file 'app/locales/en.yml', <<-YAML +en: + bar: "1" +YAML + + app_file 'config/locales/en.yml', <<-YAML +en: + foo: "2" + bar: "2" +YAML + + @plugin.write 'config/locales/en.yml', <<-YAML +en: + foo: "3" +YAML + + boot_rails + require "#{app_path}/config/environment" + + assert_equal %W( + #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml + #{app_path}/vendor/plugins/bukkits/config/locales/en.yml + #{app_path}/config/locales/en.yml + #{app_path}/app/locales/en.yml + ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } + + assert_equal "2", I18n.t(:foo) + assert_equal "1", I18n.t(:bar) + end end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From e0bdc4f446686a498c3117e27ed8561f5c6d34f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 11:06:06 +0100 Subject: Ensure namespaced controllers in engines work. --- railties/lib/rails/engine.rb | 10 ++++++++++ railties/lib/rails/tasks/routes.rake | 1 + railties/test/plugins/vendored_test.rb | 32 +++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index cc878ac8f2..6f724963b2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -73,6 +73,16 @@ module Rails end end + initializer :add_routing_namespaces do |app| + config.paths.app.controllers.to_a.each do |load_path| + load_path = File.expand_path(load_path) + Dir["#{load_path}/*/*_controller.rb"].collect do |path| + namespace = File.dirname(path).sub(/#{load_path}\/?/, '') + app.routes.controller_namespaces << namespace unless namespace.empty? + end + end + end + initializer :add_locales do config.i18n.load_path.unshift(*config.paths.config.locales.to_a) end diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 2395d73b2f..e8da72db4d 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,5 +1,6 @@ desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' task :routes => :environment do + Rails::Application.reload_routes! 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 diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 6207cd13c1..1fc8766def 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -17,6 +17,10 @@ module PluginsTest require "#{app_path}/config/environment" end + def app + @app ||= Rails.application + end + test "it loads the plugin's init.rb file" do boot_rails assert_equal "loaded", BUKKITS @@ -202,7 +206,6 @@ en: YAML boot_rails - require "#{app_path}/config/environment" assert_equal %W( #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml @@ -217,6 +220,33 @@ YAML assert_equal "2", I18n.t(:foo) assert_equal "1", I18n.t(:bar) end + + test "namespaced controllers with namespaced routes" do + @plugin.write "config/routes.rb", <<-RUBY + ActionController::Routing::Routes.draw do + namespace :admin do + match "index", :to => "admin/foo#index" + end + end + RUBY + + @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY + class Admin::FooController < ApplicationController + def index + render :text => "Rendered from namespace" + end + end + RUBY + + boot_rails + + require 'rack/test' + extend Rack::Test::Methods + + get "/admin/index" + assert_equal 200, last_response.status + assert_equal "Rendered from namespace", last_response.body + end end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From 37e4deb2606557e5340b48169ffc1435bb331439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:04:37 +0100 Subject: Ensure helpers work from configured path. --- railties/lib/rails/application.rb | 2 -- railties/lib/rails/engine/configuration.rb | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index a8ff125342..90118c8cfc 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -11,8 +11,6 @@ module Rails autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' - # TODO Check helpers works as expected - # TODO Check routes namespaces # TODO Ensure production settings are read properly class << self private :new diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index e2fdf125d3..93afdcf911 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -15,6 +15,7 @@ module Rails paths = Rails::Paths::Root.new(@root) paths.app "app", :eager_load => true, :glob => "*" paths.app.controllers "app/controllers", :eager_load => true + paths.app.helpers "app/helpers", :eager_load => true paths.app.metals "app/metal", :eager_load => true paths.app.views "app/views" paths.lib "lib", :load_path => true -- cgit v1.2.3 From b92608770e20618ab6a6c67099dd19ae4533689e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:15:46 +0100 Subject: Ensure environment config has higher priority than application ones. --- railties/lib/rails/application.rb | 2 -- railties/lib/rails/application/bootstrap.rb | 4 ++++ railties/test/application/initializer_test.rb | 13 ++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 90118c8cfc..e14719c758 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -11,7 +11,6 @@ module Rails autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' - # TODO Ensure production settings are read properly class << self private :new alias :configure :class_eval @@ -24,7 +23,6 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance - base.require_environment! end protected diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 819d00be4e..3c339ffc57 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -3,6 +3,10 @@ module Rails module Bootstrap include Initializable + initializer :load_environment_config do |app| + app.require_environment! + end + initializer :load_all_active_support do |app| require "active_support/all" unless app.config.active_support.bare end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 6686d82f19..053757979b 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -38,13 +38,24 @@ module ApplicationTests end test "load environment with global" do - app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" + app_file "config/environments/development.rb", <<-RUBY + $initialize_test_set_from_env = 'success' + AppTemplate::Application.configure do + config.cache_classes = true + config.time_zone = "Brasilia" + end + RUBY + assert_nil $initialize_test_set_from_env add_to_config <<-RUBY config.root = "#{app_path}" + config.time_zone = "UTC" RUBY + require "#{app_path}/config/environment" assert_equal "success", $initialize_test_set_from_env + assert AppTemplate::Application.config.cache_classes + assert_equal "Brasilia", AppTemplate::Application.config.time_zone end test "action_controller load paths set only if action controller in use" do -- cgit v1.2.3 From e548f96b1d5cb6529dd6fbc6544f03a3a840b48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:23:21 +0100 Subject: Rename plugin_name to railtie_name and engine_name. --- railties/lib/rails/configuration.rb | 2 +- railties/lib/rails/engine.rb | 3 +++ railties/lib/rails/railtie.rb | 21 +++++++-------------- 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index e0bd12497f..c29cd0ef2c 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -71,7 +71,7 @@ module Rails end def config_keys - (Railtie.plugin_names + Engine.plugin_names).map { |n| n.to_s }.uniq + (Railtie.railtie_names + Engine.engine_names).map { |n| n.to_s }.uniq end def options diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 6f724963b2..842785875a 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -9,6 +9,9 @@ module Rails class << self attr_accessor :called_from + alias :engine_name :railtie_name + alias :engine_names :railtie_names + def inherited(base) unless abstract_railtie?(base) base.called_from = begin diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 6424be5a55..3cf358d75f 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -22,25 +22,18 @@ module Rails end end - # TODO This should be called railtie_name and engine_name - def plugin_name(plugin_name = nil) - @plugin_name ||= name.demodulize.underscore - @plugin_name = plugin_name if plugin_name - @plugin_name + def railtie_name(railtie_name = nil) + @railtie_name ||= name.demodulize.underscore + @railtie_name = railtie_name if railtie_name + @railtie_name end - # TODO Deprecate me - def plugins - subclasses - end - - # TODO Deprecate me - def plugin_names - plugins.map { |p| p.plugin_name } + def railtie_names + subclasses.map { |p| p.railtie_name } end def subscriber(subscriber) - Rails::Subscriber.add(plugin_name, subscriber) + Rails::Subscriber.add(railtie_name, subscriber) end def rake_tasks(&blk) -- cgit v1.2.3 From dd05b6c543f48050f494214da7803da6f5655292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:49:12 +0100 Subject: Add tests for plugin sanity check. --- railties/lib/rails/engine/configurable.rb | 3 ++- railties/lib/rails/plugin.rb | 3 +-- railties/test/plugins/vendored_test.rb | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/configurable.rb b/railties/lib/rails/engine/configurable.rb index d4b7ecc532..9a370f0abb 100644 --- a/railties/lib/rails/engine/configurable.rb +++ b/railties/lib/rails/engine/configurable.rb @@ -3,10 +3,11 @@ module Rails module Configurable def self.included(base) base.extend ClassMethods - base.delegate :middleware, :root, :paths, :to => :config end module ClassMethods + delegate :middleware, :root, :paths, :to => :config + def config @config ||= Engine::Configuration.new(find_root_with_flag("lib")) end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index b47679d140..4c73809177 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -49,10 +49,9 @@ module Rails eval(File.read(file), binding, file) if file && File.file?(file) end - # TODO Write tests for this sanity check initializer :sanity_check_railties_collision do if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s) - raise "The plugin #{name.inspect} is a Railtie or an Engine and cannot be installed as Plugin" + raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin" end end end diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 1fc8766def..86f3ecd1f7 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -247,6 +247,30 @@ YAML assert_equal 200, last_response.status assert_equal "Rendered from namespace", last_response.body end + + test "plugin cannot declare an engine for it" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < Rails::Engine + end + end + RUBY + + @plugin.write "init.rb", <<-RUBY + require "bukkits" + RUBY + + rescued = false + + begin + boot_rails + rescue Exception => e + rescued = true + assert_equal '"bukkits" is a Railtie/Engine and cannot be installed as plugin', e.message + end + + assert rescued, "Expected boot rails to fail" + end end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From 84ebfa4550b2325c6c89bc13aa6f904ff88d0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 14:48:00 +0100 Subject: Ensure metals and initializers in plugins are loaded. --- .../lib/generators/rails/metal/templates/metal.rb | 2 +- railties/lib/rails/application/finisher.rb | 2 +- railties/lib/rails/application/routes_reloader.rb | 14 +++++------ railties/lib/rails/configuration.rb | 2 +- railties/lib/rails/engine.rb | 18 ++++++++------ railties/lib/rails/engine/configuration.rb | 2 +- railties/lib/rails/rack/metal.rb | 29 ++++++++++++++++------ railties/test/initializer/path_test.rb | 4 ++- railties/test/plugins/vendored_test.rb | 28 +++++++++++++++++++++ 9 files changed, 75 insertions(+), 26 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/rails/metal/templates/metal.rb b/railties/lib/generators/rails/metal/templates/metal.rb index 2f5d4e7593..8cc3f1f258 100644 --- a/railties/lib/generators/rails/metal/templates/metal.rb +++ b/railties/lib/generators/rails/metal/templates/metal.rb @@ -1,5 +1,5 @@ # Allow the metal piece to run in isolation -require File.expand_path('../../../config/environment', __FILE__) +require File.expand_path('../../../config/environment', __FILE__) unless defined?(Rails) class <%= class_name %> def self.call(env) diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index db19011b7f..6461b76d3d 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -17,7 +17,7 @@ module Rails initializer :add_builtin_route do |app| if Rails.env.development? - app.config.action_dispatch.route_paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + RoutesReloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index d861d27465..fe0cfb7801 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,7 +1,11 @@ module Rails class Application + # TODO Write tests for this behavior extracted from Application class RoutesReloader - # TODO Write tests for this behavior extracted from Application + def self.paths + @paths ||= [] + end + def initialize(config) @config, @last_change_at = config, nil end @@ -9,7 +13,7 @@ module Rails def changed_at routes_changed_at = nil - paths.each do |path| + self.class.paths.each do |path| config_changed_at = File.stat(path).mtime if routes_changed_at.nil? || config_changed_at > routes_changed_at @@ -25,7 +29,7 @@ module Rails routes.disable_clear_and_finalize = true routes.clear! - paths.each { |path| load(path) } + self.class.paths.each { |path| load(path) } routes.finalize! nil @@ -40,10 +44,6 @@ module Rails reload! end end - - def paths - @config.action_dispatch.route_paths - end end end end \ No newline at end of file diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index c29cd0ef2c..3c5c1c1e16 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -16,7 +16,7 @@ module Rails middleware.use('::ActionDispatch::Cookies') middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) - middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) }) + middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.metals) }) middleware.use('ActionDispatch::ParamsParser') middleware.use('::Rack::MethodOverride') middleware.use('::ActionDispatch::Head') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 842785875a..e40052e0f1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -71,13 +71,13 @@ module Rails end initializer :add_routing_paths do - config.paths.config.routes.to_a.each do |route| - config.action_dispatch.route_paths.unshift(route) if File.exists?(route) + paths.config.routes.to_a.each do |route| + Rails::Application::RoutesReloader.paths.unshift(route) if File.exists?(route) end end initializer :add_routing_namespaces do |app| - config.paths.app.controllers.to_a.each do |load_path| + paths.app.controllers.to_a.each do |load_path| load_path = File.expand_path(load_path) Dir["#{load_path}/*/*_controller.rb"].collect do |path| namespace = File.dirname(path).sub(/#{load_path}\/?/, '') @@ -87,17 +87,21 @@ module Rails end initializer :add_locales do - config.i18n.load_path.unshift(*config.paths.config.locales.to_a) + config.i18n.load_path.unshift(*paths.config.locales.to_a) end initializer :add_view_paths do - views = config.paths.app.views.to_a + views = paths.app.views.to_a ActionController::Base.view_paths.concat(views) if defined?(ActionController) ActionMailer::Base.view_paths.concat(views) if defined?(ActionMailer) end + initializer :add_metals do + Rails::Rack::Metal.paths.concat(paths.app.metals.to_a) + end + initializer :load_application_initializers do - config.paths.config.initializers.each do |initializer| + paths.config.initializers.to_a.sort.each do |initializer| load(initializer) end end @@ -107,7 +111,7 @@ module Rails if app.config.cache_classes config.eager_load_paths.each do |load_path| - matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ + matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/ Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency file.sub(matcher, '\1') end diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 93afdcf911..a328e14170 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -16,7 +16,7 @@ module Rails paths.app "app", :eager_load => true, :glob => "*" paths.app.controllers "app/controllers", :eager_load => true paths.app.helpers "app/helpers", :eager_load => true - paths.app.metals "app/metal", :eager_load => true + paths.app.metals "app/metal" paths.app.views "app/views" paths.lib "lib", :load_path => true paths.lib.tasks "lib/tasks", :glob => "**/*.rake" diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 565f95d7c4..732936da32 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -3,14 +3,29 @@ require 'action_dispatch' module Rails module Rack class Metal - def initialize(metal_roots, metals=nil) - load_list = metals || Dir["{#{metal_roots.join(",")}}/**/*.rb"] + def self.paths + @paths ||= [] + end + + def initialize(list=nil) + metals = [] + list = Array(list || :all).map(&:to_sym) + + self.class.paths.each do |path| + matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/ + Dir.glob("#{path}/**/*.rb").sort.each do |metal_path| + metal = metal_path.sub(matcher, '\1').to_sym + next unless list.include?(metal) || list.include?(:all) + require_dependency metal + metals << metal + end + end + + metals = metals.sort_by do |m| + [list.index(m) || list.index(:all), m.to_s] + end - @metals = load_list.map { |metal| - metal = File.basename(metal, '.rb') - require_dependency metal - metal.camelize.constantize - }.compact + @metals = metals.map { |m| m.to_s.camelize.constantize } end def new(app) diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 54bdddbdf2..7a40d7fa6e 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -38,6 +38,7 @@ module InitializerTests test "booting up Rails yields a valid paths object" do assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.helpers, "app", "helpers" assert_path @paths.app.views, "app", "views" assert_path @paths.lib, "lib" assert_path @paths.vendor, "vendor" @@ -56,7 +57,7 @@ module InitializerTests test "booting up Rails yields a list of paths that are eager" do assert @paths.app.eager_load? assert @paths.app.controllers.eager_load? - assert @paths.app.metals.eager_load? + assert @paths.app.helpers.eager_load? end test "environments has a glob equal to the current environment" do @@ -70,6 +71,7 @@ module InitializerTests assert_in_load_path "lib" assert_in_load_path "vendor" + assert_not_in_load_path "app", "metal" assert_not_in_load_path "config" assert_not_in_load_path "config", "locales" assert_not_in_load_path "config", "environments" diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 86f3ecd1f7..05c01846e1 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -221,6 +221,24 @@ YAML assert_equal "1", I18n.t(:bar) end + test "plugin metals are added to the middleware stack" do + @plugin.write 'app/metal/foo_metal.rb', <<-RUBY + class FooMetal + def self.call(env) + [200, { "Content-Type" => "text/html"}, ["FooMetal"]] + end + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal 200, last_response.status + assert_equal "FooMetal", last_response.body + end + test "namespaced controllers with namespaced routes" do @plugin.write "config/routes.rb", <<-RUBY ActionController::Routing::Routes.draw do @@ -248,6 +266,16 @@ YAML assert_equal "Rendered from namespace", last_response.body end + test "plugin with initializers" do + $plugin_initializer = false + @plugin.write "config/initializers/foo.rb", <<-RUBY + $plugin_initializer = true + RUBY + + boot_rails + assert $plugin_initializer + end + test "plugin cannot declare an engine for it" do @plugin.write "lib/bukkits.rb", <<-RUBY class Bukkits -- cgit v1.2.3 From 92126521551a7c62e9032eda4a2b8a6d92c0279f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 24 Jan 2010 10:29:38 -0600 Subject: Add Rails::Application pointer to the default app to add symmetry to Foo::Application --- railties/lib/rails/application.rb | 6 +++++- railties/lib/rails/tasks/middleware.rake | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index e14719c758..ab66d1e90b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -16,7 +16,11 @@ module Rails alias :configure :class_eval def instance - @instance ||= new + if instance_of?(Rails::Application) + Rails.application.instance + else + @instance ||= new + end end def inherited(base) diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake index 5a5bd7a7e9..c3aaddb153 100644 --- a/railties/lib/rails/tasks/middleware.rake +++ b/railties/lib/rails/tasks/middleware.rake @@ -3,5 +3,5 @@ task :middleware => :environment do Rails.configuration.middleware.active.each do |middleware| puts "use #{middleware.inspect}" end - puts "run #{Rails.application.class.name}" + puts "run #{Rails::Application.class.name}" end -- cgit v1.2.3 From 9543298d02fbd28c5edaadeed0d14f1ba19263dc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 24 Jan 2010 10:35:45 -0600 Subject: Use Rails::Application ref in Rakefile and console scripts. Less places you need to change if you rename your application. --- railties/lib/generators/rails/app/templates/Rakefile | 2 +- railties/lib/generators/rails/app/templates/script/console.tt | 2 +- railties/lib/generators/rails/app/templates/script/dbconsole.tt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/rails/app/templates/Rakefile b/railties/lib/generators/rails/app/templates/Rakefile index c19ad0e945..9cb2046439 100755 --- a/railties/lib/generators/rails/app/templates/Rakefile +++ b/railties/lib/generators/rails/app/templates/Rakefile @@ -7,4 +7,4 @@ require 'rake' require 'rake/testtask' require 'rake/rdoctask' -<%= app_const %>.load_tasks +Rails::Application.load_tasks diff --git a/railties/lib/generators/rails/app/templates/script/console.tt b/railties/lib/generators/rails/app/templates/script/console.tt index 915c5b8294..47aa254f9f 100755 --- a/railties/lib/generators/rails/app/templates/script/console.tt +++ b/railties/lib/generators/rails/app/templates/script/console.tt @@ -2,4 +2,4 @@ require File.expand_path('../../config/boot', __FILE__) require 'rails/commands/console' require File.expand_path('../../config/application', __FILE__) -Rails::Console.start(<%= app_const %>) +Rails::Console.start(Rails::Application) diff --git a/railties/lib/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/generators/rails/app/templates/script/dbconsole.tt index a92f6f2844..1e53c1d761 100755 --- a/railties/lib/generators/rails/app/templates/script/dbconsole.tt +++ b/railties/lib/generators/rails/app/templates/script/dbconsole.tt @@ -2,4 +2,4 @@ require File.expand_path('../../config/boot', __FILE__) require 'rails/commands/dbconsole' require File.expand_path('../../config/application', __FILE__) -Rails::DBConsole.start(<%= app_const %>) +Rails::DBConsole.start(Rails::Application) -- cgit v1.2.3 From 6e57b88c60fa3ad1ecfa740b8cd3173c4fe72680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 21:21:37 +0100 Subject: Fix a couple failures on 1.9.1. --- railties/lib/rails/application/finisher.rb | 2 +- railties/lib/rails/console/app.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 6461b76d3d..5cc5b4ae88 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -17,7 +17,7 @@ module Rails initializer :add_builtin_route do |app| if Rails.env.development? - RoutesReloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + Rails::Application::RoutesReloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index 98f7f774a9..7e8fd027e6 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -23,9 +23,11 @@ def new_session session end -#reloads the environment -def reload! - puts "Reloading..." - ActionDispatch::Callbacks.new(lambda {}, true).call({}) +# reloads the environment +def reload!(print=true) + puts "Reloading..." if print + ActionDispatch::Callbacks.new(lambda {}, false) true end + +reload!(false) -- cgit v1.2.3 From 396003fc48d7c0ba206ad059646c7414bee22a36 Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Sun, 24 Jan 2010 12:29:36 +0330 Subject: Revamp of Rails documentation task Signed-off-by: Yehuda Katz --- railties/lib/rails/tasks/documentation.rake | 54 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 65d0d476ba..3f49a9a720 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -11,35 +11,43 @@ namespace :doc do rdoc.rdoc_files.include('lib/**/*.rb') } - desc "Generate documentation for the Rails framework" + desc 'Generate documentation for the Rails framework. Specify path with PATH="/path/to/rails"' Rake::RDocTask.new("rails") { |rdoc| + path = ENV['RAILS_PATH'] || 'vendor/gems/gems' + version = '-3.0.pre' unless ENV['RAILS_PATH'] rdoc.rdoc_dir = 'doc/api' rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.title = "Rails Framework Documentation" rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE') - rdoc.rdoc_files.include('vendor/rails/railties/README') - rdoc.rdoc_files.include('vendor/rails/railties/lib/{*.rb,commands/*.rb,generators/*.rb}') - rdoc.rdoc_files.include('vendor/rails/activerecord/README') - rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb') - rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*') - rdoc.rdoc_files.include('vendor/rails/activeresource/README') - rdoc.rdoc_files.include('vendor/rails/activeresource/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource.rb') - rdoc.rdoc_files.include('vendor/rails/activeresource/lib/active_resource/*') - rdoc.rdoc_files.include('vendor/rails/actionpack/README') - rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb') - rdoc.rdoc_files.include('vendor/rails/actionmailer/README') - rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb') - rdoc.rdoc_files.include('vendor/rails/activesupport/README') - rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG') - rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb') + + %w(README CHANGELOG lib/action_mailer/base.rb).each do |file| + rdoc.rdoc_files.include("#{path}/actionmailer#{version}/#{file}") + end + + %w(README CHANGELOG lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file| + rdoc.rdoc_files.include("#{path}/actionpack#{version}/#{file}") + end + + %w(README CHANGELOG lib/active_model/**/*.rb).each do |file| + rdoc.rdoc_files.include("#{path}/activemodel#{version}/#{file}") + end + + %w(README CHANGELOG lib/active_record/**/*.rb).each do |file| + rdoc.rdoc_files.include("#{path}/activerecord#{version}/#{file}") + end + + %w(README CHANGELOG lib/active_resource.rb lib/active_resource/*).each do |file| + rdoc.rdoc_files.include("#{path}/activeresource#{version}/#{file}") + end + + %w(README CHANGELOG lib/active_support/**/*.rb).each do |file| + rdoc.rdoc_files.include("#{path}/activesupport#{version}/#{file}") + end + + %w(README CHANGELOG MIT-LICENSE lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file| + rdoc.rdoc_files.include("#{path}/railties#{version}/#{file}") + end } plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) } -- cgit v1.2.3 From 3b6f659fb6b1ffd323c0bbad36630cc97b96bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 25 Jan 2010 01:06:12 +0100 Subject: Add active_model/railtie back to generated boot.rb, add models back to paths, load active_support/railtie since we need it and ensure default logger is set before config. --- railties/lib/generators/rails/app/templates/config/boot.rb | 2 ++ railties/lib/rails.rb | 1 + railties/lib/rails/engine/configuration.rb | 1 + railties/test/initializer/path_test.rb | 1 + 4 files changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/generators/rails/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb index cbfa5ca3e9..e91304451b 100644 --- a/railties/lib/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/generators/rails/app/templates/config/boot.rb @@ -20,6 +20,7 @@ require 'rails/all' # and list the framework railties that you want: # # require "active_support/railtie" +# require "active_model/railtie" # require "active_record/railtie" # require "action_controller/railtie" # require "action_view/railtie" @@ -27,6 +28,7 @@ require 'rails/all' # require "active_resource/railtie" <% else -%> # Pick the frameworks you want: +# require "active_model/railtie" # require "active_record/railtie" require "active_support/railtie" require "action_controller/railtie" diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 623555e7c1..b7a39fd5a7 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -10,6 +10,7 @@ require 'rails/deprecation' require 'rails/subscriber' require 'rails/ruby_version_check' +require 'active_support/railtie' require 'action_dispatch/railtie' # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index a328e14170..c4e34b11b8 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -16,6 +16,7 @@ module Rails paths.app "app", :eager_load => true, :glob => "*" paths.app.controllers "app/controllers", :eager_load => true paths.app.helpers "app/helpers", :eager_load => true + paths.app.models "app/models", :eager_load => true paths.app.metals "app/metal" paths.app.views "app/views" paths.lib "lib", :load_path => true diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 7a40d7fa6e..2048dc57bb 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -37,6 +37,7 @@ module InitializerTests end test "booting up Rails yields a valid paths object" do + assert_path @paths.app.models, "app", "models" assert_path @paths.app.metals, "app", "metal" assert_path @paths.app.helpers, "app", "helpers" assert_path @paths.app.views, "app", "views" -- cgit v1.2.3 From 9cb3ca1d29eb770c1a7adac3798666847fceee2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Mon, 25 Jan 2010 13:13:29 +0100 Subject: Change mailer generator templates and refactor the whole naming schema. --- .../lib/generators/erb/mailer/templates/view.erb | 2 +- .../generators/rails/mailer/templates/mailer.rb | 19 +++--- .../rails/resource/resource_generator.rb | 4 +- .../scaffold_controller_generator.rb | 6 +- .../generators/test_unit/mailer/templates/fixture | 2 +- .../test_unit/mailer/templates/functional_test.rb | 12 +++- railties/lib/rails/generators/named_base.rb | 79 ++++++++++------------ railties/lib/rails/generators/resource_helpers.rb | 43 ++++++------ railties/test/generators/mailer_generator_test.rb | 40 +++++++++-- railties/test/generators/named_base_test.rb | 62 +++++++++++++---- 10 files changed, 165 insertions(+), 104 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/erb/mailer/templates/view.erb b/railties/lib/generators/erb/mailer/templates/view.erb index fcce7bd805..6d597256a6 100644 --- a/railties/lib/generators/erb/mailer/templates/view.erb +++ b/railties/lib/generators/erb/mailer/templates/view.erb @@ -1,3 +1,3 @@ <%= class_name %>#<%= @action %> -Find me in app/views/<%= @path %> +<%%= @greeting %>, find me in app/views/<%= @path %> diff --git a/railties/lib/generators/rails/mailer/templates/mailer.rb b/railties/lib/generators/rails/mailer/templates/mailer.rb index 90e0b712d6..5e7ef42370 100644 --- a/railties/lib/generators/rails/mailer/templates/mailer.rb +++ b/railties/lib/generators/rails/mailer/templates/mailer.rb @@ -1,14 +1,15 @@ class <%= class_name %> < ActionMailer::Base + delivers_from "mail@<%= application_name %>.com" <% for action in actions -%> - def <%= action %>(sent_at = Time.now) - subject '<%= class_name %>#<%= action %>' - recipients '' - from '' - sent_on sent_at - - body :greeting => 'Hi,' + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.actionmailer.<%= file_name %>.<%= action %>.subject + # + def <%= action %> + @greeting = "Hi" + mail(:to => "") end - <% end -%> -end +end \ No newline at end of file diff --git a/railties/lib/generators/rails/resource/resource_generator.rb b/railties/lib/generators/rails/resource/resource_generator.rb index 43c7cc85f4..5acb839f39 100644 --- a/railties/lib/generators/rails/resource/resource_generator.rb +++ b/railties/lib/generators/rails/resource/resource_generator.rb @@ -6,8 +6,8 @@ module Rails class ResourceGenerator < ModelGenerator #metagenerator include ResourceHelpers - hook_for :resource_controller, :required => true do |base, controller| - base.invoke controller, [ base.controller_name, base.options[:actions] ] + hook_for :resource_controller, :required => true do |controller| + invoke controller, [ controller_name, options[:actions] ] end class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [], diff --git a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb index e544e29892..49af2974cd 100644 --- a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +++ b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb @@ -18,9 +18,9 @@ module Rails hook_for :template_engine, :test_framework, :as => :scaffold - # Invoke the helper using the controller (pluralized) name. - hook_for :helper, :as => :scaffold do |base, invoked| - base.invoke invoked, [ base.controller_name ] + # Invoke the helper using the controller name (pluralized) + hook_for :helper, :as => :scaffold do |invoked| + invoke invoked, [ controller_name ] end end end diff --git a/railties/lib/generators/test_unit/mailer/templates/fixture b/railties/lib/generators/test_unit/mailer/templates/fixture index fcce7bd805..171648d6fd 100644 --- a/railties/lib/generators/test_unit/mailer/templates/fixture +++ b/railties/lib/generators/test_unit/mailer/templates/fixture @@ -1,3 +1,3 @@ <%= class_name %>#<%= @action %> -Find me in app/views/<%= @path %> +Hi, find me in app/views/<%= @path %> diff --git a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb index d7366fea5f..2f694e431c 100644 --- a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb @@ -3,11 +3,17 @@ require 'test_helper' class <%= class_name %>Test < ActionMailer::TestCase <% for action in actions -%> test "<%= action %>" do - @expected.subject = '<%= class_name %>#<%= action %>' - @expected.body = read_fixture('<%= action %>') + @actual = <%= class_name %>.<%= action %> + + @expected.subject = <%= action.to_s.humanize.inspect %> + @expected.body = read_fixture("<%= action %>") @expected.date = Time.now - assert_equal @expected, <%= class_name %>.create_<%= action %>(@expected.date) + assert_difference "<%= class_name %>.deliveries.size" do + @actual.deliver + end + + assert_equal @expected.encoded, @actual.encoded end <% end -%> diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 3e851bf888..12e918731e 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -6,17 +6,9 @@ module Rails class NamedBase < Base argument :name, :type => :string - no_tasks { - attr_reader :class_name, :singular_name, :plural_name, :table_name, - :class_path, :file_path, :class_nesting_depth - - alias :file_name :singular_name - } - def initialize(args, *options) #:nodoc: # Unfreeze name in case it's given as a frozen string args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen? - super assign_names!(self.name) parse_attributes! if respond_to?(:attributes) @@ -24,28 +16,48 @@ module Rails protected - def assign_names!(given_name) #:nodoc: - base_name, @class_path, @file_path, class_nesting, @class_nesting_depth = extract_modules(given_name) - class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) + attr_reader :class_path, :file_name + alias :singular_name :file_name - @table_name = if pluralize_table_names? - plural_name - else - singular_name + def file_path + @file_path ||= (class_path + [file_name]).join('/') + end + + def class_name + @class_name ||= (class_path + [file_name]).map!{ |m| m.camelize }.join('::') + end + + def plural_name + @plural_name ||= singular_name.pluralize + end + + def i18n_scope + @i18n_scope ||= file_path.gsub('/', '.') + end + + def table_name + @table_name ||= begin + base = pluralize_table_names? ? plural_name : singular_name + (class_path + [base]).join('_') end + end - if class_nesting.empty? - @class_name = class_name_without_nesting + # Tries to retrieve the application name or simple return application. + def application_name + if defined?(Rails) && Rails.application + Rails.application.class.name.split('::').first.underscore else - @table_name = class_nesting.underscore << "_" << @table_name - @class_name = "#{class_nesting}::#{class_name_without_nesting}" + "application" end + end - @table_name.gsub!('/', '_') + def assign_names!(name) #:nodoc: + @class_path = name.include?('/') ? name.split('/') : name.split('::') + @class_path.map! { |m| m.underscore } + @file_name = @class_path.pop end - # Convert attributes hash into an array with GeneratedAttribute objects. - # + # Convert attributes array into GeneratedAttribute objects. def parse_attributes! #:nodoc: self.attributes = (attributes || []).map do |key_value| name, type = key_value.split(':') @@ -53,29 +65,6 @@ module Rails end end - # Extract modules from filesystem-style or ruby-style path. Both - # good/fun/stuff and Good::Fun::Stuff produce the same results. - # - def extract_modules(name) #:nodoc: - modules = name.include?('/') ? name.split('/') : name.split('::') - name = modules.pop - path = modules.map { |m| m.underscore } - - file_path = (path + [name.underscore]).join('/') - nesting = modules.map { |m| m.camelize }.join('::') - - [name, path, file_path, nesting, modules.size] - end - - # Receives name and return camelized, underscored and pluralized names. - # - def inflect_names(name) #:nodoc: - camel = name.camelize - under = camel.underscore - plural = under.pluralize - [camel, under, plural] - end - def pluralize_table_names? !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names end diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index 7e00a222ed..3a98a8f9c1 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -9,14 +9,7 @@ module Rails mattr_accessor :skip_warn def self.included(base) #:nodoc: - base.class_eval do - class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName" - - no_tasks { - attr_reader :controller_name, :controller_class_name, :controller_file_name, - :controller_class_path, :controller_file_path - } - end + base.class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName" end # Set controller variables on initialization. @@ -29,29 +22,40 @@ module Rails say "Plural version of the model detected, using singularized version. Override with --force-plural." ResourceHelpers.skip_warn = true end - name.replace name.singularize - assign_names!(self.name) + assign_names!(name) end @controller_name = name.pluralize + end - base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name) - class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name) + protected + + attr_reader :controller_name - @controller_class_name = if class_nesting.empty? - class_name_without_nesting - else - "#{class_nesting}::#{class_name_without_nesting}" + def controller_class_path + @class_path end - end - protected + def controller_file_name + @controller_file_name ||= file_name.pluralize + end + + def controller_file_path + @controller_file_path ||= (controller_class_path + [controller_file_name]).join('/') + end + + def controller_class_name + @controller_class_name ||= (controller_class_path + [controller_file_name]).map!{ |m| m.camelize }.join('::') + end + + def controller_i18n_scope + @controller_i18n_scope ||= controller_file_path.gsub('/', '.') + end # Loads the ORM::Generators::ActiveModel class. This class is responsable # to tell scaffold entities how to generate an specific method for the # ORM. Check Rails::Generators::ActiveModel for more information. - # def orm_class @orm_class ||= begin # Raise an error if the class_option :orm was not defined. @@ -68,7 +72,6 @@ module Rails end # Initialize ORM::Generators::ActiveModel to access instance methods. - # def orm_instance(name=file_name) @orm_instance ||= @orm_class.new(name) end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index dfc3130f77..0203eb314c 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -6,8 +6,20 @@ class MailerGeneratorTest < Rails::Generators::TestCase arguments %w(notifier foo bar) def test_mailer_skeleton_is_created + Rails.stubs(:application).returns(Object.new) run_generator - assert_file "app/mailers/notifier.rb", /class Notifier < ActionMailer::Base/ + assert_file "app/mailers/notifier.rb" do |mailer| + assert_match /class Notifier < ActionMailer::Base/, mailer + assert_match /delivers_from "mail@object.com"/, mailer + end + end + + def test_mailer_with_i18n_helper + run_generator + assert_file "app/mailers/notifier.rb" do |mailer| + assert_match /en\.actionmailer\.notifier\.foo\.subject/, mailer + assert_match /en\.actionmailer\.notifier\.bar\.subject/, mailer + end end def test_check_class_collision @@ -24,8 +36,15 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_template_engine run_generator - assert_file "app/views/notifier/foo.erb", /app\/views\/notifier\/foo/ - assert_file "app/views/notifier/bar.erb", /app\/views\/notifier\/bar/ + assert_file "app/views/notifier/foo.erb" do |view| + assert_match /app\/views\/notifier\/foo/, view + assert_match /<%= @greeting %>/, view + end + + assert_file "app/views/notifier/bar.erb" do |view| + assert_match /app\/views\/notifier\/bar/, view + assert_match /<%= @greeting %>/, view + end end def test_invokes_default_template_engine_even_with_no_action @@ -40,7 +59,18 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_actions_are_turned_into_methods run_generator - assert_file "app/mailers/notifier.rb", /def foo/ - assert_file "app/mailers/notifier.rb", /def bar/ + + assert_file "app/mailers/notifier.rb" do |mailer| + assert_instance_method :foo, mailer do |foo| + assert_match /mail\(:to => ""\)/, foo + assert_match /@greeting = "Hi"/, foo + end + + assert_instance_method :bar, mailer do |bar| + assert_match /mail\(:to => ""\)/, bar + assert_match /@greeting = "Hi"/, bar + end + end + end end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 99eb431a49..7514bc32bd 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -16,28 +16,60 @@ class NamedBaseTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_attributes - g = generator ["admin/foo"] - assert_equal 'admin/foo', g.name - assert_equal %w(admin), g.class_path - assert_equal 1, g.class_nesting_depth - assert_equal 'Admin::Foo', g.class_name - assert_equal 'foo', g.singular_name - assert_equal 'foos', g.plural_name - assert_equal g.singular_name, g.file_name - assert_equal "admin_#{g.plural_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin/foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name + end + + def test_named_generator_attributes_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name end def test_named_generator_attributes_without_pluralized ActiveRecord::Base.pluralize_table_names = false - g = generator ["admin/foo"] - assert_equal "admin_#{g.singular_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin_foo', :table_name end def test_scaffold_plural_names - g = generator ["ProductLine"] - assert_equal "ProductLines", g.controller_name - assert_equal "ProductLines", g.controller_class_name - assert_equal "product_lines", g.controller_file_name + g = generator ['admin/foo'] + assert_name g, 'admin/foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope + end + + def test_scaffold_plural_names_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope end + protected + + def assert_name(generator, value, method) + assert_equal value, generator.send(method) + end end -- cgit v1.2.3 From 2d1f9fb98f6b4f7afa469eba57eac4041c8ee539 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 25 Jan 2010 11:06:39 -0600 Subject: Plugins need to load before app initializers --- railties/lib/rails/application.rb | 2 +- railties/test/plugins/vendored_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index ab66d1e90b..6633c36a21 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -91,8 +91,8 @@ module Rails def initializers initializers = Bootstrap.initializers - initializers += super railties.all { |r| initializers += r.initializers } + initializers += super initializers += Finisher.initializers initializers end diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 05c01846e1..3977099184 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -37,6 +37,19 @@ module PluginsTest assert_equal "Bukkits", Bukkits.name end + test "plugin init is ran before application initializers" do + plugin "foo", "$foo = true" do |plugin| + plugin.write "lib/foo.rb", "module Foo; end" + end + + app_file 'config/initializers/foo.rb', <<-RUBY + raise "no $foo" unless $foo + raise "no Foo" unless Foo + RUBY + + boot_rails + end + test "plugin paths get added to the AS::Dependency list" do boot_rails assert_equal "Bukkits", Bukkits.name -- cgit v1.2.3 From c6104e6514d7e0af8dca92fcb40a6adb72e16611 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 25 Jan 2010 12:55:30 -0600 Subject: Failing test for using plugin middleware in application config --- railties/test/plugins/vendored_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties') diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 3977099184..41073d33a2 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -252,6 +252,26 @@ YAML assert_equal "FooMetal", last_response.body end + test "use plugin middleware in application config" do + plugin "foo" do |plugin| + plugin.write "lib/foo.rb", <<-RUBY + class Foo + def initialize(app) + @app = app + end + + def call(env) + @app.call(env) + end + end + RUBY + end + + add_to_config "config.middleware.use :Foo" + + boot_rails + end + test "namespaced controllers with namespaced routes" do @plugin.write "config/routes.rb", <<-RUBY ActionController::Routing::Routes.draw do -- cgit v1.2.3 From 1177a40e68b6661d6d2cb4aefdd9a805459cd936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 25 Jan 2010 22:00:07 +0100 Subject: Fix i18n locales order test. --- railties/lib/rails/engine.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index e40052e0f1..a9c94bc020 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -57,12 +57,12 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. initializer :set_autoload_paths do |app| - ActiveSupport::Dependencies.load_paths.concat(config.load_paths) + ActiveSupport::Dependencies.load_paths.unshift(*config.load_paths) if reloadable?(app) - ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) + ActiveSupport::Dependencies.load_once_paths.unshift(*config.load_once_paths) else - ActiveSupport::Dependencies.load_once_paths.concat(config.load_paths) + ActiveSupport::Dependencies.load_once_paths.unshift(*config.load_paths) end # Freeze so future modifications will fail rather than do nothing mysteriously @@ -86,18 +86,20 @@ module Rails end end + # I18n load paths are a special case since the ones added + # later have higher priority. initializer :add_locales do - config.i18n.load_path.unshift(*paths.config.locales.to_a) + config.i18n.engines_load_path.concat(paths.config.locales.to_a) end initializer :add_view_paths do views = paths.app.views.to_a - ActionController::Base.view_paths.concat(views) if defined?(ActionController) - ActionMailer::Base.view_paths.concat(views) if defined?(ActionMailer) + ActionController::Base.view_paths.unshift(*views) if defined?(ActionController) + ActionMailer::Base.view_paths.unshift(*views) if defined?(ActionMailer) end initializer :add_metals do - Rails::Rack::Metal.paths.concat(paths.app.metals.to_a) + Rails::Rack::Metal.paths.unshift(*paths.app.metals.to_a) end initializer :load_application_initializers do -- cgit v1.2.3 From 02908e11425069e5b91cbf8ec3c8344a58493ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 25 Jan 2010 22:59:08 +0100 Subject: As first step setup the load path and lazy compare middlewares. --- railties/lib/rails/application/bootstrap.rb | 4 +++ railties/lib/rails/engine.rb | 4 +-- railties/test/plugins/vendored_test.rb | 38 ++++++++++++++--------------- 3 files changed, 24 insertions(+), 22 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 3c339ffc57..f038027c97 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -76,6 +76,10 @@ module Rails initializer :initialize_dependency_mechanism do |app| ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load end + + initializer :bootstrap_load_path do + # This is just an initializer used as hook so all load paths are loaded together + end end end end \ No newline at end of file diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index a9c94bc020..8cb938c2b9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -47,7 +47,7 @@ module Rails end # Add configured load paths to ruby load paths and remove duplicates. - initializer :set_load_path do + initializer :set_load_path, :before => :bootstrap_load_path do config.load_paths.reverse_each do |path| $LOAD_PATH.unshift(path) if File.directory?(path) end @@ -56,7 +56,7 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths do |app| + initializer :set_autoload_paths, :before => :bootstrap_load_path do |app| ActiveSupport::Dependencies.load_paths.unshift(*config.load_paths) if reloadable?(app) diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index 41073d33a2..c14178ec66 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -48,6 +48,7 @@ module PluginsTest RUBY boot_rails + assert $foo end test "plugin paths get added to the AS::Dependency list" do @@ -252,26 +253,6 @@ YAML assert_equal "FooMetal", last_response.body end - test "use plugin middleware in application config" do - plugin "foo" do |plugin| - plugin.write "lib/foo.rb", <<-RUBY - class Foo - def initialize(app) - @app = app - end - - def call(env) - @app.call(env) - end - end - RUBY - end - - add_to_config "config.middleware.use :Foo" - - boot_rails - end - test "namespaced controllers with namespaced routes" do @plugin.write "config/routes.rb", <<-RUBY ActionController::Routing::Routes.draw do @@ -332,6 +313,23 @@ YAML assert rescued, "Expected boot rails to fail" end + + test "use plugin middleware in application config" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + def initialize(app) + @app = app + end + + def call(env) + @app.call(env) + end + end + RUBY + + add_to_config "config.middleware.use \"Bukkits\"" + boot_rails + end end class VendoredOrderingTest < Test::Unit::TestCase -- cgit v1.2.3 From cc1bb8590e6021e0c86b345857358704fa68c9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 25 Jan 2010 23:17:39 +0100 Subject: Refactor some railties tests structure. --- railties/test/plugins/configuration_test.rb | 45 --- railties/test/plugins/framework_extension_test.rb | 68 ---- railties/test/plugins/vendored_test.rb | 386 --------------------- railties/test/railties/configuration_test.rb | 45 +++ railties/test/railties/framework_extension_test.rb | 68 ++++ railties/test/railties/plugin_ordering_test.rb | 55 +++ railties/test/railties/plugin_test.rb | 334 ++++++++++++++++++ 7 files changed, 502 insertions(+), 499 deletions(-) delete mode 100644 railties/test/plugins/configuration_test.rb delete mode 100644 railties/test/plugins/framework_extension_test.rb delete mode 100644 railties/test/plugins/vendored_test.rb create mode 100644 railties/test/railties/configuration_test.rb create mode 100644 railties/test/railties/framework_extension_test.rb create mode 100644 railties/test/railties/plugin_ordering_test.rb create mode 100644 railties/test/railties/plugin_test.rb (limited to 'railties') diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb deleted file mode 100644 index c59040c712..0000000000 --- a/railties/test/plugins/configuration_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "isolation/abstract_unit" - -module PluginsTest - class ConfigurationTest < Test::Unit::TestCase - def setup - build_app - boot_rails - require "rails/all" - end - - test "config is available to plugins" do - class Foo < Rails::Railtie ; end - assert_nil Foo.config.action_controller.foo - end - - test "a config name is available for the plugin" do - class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end - assert_equal "hello", Foo.config.foo.greetings - end - - test "plugin configurations are available in the application" do - class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end - require "#{app_path}/config/application" - assert_equal "hello", AppTemplate::Application.config.foo.greetings - end - - test "plugin config merges are deep" do - class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end - class Bar < Rails::Railtie - config.foo.bar = "bar" - end - assert_equal "hello", Bar.config.foo.greetings - assert_equal "bar", Bar.config.foo.bar - end - - test "plugin can add subscribers" do - begin - class Foo < Rails::Railtie; subscriber(Rails::Subscriber.new); end - assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] - ensure - Rails::Subscriber.subscribers.clear - end - end - end -end diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb deleted file mode 100644 index d57fd4e635..0000000000 --- a/railties/test/plugins/framework_extension_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -require "isolation/abstract_unit" - -module PluginsTest - class FrameworkExtensionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf("#{app_path}/config/environments") - require "rails/all" - end - - test "rake_tasks block is executed when MyApp.load_tasks is called" do - $ran_block = false - - class MyTie < Rails::Railtie - rake_tasks do - $ran_block = true - end - end - - require "#{app_path}/config/environment" - - assert !$ran_block - require 'rake' - require 'rake/testtask' - require 'rake/rdoctask' - - AppTemplate::Application.load_tasks - assert $ran_block - end - - test "generators block is executed when MyApp.load_generators is called" do - $ran_block = false - - class MyTie < Rails::Railtie - generators do - $ran_block = true - end - end - - require "#{app_path}/config/environment" - - assert !$ran_block - AppTemplate::Application.load_generators - assert $ran_block - end - end - - class ActiveRecordExtensionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf("#{app_path}/config/environments") - end - - test "active_record extensions are applied to ActiveRecord" do - add_to_config "config.active_record.table_name_prefix = 'tbl_'" - - require "#{app_path}/config/environment" - - assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix - end - end -end \ No newline at end of file diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb deleted file mode 100644 index c14178ec66..0000000000 --- a/railties/test/plugins/vendored_test.rb +++ /dev/null @@ -1,386 +0,0 @@ -require "isolation/abstract_unit" - -module PluginsTest - class VendoredTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - - @plugin = plugin "bukkits", "::LEVEL = config.log_level" do |plugin| - plugin.write "lib/bukkits.rb", "class Bukkits; end" - end - end - - def boot_rails - super - require "#{app_path}/config/environment" - end - - def app - @app ||= Rails.application - end - - test "it loads the plugin's init.rb file" do - boot_rails - assert_equal "loaded", BUKKITS - end - - test "the init.rb file has access to the config object" do - boot_rails - assert_equal :debug, LEVEL - end - - test "the plugin puts its lib directory on the load path" do - boot_rails - require "bukkits" - assert_equal "Bukkits", Bukkits.name - end - - test "plugin init is ran before application initializers" do - plugin "foo", "$foo = true" do |plugin| - plugin.write "lib/foo.rb", "module Foo; end" - end - - app_file 'config/initializers/foo.rb', <<-RUBY - raise "no $foo" unless $foo - raise "no Foo" unless Foo - RUBY - - boot_rails - assert $foo - end - - test "plugin paths get added to the AS::Dependency list" do - boot_rails - assert_equal "Bukkits", Bukkits.name - end - - test "plugin constants do not get reloaded by default" do - boot_rails - assert_equal "Bukkits", Bukkits.name - ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_nothing_raised { Bukkits } - end - - test "plugin constants get reloaded if config.reload_plugins is set" do - add_to_config <<-RUBY - config.reload_plugins = true - RUBY - - boot_rails - - assert_equal "Bukkits", Bukkits.name - ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_raises(NameError) { Bukkits } - end - - test "plugin should work without init.rb" do - @plugin.delete("init.rb") - - boot_rails - - require "bukkits" - assert_nothing_raised { Bukkits } - end - - test "the plugin puts its models directory on the load path" do - @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end" - - boot_rails - - assert_nothing_raised { MyBukkit } - end - - test "the plugin puts is controllers directory on the load path" do - @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end" - - boot_rails - - assert_nothing_raised { BukkitController } - end - - test "the plugin adds its view to the load path" do - @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY - class BukkitController < ActionController::Base - def index - end - end - RUBY - - @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" - - boot_rails - - require "action_controller" - require "rack/mock" - response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) - assert_equal "Hello bukkits\n", response[2].body - end - - test "the plugin adds helpers to the controller's views" do - @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY - class BukkitController < ActionController::Base - def index - end - end - RUBY - - @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY - module BukkitHelper - def bukkits - "bukkits" - end - end - RUBY - - @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>" - - boot_rails - - require "rack/mock" - response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) - assert_equal "Hello bukkits\n", response[2].body - end - - test "routes.rb are added to the router" do - @plugin.write "config/routes.rb", <<-RUBY - class Sprokkit - def self.call(env) - [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]] - end - end - - ActionController::Routing::Routes.draw do - match "/sprokkit", :to => Sprokkit - end - RUBY - - boot_rails - require "rack/mock" - response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit")) - assert_equal "I am a Sprokkit", response[2].join - end - - test "tasks are loaded by default" do - $executed = false - @plugin.write "lib/tasks/foo.rake", <<-RUBY - task :foo do - $executed = true - end - RUBY - - boot_rails - require 'rake' - require 'rake/rdoctask' - require 'rake/testtask' - Rails.application.load_tasks - Rake::Task[:foo].invoke - assert $executed - end - - test "deprecated tasks are also loaded" do - $executed = false - @plugin.write "tasks/foo.rake", <<-RUBY - task :foo do - $executed = true - end - RUBY - - boot_rails - require 'rake' - require 'rake/rdoctask' - require 'rake/testtask' - Rails.application.load_tasks - Rake::Task[:foo].invoke - assert $executed - end - - test "i18n files are added with lower priority than application ones" do - add_to_config <<-RUBY - config.i18n.load_path << "#{app_path}/app/locales/en.yml" - RUBY - - app_file 'app/locales/en.yml', <<-YAML -en: - bar: "1" -YAML - - app_file 'config/locales/en.yml', <<-YAML -en: - foo: "2" - bar: "2" -YAML - - @plugin.write 'config/locales/en.yml', <<-YAML -en: - foo: "3" -YAML - - boot_rails - - assert_equal %W( - #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - #{app_path}/vendor/plugins/bukkits/config/locales/en.yml - #{app_path}/config/locales/en.yml - #{app_path}/app/locales/en.yml - ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } - - assert_equal "2", I18n.t(:foo) - assert_equal "1", I18n.t(:bar) - end - - test "plugin metals are added to the middleware stack" do - @plugin.write 'app/metal/foo_metal.rb', <<-RUBY - class FooMetal - def self.call(env) - [200, { "Content-Type" => "text/html"}, ["FooMetal"]] - end - end - RUBY - - boot_rails - require 'rack/test' - extend Rack::Test::Methods - - get "/" - assert_equal 200, last_response.status - assert_equal "FooMetal", last_response.body - end - - test "namespaced controllers with namespaced routes" do - @plugin.write "config/routes.rb", <<-RUBY - ActionController::Routing::Routes.draw do - namespace :admin do - match "index", :to => "admin/foo#index" - end - end - RUBY - - @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY - class Admin::FooController < ApplicationController - def index - render :text => "Rendered from namespace" - end - end - RUBY - - boot_rails - - require 'rack/test' - extend Rack::Test::Methods - - get "/admin/index" - assert_equal 200, last_response.status - assert_equal "Rendered from namespace", last_response.body - end - - test "plugin with initializers" do - $plugin_initializer = false - @plugin.write "config/initializers/foo.rb", <<-RUBY - $plugin_initializer = true - RUBY - - boot_rails - assert $plugin_initializer - end - - test "plugin cannot declare an engine for it" do - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - class Engine < Rails::Engine - end - end - RUBY - - @plugin.write "init.rb", <<-RUBY - require "bukkits" - RUBY - - rescued = false - - begin - boot_rails - rescue Exception => e - rescued = true - assert_equal '"bukkits" is a Railtie/Engine and cannot be installed as plugin', e.message - end - - assert rescued, "Expected boot rails to fail" - end - - test "use plugin middleware in application config" do - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - def initialize(app) - @app = app - end - - def call(env) - @app.call(env) - end - end - RUBY - - add_to_config "config.middleware.use \"Bukkits\"" - boot_rails - end - end - - class VendoredOrderingTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - $arr = [] - plugin "a_plugin", "$arr << :a" - plugin "b_plugin", "$arr << :b" - plugin "c_plugin", "$arr << :c" - end - - def boot_rails - super - require "#{app_path}/config/environment" - end - - test "plugins are loaded alphabetically by default" do - boot_rails - assert_equal [:a, :b, :c], $arr - end - - test "if specified, only those plugins are loaded" do - add_to_config "config.plugins = [:b_plugin]" - boot_rails - assert_equal [:b], $arr - end - - test "the plugins are initialized in the order they are specified" do - add_to_config "config.plugins = [:b_plugin, :a_plugin]" - boot_rails - assert_equal [:b, :a], $arr - end - - test "if :all is specified, the remaining plugins are loaded in alphabetical order" do - add_to_config "config.plugins = [:c_plugin, :all]" - boot_rails - assert_equal [:c, :a, :b], $arr - end - - test "if :all is at the beginning, it represents the plugins not otherwise specified" do - add_to_config "config.plugins = [:all, :b_plugin]" - boot_rails - assert_equal [:a, :c, :b], $arr - end - - test "plugin order array is strings" do - add_to_config "config.plugins = %w( c_plugin all )" - boot_rails - assert_equal [:c, :a, :b], $arr - end - end -end diff --git a/railties/test/railties/configuration_test.rb b/railties/test/railties/configuration_test.rb new file mode 100644 index 0000000000..c5ff6dad9c --- /dev/null +++ b/railties/test/railties/configuration_test.rb @@ -0,0 +1,45 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class ConfigurationTest < Test::Unit::TestCase + def setup + build_app + boot_rails + require "rails/all" + end + + test "config is available to plugins" do + class Foo < Rails::Railtie ; end + assert_nil Foo.config.action_controller.foo + end + + test "a config name is available for the plugin" do + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end + assert_equal "hello", Foo.config.foo.greetings + end + + test "plugin configurations are available in the application" do + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end + require "#{app_path}/config/application" + assert_equal "hello", AppTemplate::Application.config.foo.greetings + end + + test "plugin config merges are deep" do + class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end + class Bar < Rails::Railtie + config.foo.bar = "bar" + end + assert_equal "hello", Bar.config.foo.greetings + assert_equal "bar", Bar.config.foo.bar + end + + test "plugin can add subscribers" do + begin + class Foo < Rails::Railtie; subscriber(Rails::Subscriber.new); end + assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] + ensure + Rails::Subscriber.subscribers.clear + end + end + end +end diff --git a/railties/test/railties/framework_extension_test.rb b/railties/test/railties/framework_extension_test.rb new file mode 100644 index 0000000000..84bd6ed16b --- /dev/null +++ b/railties/test/railties/framework_extension_test.rb @@ -0,0 +1,68 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class FrameworkExtensionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + require "rails/all" + end + + test "rake_tasks block is executed when MyApp.load_tasks is called" do + $ran_block = false + + class MyTie < Rails::Railtie + rake_tasks do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + require 'rake' + require 'rake/testtask' + require 'rake/rdoctask' + + AppTemplate::Application.load_tasks + assert $ran_block + end + + test "generators block is executed when MyApp.load_generators is called" do + $ran_block = false + + class MyTie < Rails::Railtie + generators do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + AppTemplate::Application.load_generators + assert $ran_block + end + end + + class ActiveRecordExtensionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + end + + test "active_record extensions are applied to ActiveRecord" do + add_to_config "config.active_record.table_name_prefix = 'tbl_'" + + require "#{app_path}/config/environment" + + assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix + end + end +end \ No newline at end of file diff --git a/railties/test/railties/plugin_ordering_test.rb b/railties/test/railties/plugin_ordering_test.rb new file mode 100644 index 0000000000..a72e59952e --- /dev/null +++ b/railties/test/railties/plugin_ordering_test.rb @@ -0,0 +1,55 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class PluginOrderingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + $arr = [] + plugin "a_plugin", "$arr << :a" + plugin "b_plugin", "$arr << :b" + plugin "c_plugin", "$arr << :c" + end + + def boot_rails + super + require "#{app_path}/config/environment" + end + + test "plugins are loaded alphabetically by default" do + boot_rails + assert_equal [:a, :b, :c], $arr + end + + test "if specified, only those plugins are loaded" do + add_to_config "config.plugins = [:b_plugin]" + boot_rails + assert_equal [:b], $arr + end + + test "the plugins are initialized in the order they are specified" do + add_to_config "config.plugins = [:b_plugin, :a_plugin]" + boot_rails + assert_equal [:b, :a], $arr + end + + test "if :all is specified, the remaining plugins are loaded in alphabetical order" do + add_to_config "config.plugins = [:c_plugin, :all]" + boot_rails + assert_equal [:c, :a, :b], $arr + end + + test "if :all is at the beginning, it represents the plugins not otherwise specified" do + add_to_config "config.plugins = [:all, :b_plugin]" + boot_rails + assert_equal [:a, :c, :b], $arr + end + + test "plugin order array is strings" do + add_to_config "config.plugins = %w( c_plugin all )" + boot_rails + assert_equal [:c, :a, :b], $arr + end + end +end \ No newline at end of file diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb new file mode 100644 index 0000000000..65d057383c --- /dev/null +++ b/railties/test/railties/plugin_test.rb @@ -0,0 +1,334 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class PluginTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + + @plugin = plugin "bukkits", "::LEVEL = config.log_level" do |plugin| + plugin.write "lib/bukkits.rb", "class Bukkits; end" + end + end + + def boot_rails + super + require "#{app_path}/config/environment" + end + + def app + @app ||= Rails.application + end + + test "it loads the plugin's init.rb file" do + boot_rails + assert_equal "loaded", BUKKITS + end + + test "the init.rb file has access to the config object" do + boot_rails + assert_equal :debug, LEVEL + end + + test "the plugin puts its lib directory on the load path" do + boot_rails + require "bukkits" + assert_equal "Bukkits", Bukkits.name + end + + test "plugin init is ran before application initializers" do + plugin "foo", "$foo = true" do |plugin| + plugin.write "lib/foo.rb", "module Foo; end" + end + + app_file 'config/initializers/foo.rb', <<-RUBY + raise "no $foo" unless $foo + raise "no Foo" unless Foo + RUBY + + boot_rails + assert $foo + end + + test "plugin paths get added to the AS::Dependency list" do + boot_rails + assert_equal "Bukkits", Bukkits.name + end + + test "plugin constants do not get reloaded by default" do + boot_rails + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_nothing_raised { Bukkits } + end + + test "plugin constants get reloaded if config.reload_plugins is set" do + add_to_config <<-RUBY + config.reload_plugins = true + RUBY + + boot_rails + + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_raises(NameError) { Bukkits } + end + + test "plugin should work without init.rb" do + @plugin.delete("init.rb") + + boot_rails + + require "bukkits" + assert_nothing_raised { Bukkits } + end + + test "the plugin puts its models directory on the load path" do + @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end" + + boot_rails + + assert_nothing_raised { MyBukkit } + end + + test "the plugin puts is controllers directory on the load path" do + @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end" + + boot_rails + + assert_nothing_raised { BukkitController } + end + + test "the plugin adds its view to the load path" do + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" + + boot_rails + + require "action_controller" + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + test "the plugin adds helpers to the controller's views" do + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY + module BukkitHelper + def bukkits + "bukkits" + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>" + + boot_rails + + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + test "routes.rb are added to the router" do + @plugin.write "config/routes.rb", <<-RUBY + class Sprokkit + def self.call(env) + [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]] + end + end + + ActionController::Routing::Routes.draw do + match "/sprokkit", :to => Sprokkit + end + RUBY + + boot_rails + require "rack/mock" + response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit")) + assert_equal "I am a Sprokkit", response[2].join + end + + test "tasks are loaded by default" do + $executed = false + @plugin.write "lib/tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + + test "deprecated tasks are also loaded" do + $executed = false + @plugin.write "tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + + test "i18n files are added with lower priority than application ones" do + add_to_config <<-RUBY + config.i18n.load_path << "#{app_path}/app/locales/en.yml" + RUBY + + app_file 'app/locales/en.yml', <<-YAML +en: + bar: "1" +YAML + + app_file 'config/locales/en.yml', <<-YAML +en: + foo: "2" + bar: "2" +YAML + + @plugin.write 'config/locales/en.yml', <<-YAML +en: + foo: "3" +YAML + + boot_rails + + assert_equal %W( + #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml + #{app_path}/vendor/plugins/bukkits/config/locales/en.yml + #{app_path}/config/locales/en.yml + #{app_path}/app/locales/en.yml + ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } + + assert_equal "2", I18n.t(:foo) + assert_equal "1", I18n.t(:bar) + end + + test "plugin metals are added to the middleware stack" do + @plugin.write 'app/metal/foo_metal.rb', <<-RUBY + class FooMetal + def self.call(env) + [200, { "Content-Type" => "text/html"}, ["FooMetal"]] + end + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal 200, last_response.status + assert_equal "FooMetal", last_response.body + end + + test "namespaced controllers with namespaced routes" do + @plugin.write "config/routes.rb", <<-RUBY + ActionController::Routing::Routes.draw do + namespace :admin do + match "index", :to => "admin/foo#index" + end + end + RUBY + + @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY + class Admin::FooController < ApplicationController + def index + render :text => "Rendered from namespace" + end + end + RUBY + + boot_rails + + require 'rack/test' + extend Rack::Test::Methods + + get "/admin/index" + assert_equal 200, last_response.status + assert_equal "Rendered from namespace", last_response.body + end + + test "plugin with initializers" do + $plugin_initializer = false + @plugin.write "config/initializers/foo.rb", <<-RUBY + $plugin_initializer = true + RUBY + + boot_rails + assert $plugin_initializer + end + + test "plugin cannot declare an engine for it" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < Rails::Engine + end + end + RUBY + + @plugin.write "init.rb", <<-RUBY + require "bukkits" + RUBY + + rescued = false + + begin + boot_rails + rescue Exception => e + rescued = true + assert_equal '"bukkits" is a Railtie/Engine and cannot be installed as plugin', e.message + end + + assert rescued, "Expected boot rails to fail" + end + + test "use plugin middleware in application config" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + def initialize(app) + @app = app + end + + def call(env) + @app.call(env) + end + end + RUBY + + add_to_config "config.middleware.use \"Bukkits\"" + boot_rails + end + end +end -- cgit v1.2.3 From 3086dbd8d0705bc8e5e45cb04d9f8191f85a2685 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 25 Jan 2010 16:33:29 -0600 Subject: Failing test for plugin init requiring another plugin lib file --- railties/test/plugins/vendored_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties') diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb index c14178ec66..940648a0b6 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/plugins/vendored_test.rb @@ -382,5 +382,22 @@ YAML boot_rails assert_equal [:c, :a, :b], $arr end + + test "can require lib file from a different plugin" do + plugin "foo", "require 'bar'" do |plugin| + plugin.write "lib/foo.rb", "$foo = true" + end + + plugin "bar", "require 'foo'" do |plugin| + plugin.write "lib/bar.rb", "$bar = true" + end + + add_to_config "config.plugins = [:foo, :bar]" + + boot_rails + + assert $foo + assert $bar + end end end -- cgit v1.2.3 From 5d078692453c454289823700b67e64bcd4c8de7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 00:08:08 +0100 Subject: Ensure all initializers are collections. --- railties/lib/rails/application.rb | 4 +-- railties/lib/rails/application/bootstrap.rb | 42 ++++++++++++++--------------- railties/lib/rails/application/finisher.rb | 16 +++++------ railties/lib/rails/initializable.rb | 9 ++++--- 4 files changed, 36 insertions(+), 35 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 6633c36a21..b7e5eb7a1d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -90,10 +90,10 @@ module Rails end def initializers - initializers = Bootstrap.initializers + initializers = Bootstrap.initializers_for(self) railties.all { |r| initializers += r.initializers } initializers += super - initializers += Finisher.initializers + initializers += Finisher.initializers_for(self) initializers end diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index f038027c97..b20e53f2de 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -3,28 +3,28 @@ module Rails module Bootstrap include Initializable - initializer :load_environment_config do |app| - app.require_environment! + initializer :load_environment_config do + require_environment! end - initializer :load_all_active_support do |app| - require "active_support/all" unless app.config.active_support.bare + initializer :load_all_active_support do + require "active_support/all" unless config.active_support.bare 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. - initializer :preload_frameworks do |app| + initializer :preload_frameworks do require 'active_support/dependencies' - ActiveSupport::Autoload.eager_autoload! if app.config.preload_frameworks + ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks end # Initialize the logger early in the stack in case we need to log some deprecation. - initializer :initialize_logger do |app| - Rails.logger ||= app.config.logger || begin - path = app.config.paths.log.to_a.first + initializer :initialize_logger do + Rails.logger ||= config.logger || begin + path = config.paths.log.to_a.first logger = ActiveSupport::BufferedLogger.new(path) - logger.level = ActiveSupport::BufferedLogger.const_get(app.config.log_level.to_s.upcase) + logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) logger.auto_flushing = false if Rails.env.production? logger rescue StandardError => e @@ -39,23 +39,23 @@ module Rails end # Initialize cache early in the stack so railties can make use of it. - initializer :initialize_cache do |app| + initializer :initialize_cache do unless defined?(RAILS_CACHE) - silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(app.config.cache_store) } + silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) } if RAILS_CACHE.respond_to?(:middleware) - app.config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) + config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware) end end end # Initialize rails subscriber on top of notifications. - initializer :initialize_subscriber do |app| + initializer :initialize_subscriber do require 'active_support/notifications' - if app.config.colorize_logging == false - Rails::Subscriber.colorize_logging = false - app.config.generators.colorize_logging = false + if config.colorize_logging == false + Rails::Subscriber.colorize_logging = false + config.generators.colorize_logging = false end ActiveSupport::Notifications.subscribe do |*args| @@ -63,8 +63,8 @@ module Rails end end - initializer :set_clear_dependencies_hook do |app| - unless app.config.cache_classes + initializer :set_clear_dependencies_hook do + unless config.cache_classes ActionDispatch::Callbacks.after do ActiveSupport::Dependencies.clear end @@ -73,8 +73,8 @@ module Rails # Sets the dependency loading mechanism. # TODO: Remove files from the $" and always use require. - initializer :initialize_dependency_mechanism do |app| - ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load + initializer :initialize_dependency_mechanism do + ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end initializer :bootstrap_load_path do diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 5cc5b4ae88..d67420938a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -15,26 +15,26 @@ module Rails end end - initializer :add_builtin_route do |app| + initializer :add_builtin_route do if Rails.env.development? Rails::Application::RoutesReloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end - initializer :build_middleware_stack do |app| - app.app + initializer :build_middleware_stack do + app end # Fires the user-supplied after_initialize block (config#after_initialize) - initializer :after_initialize do |app| - app.config.after_initialize_blocks.each do |block| - block.call(app) + initializer :after_initialize do + config.after_initialize_blocks.each do |block| + block.call(self) end end # Disable dependency loading during request cycle - initializer :disable_dependency_loading do |app| - if app.config.cache_classes && !app.config.dependency_loading + initializer :disable_dependency_loading do + if config.cache_classes && !config.dependency_loading ActiveSupport::Dependencies.unhook! end end diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index cea4a0fdf7..d91f67823f 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -64,10 +64,7 @@ module Rails end def initializers - @initializers ||= begin - initializers = self.class.initializers_chain - Collection.new(initializers.map { |i| i.bind(self) }) - end + @initializers ||= self.class.initializers_for(self) end module ClassMethods @@ -84,6 +81,10 @@ module Rails initializers end + def initializers_for(binding) + Collection.new(initializers_chain.map { |i| i.bind(binding) }) + end + def initializer(name, opts = {}, &blk) raise ArgumentError, "A block must be passed when defining an initializer" unless blk initializers << Initializer.new(name, nil, opts, &blk) -- cgit v1.2.3 From 1b3cb54ebae685d4db9eefc99ce68b36d5641751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Tue, 26 Jan 2010 01:06:48 +0100 Subject: More work on generated mailer templates. --- railties/lib/generators/erb/mailer/mailer_generator.rb | 2 +- railties/lib/generators/erb/mailer/templates/view.erb | 3 --- railties/lib/generators/erb/mailer/templates/view.text.erb | 3 +++ railties/lib/generators/rails/mailer/templates/mailer.rb | 4 ++-- .../generators/test_unit/mailer/templates/functional_test.rb | 10 +++------- railties/test/generators/mailer_generator_test.rb | 11 +++++------ railties/test/generators/named_base_test.rb | 8 ++++++++ 7 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 railties/lib/generators/erb/mailer/templates/view.erb create mode 100644 railties/lib/generators/erb/mailer/templates/view.text.erb (limited to 'railties') diff --git a/railties/lib/generators/erb/mailer/mailer_generator.rb b/railties/lib/generators/erb/mailer/mailer_generator.rb index 4ec2f4c9f4..408c942cef 100644 --- a/railties/lib/generators/erb/mailer/mailer_generator.rb +++ b/railties/lib/generators/erb/mailer/mailer_generator.rb @@ -12,7 +12,7 @@ module Erb def create_view_files actions.each do |action| @action, @path = action, File.join(file_path, action) - template "view.erb", File.join("app/views", "#{@path}.erb") + template "view.text.erb", File.join("app/views", "#{@path}.text.erb") end end end diff --git a/railties/lib/generators/erb/mailer/templates/view.erb b/railties/lib/generators/erb/mailer/templates/view.erb deleted file mode 100644 index 6d597256a6..0000000000 --- a/railties/lib/generators/erb/mailer/templates/view.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= class_name %>#<%= @action %> - -<%%= @greeting %>, find me in app/views/<%= @path %> diff --git a/railties/lib/generators/erb/mailer/templates/view.text.erb b/railties/lib/generators/erb/mailer/templates/view.text.erb new file mode 100644 index 0000000000..6d597256a6 --- /dev/null +++ b/railties/lib/generators/erb/mailer/templates/view.text.erb @@ -0,0 +1,3 @@ +<%= class_name %>#<%= @action %> + +<%%= @greeting %>, find me in app/views/<%= @path %> diff --git a/railties/lib/generators/rails/mailer/templates/mailer.rb b/railties/lib/generators/rails/mailer/templates/mailer.rb index 5e7ef42370..1685b73633 100644 --- a/railties/lib/generators/rails/mailer/templates/mailer.rb +++ b/railties/lib/generators/rails/mailer/templates/mailer.rb @@ -1,5 +1,5 @@ class <%= class_name %> < ActionMailer::Base - delivers_from "mail@<%= application_name %>.com" + delivers_from "from@example.com" <% for action in actions -%> # Subject can be set in your I18n file at config/locales/en.yml @@ -9,7 +9,7 @@ class <%= class_name %> < ActionMailer::Base # def <%= action %> @greeting = "Hi" - mail(:to => "") + mail(:to => "to@example.com") end <% end -%> end \ No newline at end of file diff --git a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb index 2f694e431c..fcebb40135 100644 --- a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb @@ -3,17 +3,13 @@ require 'test_helper' class <%= class_name %>Test < ActionMailer::TestCase <% for action in actions -%> test "<%= action %>" do - @actual = <%= class_name %>.<%= action %> - @expected.subject = <%= action.to_s.humanize.inspect %> + @expected.to = "to@example.com" + @expected.from = "from@example.com" @expected.body = read_fixture("<%= action %>") @expected.date = Time.now - assert_difference "<%= class_name %>.deliveries.size" do - @actual.deliver - end - - assert_equal @expected.encoded, @actual.encoded + assert_equal @expected, <%= class_name %>.<%= action %> end <% end -%> diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 0203eb314c..99ce53323e 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -6,11 +6,10 @@ class MailerGeneratorTest < Rails::Generators::TestCase arguments %w(notifier foo bar) def test_mailer_skeleton_is_created - Rails.stubs(:application).returns(Object.new) run_generator assert_file "app/mailers/notifier.rb" do |mailer| assert_match /class Notifier < ActionMailer::Base/, mailer - assert_match /delivers_from "mail@object.com"/, mailer + assert_match /delivers_from "from@example.com"/, mailer end end @@ -36,12 +35,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_template_engine run_generator - assert_file "app/views/notifier/foo.erb" do |view| + assert_file "app/views/notifier/foo.text.erb" do |view| assert_match /app\/views\/notifier\/foo/, view assert_match /<%= @greeting %>/, view end - assert_file "app/views/notifier/bar.erb" do |view| + assert_file "app/views/notifier/bar.text.erb" do |view| assert_match /app\/views\/notifier\/bar/, view assert_match /<%= @greeting %>/, view end @@ -62,12 +61,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase assert_file "app/mailers/notifier.rb" do |mailer| assert_instance_method :foo, mailer do |foo| - assert_match /mail\(:to => ""\)/, foo + assert_match /mail\(:to => "to@example.com"\)/, foo assert_match /@greeting = "Hi"/, foo end assert_instance_method :bar, mailer do |bar| - assert_match /mail\(:to => ""\)/, bar + assert_match /mail\(:to => "to@example.com"\)/, bar assert_match /@greeting = "Hi"/, bar end end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 7514bc32bd..f327fb1282 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -67,6 +67,14 @@ class NamedBaseTest < Rails::Generators::TestCase assert_name g, 'admin.foos', :controller_i18n_scope end + def test_application_name + g = generator ['Admin::Foo'] + Rails.stubs(:application).returns(Object.new) + assert_name g, "object", :application_name + Rails.stubs(:application).returns(nil) + assert_name g, "application", :application_name + end + protected def assert_name(generator, value, method) -- cgit v1.2.3 From b8c82edc1f5b95bceea3d40de778ec0cd5a37d15 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Tue, 26 Jan 2010 18:59:52 +1100 Subject: Updating generators for mailer to reflect changes in API --- railties/lib/generators/rails/mailer/templates/mailer.rb | 4 ++-- railties/test/generators/mailer_generator_test.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/rails/mailer/templates/mailer.rb b/railties/lib/generators/rails/mailer/templates/mailer.rb index 1685b73633..df9d0a0923 100644 --- a/railties/lib/generators/rails/mailer/templates/mailer.rb +++ b/railties/lib/generators/rails/mailer/templates/mailer.rb @@ -1,5 +1,5 @@ class <%= class_name %> < ActionMailer::Base - delivers_from "from@example.com" + self.defaults = { :from => "from@example.com" } <% for action in actions -%> # Subject can be set in your I18n file at config/locales/en.yml @@ -9,7 +9,7 @@ class <%= class_name %> < ActionMailer::Base # def <%= action %> @greeting = "Hi" - mail(:to => "to@example.com") + mail(:to => "to@example.org") end <% end -%> end \ No newline at end of file diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 99ce53323e..e585298a93 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -9,7 +9,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase run_generator assert_file "app/mailers/notifier.rb" do |mailer| assert_match /class Notifier < ActionMailer::Base/, mailer - assert_match /delivers_from "from@example.com"/, mailer + assert_match /self\.defaults\ =\ \{\ :from\ =>\ "from@example\.com"\ \}/, mailer end end @@ -61,12 +61,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase assert_file "app/mailers/notifier.rb" do |mailer| assert_instance_method :foo, mailer do |foo| - assert_match /mail\(:to => "to@example.com"\)/, foo + assert_match /mail\(:to => "to@example.org"\)/, foo assert_match /@greeting = "Hi"/, foo end assert_instance_method :bar, mailer do |bar| - assert_match /mail\(:to => "to@example.com"\)/, bar + assert_match /mail\(:to => "to@example.org"\)/, bar assert_match /@greeting = "Hi"/, bar end end -- cgit v1.2.3 From 8fabcb2eca03150b1c0c3dbc88dd13123f76894f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Tue, 26 Jan 2010 11:48:25 +0100 Subject: Update generators to use new defaults. --- railties/lib/generators/rails/mailer/templates/mailer.rb | 2 +- railties/test/generators/mailer_generator_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/rails/mailer/templates/mailer.rb b/railties/lib/generators/rails/mailer/templates/mailer.rb index df9d0a0923..cdc6e41266 100644 --- a/railties/lib/generators/rails/mailer/templates/mailer.rb +++ b/railties/lib/generators/rails/mailer/templates/mailer.rb @@ -1,5 +1,5 @@ class <%= class_name %> < ActionMailer::Base - self.defaults = { :from => "from@example.com" } + self.defaults :from => "from@example.com" <% for action in actions -%> # Subject can be set in your I18n file at config/locales/en.yml diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index e585298a93..0b7f5c6817 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -9,7 +9,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase run_generator assert_file "app/mailers/notifier.rb" do |mailer| assert_match /class Notifier < ActionMailer::Base/, mailer - assert_match /self\.defaults\ =\ \{\ :from\ =>\ "from@example\.com"\ \}/, mailer + assert_match /self\.defaults :from => "from@example.com"/, mailer end end -- cgit v1.2.3 From db99324a89a2a681c6f6b0957dac7a309bfca574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 12:14:48 +0100 Subject: Ensure calling a method in Rails::Application does not instantiate a void application. --- railties/lib/rails/application.rb | 6 +++--- railties/test/application/configuration_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b7e5eb7a1d..eba49e1520 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -16,10 +16,10 @@ module Rails alias :configure :class_eval def instance - if instance_of?(Rails::Application) - Rails.application.instance + if self == Rails::Application + Rails.application else - @instance ||= new + @@instance ||= new end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6968e87986..d3ba54a668 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -19,6 +19,13 @@ module ApplicationTests FileUtils.rm_rf("#{app_path}/config/environments") end + test "Rails::Application.instance is nil until app is initialized" do + require 'rails' + assert_nil Rails::Application.instance + require "#{app_path}/config/environment" + assert_equal AppTemplate::Application.instance, Rails::Application.instance + end + test "the application root is set correctly" do require "#{app_path}/config/environment" assert_equal Pathname.new(app_path), Rails.application.root -- cgit v1.2.3 From 007c0bb3b0e678f685fb82c1eb6c20e73f601b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 12:16:37 +0100 Subject: Ensure proper class is shown on rake middleware. --- railties/lib/rails/tasks/middleware.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake index c3aaddb153..62e10e2beb 100644 --- a/railties/lib/rails/tasks/middleware.rake +++ b/railties/lib/rails/tasks/middleware.rake @@ -3,5 +3,5 @@ task :middleware => :environment do Rails.configuration.middleware.active.each do |middleware| puts "use #{middleware.inspect}" end - puts "run #{Rails::Application.class.name}" + puts "run #{Rails::Application.instance.class.name}" end -- cgit v1.2.3 From e6da2f651ffc24e5be3842051df73493d158a6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 12:23:02 +0100 Subject: Ensure app does not show up in generators. --- railties/lib/rails/generators.rb | 1 + railties/test/generators_test.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 83b8c74966..2281746b00 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -200,6 +200,7 @@ module Rails # Print Rails defaults first. rails = groups.delete("rails") rails.map! { |n| n.sub(/^rails:/, '') } + rails.delete("app") print_list("rails", rails) groups.sort.each { |b, n| print_list(b, n) } diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index f37b684f73..33cc27bd84 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -99,6 +99,7 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /Rails:/, output assert_match /^ model$/, output assert_match /^ scaffold_controller$/, output + assert_no_match /^ app$/, output end def test_rails_generators_with_others_information -- cgit v1.2.3 From 1dca7ebc93ebf067a73d23ddc33d97229a0b482f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 13:57:11 +0100 Subject: Refactor railties test, break huge files in smaller chunks and move initializers to application folder. --- railties/test/application/configuration_test.rb | 23 +- railties/test/application/generators_test.rb | 13 - railties/test/application/initializer_test.rb | 196 ------------- .../test/application/initializers/boot_test.rb | 16 ++ .../initializers/check_ruby_version_test.rb | 33 +++ .../application/initializers/frameworks_test.rb | 80 ++++++ .../test/application/initializers/i18n_test.rb | 55 ++++ .../application/initializers/initializers_test.rb | 55 ++++ .../application/initializers/load_path_test.rb | 62 ++++ .../application/initializers/notifications_test.rb | 48 ++++ railties/test/application/load_test.rb | 46 --- railties/test/application/notifications_test.rb | 48 ---- railties/test/application/paths_test.rb | 99 +++++++ railties/test/application/rackup_test.rb | 46 +++ railties/test/application/routing_test.rb | 78 +++-- railties/test/initializer/boot_test.rb | 16 -- .../test/initializer/check_ruby_version_test.rb | 33 --- railties/test/initializer/path_test.rb | 99 ------- railties/test/railties/framework_extension_test.rb | 14 + railties/test/railties/plugin_test.rb | 280 +----------------- railties/test/railties/shared_tests.rb | 318 +++++++++++++++++++++ 21 files changed, 869 insertions(+), 789 deletions(-) delete mode 100644 railties/test/application/initializer_test.rb create mode 100644 railties/test/application/initializers/boot_test.rb create mode 100644 railties/test/application/initializers/check_ruby_version_test.rb create mode 100644 railties/test/application/initializers/frameworks_test.rb create mode 100644 railties/test/application/initializers/i18n_test.rb create mode 100644 railties/test/application/initializers/initializers_test.rb create mode 100644 railties/test/application/initializers/load_path_test.rb create mode 100644 railties/test/application/initializers/notifications_test.rb delete mode 100644 railties/test/application/load_test.rb delete mode 100644 railties/test/application/notifications_test.rb create mode 100644 railties/test/application/paths_test.rb create mode 100644 railties/test/application/rackup_test.rb delete mode 100644 railties/test/initializer/boot_test.rb delete mode 100644 railties/test/initializer/check_ruby_version_test.rb delete mode 100644 railties/test/initializer/path_test.rb create mode 100644 railties/test/railties/shared_tests.rb (limited to 'railties') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index d3ba54a668..666c47af67 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module ApplicationTests - class InitializerTest < Test::Unit::TestCase + class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def new_app @@ -59,21 +59,12 @@ module ApplicationTests end end - test "if there's no config.active_support.bare, all of ActiveSupport is required" do - use_frameworks [] + test "Rails.root should be a Pathname" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY require "#{app_path}/config/environment" - assert_nothing_raised { [1,2,3].rand } - end - - test "config.active_support.bare does not require all of ActiveSupport" do - add_to_config "config.active_support.bare = true" - - use_frameworks [] - - Dir.chdir("#{app_path}/app") do - require "#{app_path}/config/environment" - assert_raises(NoMethodError) { [1,2,3].rand } - end + assert_instance_of Pathname, Rails.root end test "marking the application as threadsafe sets the correct config variables" do @@ -136,7 +127,7 @@ module ApplicationTests value = value.reverse if key =~ /baz/ }] RUBY - + assert_nothing_raised do require "#{app_path}/config/application" end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index e1e51c318c..1e6e30e9c3 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -92,18 +92,5 @@ module ApplicationTests assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases) end end - - test "generators with hashes are deep merged" do - with_config do |c| - c.generators do |g| - g.orm :datamapper, :migration => false - g.plugin :aliases => { :generator => "-g" }, - :generator => true - end - end - - assert Rails::Generators.aliases.size >= 1 - assert Rails::Generators.options.size >= 1 - end end end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb deleted file mode 100644 index 053757979b..0000000000 --- a/railties/test/application/initializer_test.rb +++ /dev/null @@ -1,196 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class InitializerTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - test "initializing an application adds the application paths to the load path" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - require "#{app_path}/config/environment" - assert $:.include?("#{app_path}/app/models") - end - - test "eager loading loads parent classes before children" do - app_file "lib/zoo.rb", <<-ZOO - class Zoo ; include ReptileHouse ; end - ZOO - app_file "lib/zoo/reptile_house.rb", <<-ZOO - module Zoo::ReptileHouse ; end - ZOO - - add_to_config <<-RUBY - config.root = "#{app_path}" - config.eager_load_paths << "#{app_path}/lib" - RUBY - - require "#{app_path}/config/environment" - - assert Zoo - end - - test "load environment with global" do - app_file "config/environments/development.rb", <<-RUBY - $initialize_test_set_from_env = 'success' - AppTemplate::Application.configure do - config.cache_classes = true - config.time_zone = "Brasilia" - end - RUBY - - assert_nil $initialize_test_set_from_env - add_to_config <<-RUBY - config.root = "#{app_path}" - config.time_zone = "UTC" - RUBY - - require "#{app_path}/config/environment" - assert_equal "success", $initialize_test_set_from_env - assert AppTemplate::Application.config.cache_classes - assert_equal "Brasilia", AppTemplate::Application.config.time_zone - end - - test "action_controller load paths set only if action controller in use" do - assert_nothing_raised NameError do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - use_frameworks [] - require "#{app_path}/config/environment" - end - end - - test "after_initialize block works correctly" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize { $test_after_initialize_block1 = "success" } - config.after_initialize { $test_after_initialize_block2 = "congratulations" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - - test "after_initialize block works correctly when no block is passed" do - add_to_config <<-RUBY - 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" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - - test "after_initialize runs after frameworks have been initialized" do - $activerecord_configurations = nil - add_to_config <<-RUBY - config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } - RUBY - - require "#{app_path}/config/environment" - assert $activerecord_configurations - assert $activerecord_configurations['development'] - end - - # i18n - test "setting another default locale" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.default_locale = :de - RUBY - require "#{app_path}/config/environment" - - assert_equal :de, I18n.default_locale - end - - test "no config locales dir present should return empty load path" do - FileUtils.rm_rf "#{app_path}/config/locales" - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - require "#{app_path}/config/environment" - - assert_equal [], Rails.application.config.i18n.load_path - end - - test "config locales dir present should be added to load path" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - require "#{app_path}/config/environment" - assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path - end - - test "config defaults should be added with config settings" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.load_path << "my/other/locale.yml" - RUBY - require "#{app_path}/config/environment" - - assert_equal [ - "#{app_path}/config/locales/en.yml", "my/other/locale.yml" - ], Rails.application.config.i18n.load_path - end - - # DB middleware - test "database middleware doesn't initialize when session store is not active_record" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.action_controller.session_store = :cookie_store - RUBY - require "#{app_path}/config/environment" - - assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) - end - - test "database middleware initializes when session store is active record" do - add_to_config "config.action_controller.session_store = :active_record_store" - - require "#{app_path}/config/environment" - - expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] - middleware = Rails.application.config.middleware.map { |m| m.klass } - assert_equal expects, middleware & expects - end - - test "Rails.root should be a Pathname" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - require "#{app_path}/config/environment" - assert_instance_of Pathname, Rails.root - end - end - - class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - test "database middleware doesn't initialize when activerecord is not in frameworks" do - use_frameworks [] - require "#{app_path}/config/environment" - - assert_nil defined?(ActiveRecord) - end - end -end diff --git a/railties/test/application/initializers/boot_test.rb b/railties/test/application/initializers/boot_test.rb new file mode 100644 index 0000000000..5ec562f12f --- /dev/null +++ b/railties/test/application/initializers/boot_test.rb @@ -0,0 +1,16 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class GemBooting < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + # build_app + # boot_rails + end + + test "booting rails sets the load paths correctly" do + # This test is pending reworking the boot process + end + end +end \ No newline at end of file diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb new file mode 100644 index 0000000000..58782b2511 --- /dev/null +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -0,0 +1,33 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class CheckRubyVersionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + test "rails initializes with ruby 1.8.7 or later" do + if RUBY_VERSION < '1.8.7' + assert_rails_does_not_boot + else + assert_rails_boots + end + end + + def assert_rails_boots + assert_nothing_raised "It appears that rails does not boot" do + require "rails/all" + end + end + + def assert_rails_does_not_boot + $stderr = File.open("/dev/null", "w") + assert_raises(SystemExit) do + require "rails/all" + end + end + end +end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb new file mode 100644 index 0000000000..ea052320ef --- /dev/null +++ b/railties/test/application/initializers/frameworks_test.rb @@ -0,0 +1,80 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class FrameworlsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # AC & AM + test "set load paths set only if action controller or action mailer are in use" do + assert_nothing_raised NameError do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + use_frameworks [] + require "#{app_path}/config/environment" + end + end + + test "sets action_controller and action_mailer load paths" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + ActionController::Base.view_paths.include?(File.expand_path("app/views", app_path)) + ActionMailer::Base.view_paths.include?(File.expand_path("app/views", app_path)) + end + + # AS + test "if there's no config.active_support.bare, all of ActiveSupport is required" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_nothing_raised { [1,2,3].rand } + end + + test "config.active_support.bare does not require all of ActiveSupport" do + add_to_config "config.active_support.bare = true" + + use_frameworks [] + + Dir.chdir("#{app_path}/app") do + require "#{app_path}/config/environment" + assert_raises(NoMethodError) { [1,2,3].rand } + end + end + + # AR + test "database middleware doesn't initialize when session store is not active_record" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.action_controller.session_store = :cookie_store + RUBY + require "#{app_path}/config/environment" + + assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) + end + + test "database middleware initializes when session store is active record" do + add_to_config "config.action_controller.session_store = :active_record_store" + + require "#{app_path}/config/environment" + + expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] + middleware = Rails.application.config.middleware.map { |m| m.klass } + assert_equal expects, middleware & expects + end + + test "database middleware doesn't initialize when activerecord is not in frameworks" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_nil defined?(ActiveRecord) + end + end +end diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb new file mode 100644 index 0000000000..99b2d86013 --- /dev/null +++ b/railties/test/application/initializers/i18n_test.rb @@ -0,0 +1,55 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class I18nTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # i18n + test "setting another default locale" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.i18n.default_locale = :de + RUBY + require "#{app_path}/config/environment" + + assert_equal :de, I18n.default_locale + end + + test "no config locales dir present should return empty load path" do + FileUtils.rm_rf "#{app_path}/config/locales" + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + require "#{app_path}/config/environment" + + assert_equal [], Rails.application.config.i18n.load_path + end + + test "config locales dir present should be added to load path" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path + end + + test "config defaults should be added with config settings" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.i18n.load_path << "my/other/locale.yml" + RUBY + require "#{app_path}/config/environment" + + assert_equal [ + "#{app_path}/config/locales/en.yml", "my/other/locale.yml" + ], Rails.application.config.i18n.load_path + end + end +end \ No newline at end of file diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb new file mode 100644 index 0000000000..0c3de7ce33 --- /dev/null +++ b/railties/test/application/initializers/initializers_test.rb @@ -0,0 +1,55 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializersTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + test "load initializers" do + app_file "config/initializers/foo.rb", "$foo = true" + require "#{app_path}/config/environment" + assert $foo + end + + test "after_initialize block works correctly" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.after_initialize { $test_after_initialize_block1 = "success" } + config.after_initialize { $test_after_initialize_block2 = "congratulations" } + RUBY + require "#{app_path}/config/environment" + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + test "after_initialize block works correctly when no block is passed" do + add_to_config <<-RUBY + 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" } + RUBY + require "#{app_path}/config/environment" + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + test "after_initialize runs after frameworks have been initialized" do + $activerecord_configurations = nil + add_to_config <<-RUBY + config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } + RUBY + + require "#{app_path}/config/environment" + assert $activerecord_configurations + assert $activerecord_configurations['development'] + end + end +end diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb new file mode 100644 index 0000000000..714b6114a2 --- /dev/null +++ b/railties/test/application/initializers/load_path_test.rb @@ -0,0 +1,62 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class LoadPathTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # General + test "initializing an application adds the application paths to the load path" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + assert $:.include?("#{app_path}/app/models") + end + + test "eager loading loads parent classes before children" do + app_file "lib/zoo.rb", <<-ZOO + class Zoo ; include ReptileHouse ; end + ZOO + app_file "lib/zoo/reptile_house.rb", <<-ZOO + module Zoo::ReptileHouse ; end + ZOO + + add_to_config <<-RUBY + config.root = "#{app_path}" + config.eager_load_paths << "#{app_path}/lib" + RUBY + + require "#{app_path}/config/environment" + + assert Zoo + end + + test "load environment with global" do + app_file "config/environments/development.rb", <<-RUBY + $initialize_test_set_from_env = 'success' + AppTemplate::Application.configure do + config.cache_classes = true + config.time_zone = "Brasilia" + end + RUBY + + assert_nil $initialize_test_set_from_env + add_to_config <<-RUBY + config.root = "#{app_path}" + config.time_zone = "UTC" + RUBY + + require "#{app_path}/config/environment" + assert_equal "success", $initialize_test_set_from_env + assert AppTemplate::Application.config.cache_classes + assert_equal "Brasilia", AppTemplate::Application.config.time_zone + end + end +end diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb new file mode 100644 index 0000000000..061bb34c19 --- /dev/null +++ b/railties/test/application/initializers/notifications_test.rb @@ -0,0 +1,48 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class MockLogger + def method_missing(*args) + @logged ||= [] + @logged << args.last + end + + def logged + @logged.compact.map { |l| l.to_s.strip } + end + end + + class NotificationsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + def instrument(*args, &block) + ActiveSupport::Notifications.instrument(*args, &block) + end + + def wait + ActiveSupport::Notifications.notifier.wait + end + + test "rails subscribers are added" do + add_to_config <<-RUBY + config.colorize_logging = false + RUBY + + require "#{app_path}/config/environment" + + ActiveRecord::Base.logger = logger = MockLogger.new + + # Mimic ActiveRecord notifications + instrument "active_record.sql", :name => "SQL", :sql => "SHOW tables" + wait + + assert_equal 1, logger.logged.size + assert_match /SHOW tables/, logger.logged.last + end + end +end diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb deleted file mode 100644 index 1c5811b07a..0000000000 --- a/railties/test/application/load_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class LoadTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def rackup - require "rack" - app, options = Rack::Builder.parse_file("#{app_path}/config.ru") - app - end - - def setup - build_app - boot_rails - end - - test "rails app is present" do - assert File.exist?(app_path("config")) - end - - test "config.ru can be racked up" do - Dir.chdir app_path do - @app = rackup - assert_welcome get("/") - end - end - - test "Rails.application is available after config.ru has been racked up" do - rackup - assert Rails.application.is_a?(Rails::Application) - end - - # Passenger still uses AC::Dispatcher, so we need to - # keep it working for now - test "deprecated ActionController::Dispatcher still works" do - rackup - assert ActionController::Dispatcher.new.is_a?(Rails::Application) - end - - test "the config object is available on the application object" do - rackup - assert_equal 'UTC', Rails.application.config.time_zone - end - end -end diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb deleted file mode 100644 index 061bb34c19..0000000000 --- a/railties/test/application/notifications_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class MockLogger - def method_missing(*args) - @logged ||= [] - @logged << args.last - end - - def logged - @logged.compact.map { |l| l.to_s.strip } - end - end - - class NotificationsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - end - - def instrument(*args, &block) - ActiveSupport::Notifications.instrument(*args, &block) - end - - def wait - ActiveSupport::Notifications.notifier.wait - end - - test "rails subscribers are added" do - add_to_config <<-RUBY - config.colorize_logging = false - RUBY - - require "#{app_path}/config/environment" - - ActiveRecord::Base.logger = logger = MockLogger.new - - # Mimic ActiveRecord notifications - instrument "active_record.sql", :name => "SQL", :sql => "SHOW tables" - wait - - assert_equal 1, logger.logged.size - assert_match /SHOW tables/, logger.logged.last - end - end -end diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb new file mode 100644 index 0000000000..ac0aa27c64 --- /dev/null +++ b/railties/test/application/paths_test.rb @@ -0,0 +1,99 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class PathsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + app_file "config/environments/development.rb", "" + add_to_config <<-RUBY + config.root = "#{app_path}" + config.after_initialize do + ActionController::Base.session_store = nil + end + RUBY + use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] + require "#{app_path}/config/environment" + @paths = Rails.application.config.paths + end + + def root(*path) + app_path(*path).to_s + end + + def assert_path(paths, *dir) + assert_equal [root(*dir)], paths.paths + end + + def assert_in_load_path(*path) + assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + def assert_not_in_load_path(*path) + assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + test "booting up Rails yields a valid paths object" do + assert_path @paths.app.models, "app", "models" + assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.helpers, "app", "helpers" + assert_path @paths.app.views, "app", "views" + assert_path @paths.lib, "lib" + assert_path @paths.vendor, "vendor" + assert_path @paths.vendor.plugins, "vendor", "plugins" + assert_path @paths.tmp, "tmp" + assert_path @paths.tmp.cache, "tmp", "cache" + assert_path @paths.config, "config" + assert_path @paths.config.locales, "config", "locales", "en.yml" + assert_path @paths.config.environment, "config", "environments", "development.rb" + + assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first + assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, + Pathname.new(@paths.app.controllers.to_a[1]).expand_path + end + + test "booting up Rails yields a list of paths that are eager" do + assert @paths.app.eager_load? + assert @paths.app.controllers.eager_load? + assert @paths.app.helpers.eager_load? + end + + test "environments has a glob equal to the current environment" do + assert_equal "#{Rails.env}.rb", @paths.config.environment.glob + end + + test "load path includes each of the paths in config.paths as long as the directories exist" do + assert_in_load_path "app", "controllers" + assert_in_load_path "app", "models" + assert_in_load_path "app", "helpers" + assert_in_load_path "lib" + assert_in_load_path "vendor" + + assert_not_in_load_path "app", "metal" + assert_not_in_load_path "config" + assert_not_in_load_path "config", "locales" + assert_not_in_load_path "config", "environments" + assert_not_in_load_path "tmp" + assert_not_in_load_path "tmp", "cache" + end + + test "controller paths include builtin in development mode" do + Rails.env.replace "development" + assert Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in test mode" do + Rails.env.replace "test" + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in production mode" do + Rails.env.replace "production" + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + end +end diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb new file mode 100644 index 0000000000..f909c1b282 --- /dev/null +++ b/railties/test/application/rackup_test.rb @@ -0,0 +1,46 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class RackupTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def rackup + require "rack" + app, options = Rack::Builder.parse_file("#{app_path}/config.ru") + app + end + + def setup + build_app + boot_rails + end + + test "rails app is present" do + assert File.exist?(app_path("config")) + end + + test "config.ru can be racked up" do + Dir.chdir app_path do + @app = rackup + assert_welcome get("/") + end + end + + test "Rails.application is available after config.ru has been racked up" do + rackup + assert Rails.application.is_a?(Rails::Application) + end + + # Passenger still uses AC::Dispatcher, so we need to + # keep it working for now + test "deprecated ActionController::Dispatcher still works" do + rackup + assert ActionController::Dispatcher.new.is_a?(Rails::Application) + end + + test "the config object is available on the application object" do + rackup + assert_equal 'UTC', Rails.application.config.time_zone + end + end +end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 50cb9e3acc..b93e349a46 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -14,7 +14,6 @@ module ApplicationTests def app @app ||= begin require "#{app_path}/config/environment" - Rails.application end end @@ -26,7 +25,7 @@ module ApplicationTests test "simple controller" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -43,9 +42,36 @@ module ApplicationTests assert_equal 'foo', last_response.body end + test "simple controller with helper" do + controller :foo, <<-RUBY + class FooController < ApplicationController + def index + render :inline => "<%= foo_or_bar? %>" + end + end + RUBY + + app_file 'app/helpers/bar_helper.rb', <<-RUBY + module BarHelper + def foo_or_bar? + "bar" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + match ':controller(/:action)' + end + RUBY + + get '/foo' + assert_equal 'bar', last_response.body + end + test "multiple controllers" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -75,7 +101,7 @@ module ApplicationTests test "nested controller" do controller 'foo', <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -84,7 +110,7 @@ module ApplicationTests controller 'admin/foo', <<-RUBY module Admin - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "admin::foo" end @@ -105,47 +131,9 @@ module ApplicationTests assert_equal 'admin::foo', last_response.body end - test "merges with plugin routes" do - controller 'foo', <<-RUBY - class FooController < ActionController::Base - def index - render :text => "foo" - end - end - RUBY - - app_file 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do |map| - match 'foo', :to => 'foo#index' - end - RUBY - - plugin 'bar', 'require File.dirname(__FILE__) + "/app/controllers/bar"' do |plugin| - plugin.write 'app/controllers/bar.rb', <<-RUBY - class BarController < ActionController::Base - def index - render :text => "bar" - end - end - RUBY - - plugin.write 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do |map| - match 'bar', :to => 'bar#index' - end - RUBY - end - - get '/foo' - assert_equal 'foo', last_response.body - - get '/bar' - assert_equal 'bar', last_response.body - end - test "reloads routes when configuration is changed" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def bar render :text => "bar" end @@ -191,7 +179,7 @@ module ApplicationTests RUBY controller 'yazilar', <<-RUBY - class YazilarController < ActionController::Base + class YazilarController < ApplicationController def index render :text => 'yazilar#index' end diff --git a/railties/test/initializer/boot_test.rb b/railties/test/initializer/boot_test.rb deleted file mode 100644 index 5ee3c45b21..0000000000 --- a/railties/test/initializer/boot_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "isolation/abstract_unit" - -module BootTests - class GemBooting < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - # build_app - # boot_rails - end - - test "booting rails sets the load paths correctly" do - # This test is pending reworking the boot process - 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 deleted file mode 100644 index 311f19a28a..0000000000 --- a/railties/test/initializer/check_ruby_version_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "isolation/abstract_unit" - -module InitializerTests - class CheckRubyVersionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - end - - test "rails initializes with ruby 1.8.7 or later" do - if RUBY_VERSION < '1.8.7' - assert_rails_does_not_boot - else - assert_rails_boots - end - end - - def assert_rails_boots - assert_nothing_raised "It appears that rails does not boot" do - require "rails/all" - end - end - - def assert_rails_does_not_boot - $stderr = File.open("/dev/null", "w") - assert_raises(SystemExit) do - require "rails/all" - end - end - end -end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb deleted file mode 100644 index 2048dc57bb..0000000000 --- a/railties/test/initializer/path_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "isolation/abstract_unit" - -module InitializerTests - class PathTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf("#{app_path}/config/environments") - app_file "config/environments/development.rb", "" - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize do - ActionController::Base.session_store = nil - end - RUBY - use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] - require "#{app_path}/config/environment" - @paths = Rails.application.config.paths - end - - def root(*path) - app_path(*path).to_s - end - - def assert_path(paths, *dir) - assert_equal [root(*dir)], paths.paths - end - - def assert_in_load_path(*path) - assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - - def assert_not_in_load_path(*path) - assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - - test "booting up Rails yields a valid paths object" do - assert_path @paths.app.models, "app", "models" - assert_path @paths.app.metals, "app", "metal" - assert_path @paths.app.helpers, "app", "helpers" - assert_path @paths.app.views, "app", "views" - assert_path @paths.lib, "lib" - assert_path @paths.vendor, "vendor" - assert_path @paths.vendor.plugins, "vendor", "plugins" - assert_path @paths.tmp, "tmp" - assert_path @paths.tmp.cache, "tmp", "cache" - assert_path @paths.config, "config" - assert_path @paths.config.locales, "config", "locales", "en.yml" - assert_path @paths.config.environment, "config", "environments", "development.rb" - - assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first - assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, - Pathname.new(@paths.app.controllers.to_a[1]).expand_path - end - - test "booting up Rails yields a list of paths that are eager" do - assert @paths.app.eager_load? - assert @paths.app.controllers.eager_load? - assert @paths.app.helpers.eager_load? - end - - test "environments has a glob equal to the current environment" do - assert_equal "#{Rails.env}.rb", @paths.config.environment.glob - end - - test "load path includes each of the paths in config.paths as long as the directories exist" do - assert_in_load_path "app", "controllers" - assert_in_load_path "app", "models" - assert_in_load_path "app", "helpers" - assert_in_load_path "lib" - assert_in_load_path "vendor" - - assert_not_in_load_path "app", "metal" - assert_not_in_load_path "config" - assert_not_in_load_path "config", "locales" - assert_not_in_load_path "config", "environments" - assert_not_in_load_path "tmp" - assert_not_in_load_path "tmp", "cache" - end - - test "controller paths include builtin in development mode" do - Rails.env.replace "development" - assert Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - - test "controller paths does not have builtin_directories in test mode" do - Rails.env.replace "test" - assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - - test "controller paths does not have builtin_directories in production mode" do - Rails.env.replace "production" - assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - - end -end diff --git a/railties/test/railties/framework_extension_test.rb b/railties/test/railties/framework_extension_test.rb index 84bd6ed16b..48e513cf01 100644 --- a/railties/test/railties/framework_extension_test.rb +++ b/railties/test/railties/framework_extension_test.rb @@ -46,6 +46,20 @@ module RailtiesTest AppTemplate::Application.load_generators assert $ran_block end + + test "railtie initializer" do + $ran_block = false + + class MyTie < Rails::Railtie + initializer :something_nice do + $ran_block = true + end + end + + assert !$ran_block + require "#{app_path}/config/environment" + assert $ran_block + end end class ActiveRecordExtensionTest < Test::Unit::TestCase diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index 65d057383c..adcc5431f6 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -1,8 +1,10 @@ require "isolation/abstract_unit" +require "railties/shared_tests" module RailtiesTest - class PluginTest < Test::Unit::TestCase + class PluginSpecificTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include SharedTests def setup build_app @@ -12,15 +14,6 @@ module RailtiesTest end end - def boot_rails - super - require "#{app_path}/config/environment" - end - - def app - @app ||= Rails.application - end - test "it loads the plugin's init.rb file" do boot_rails assert_equal "loaded", BUKKITS @@ -31,52 +24,6 @@ module RailtiesTest assert_equal :debug, LEVEL end - test "the plugin puts its lib directory on the load path" do - boot_rails - require "bukkits" - assert_equal "Bukkits", Bukkits.name - end - - test "plugin init is ran before application initializers" do - plugin "foo", "$foo = true" do |plugin| - plugin.write "lib/foo.rb", "module Foo; end" - end - - app_file 'config/initializers/foo.rb', <<-RUBY - raise "no $foo" unless $foo - raise "no Foo" unless Foo - RUBY - - boot_rails - assert $foo - end - - test "plugin paths get added to the AS::Dependency list" do - boot_rails - assert_equal "Bukkits", Bukkits.name - end - - test "plugin constants do not get reloaded by default" do - boot_rails - assert_equal "Bukkits", Bukkits.name - ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_nothing_raised { Bukkits } - end - - test "plugin constants get reloaded if config.reload_plugins is set" do - add_to_config <<-RUBY - config.reload_plugins = true - RUBY - - boot_rails - - assert_equal "Bukkits", Bukkits.name - ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_raises(NameError) { Bukkits } - end - test "plugin should work without init.rb" do @plugin.delete("init.rb") @@ -86,210 +33,6 @@ module RailtiesTest assert_nothing_raised { Bukkits } end - test "the plugin puts its models directory on the load path" do - @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end" - - boot_rails - - assert_nothing_raised { MyBukkit } - end - - test "the plugin puts is controllers directory on the load path" do - @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end" - - boot_rails - - assert_nothing_raised { BukkitController } - end - - test "the plugin adds its view to the load path" do - @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY - class BukkitController < ActionController::Base - def index - end - end - RUBY - - @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" - - boot_rails - - require "action_controller" - require "rack/mock" - response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) - assert_equal "Hello bukkits\n", response[2].body - end - - test "the plugin adds helpers to the controller's views" do - @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY - class BukkitController < ActionController::Base - def index - end - end - RUBY - - @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY - module BukkitHelper - def bukkits - "bukkits" - end - end - RUBY - - @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>" - - boot_rails - - require "rack/mock" - response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) - assert_equal "Hello bukkits\n", response[2].body - end - - test "routes.rb are added to the router" do - @plugin.write "config/routes.rb", <<-RUBY - class Sprokkit - def self.call(env) - [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]] - end - end - - ActionController::Routing::Routes.draw do - match "/sprokkit", :to => Sprokkit - end - RUBY - - boot_rails - require "rack/mock" - response = Rails.application.call(Rack::MockRequest.env_for("/sprokkit")) - assert_equal "I am a Sprokkit", response[2].join - end - - test "tasks are loaded by default" do - $executed = false - @plugin.write "lib/tasks/foo.rake", <<-RUBY - task :foo do - $executed = true - end - RUBY - - boot_rails - require 'rake' - require 'rake/rdoctask' - require 'rake/testtask' - Rails.application.load_tasks - Rake::Task[:foo].invoke - assert $executed - end - - test "deprecated tasks are also loaded" do - $executed = false - @plugin.write "tasks/foo.rake", <<-RUBY - task :foo do - $executed = true - end - RUBY - - boot_rails - require 'rake' - require 'rake/rdoctask' - require 'rake/testtask' - Rails.application.load_tasks - Rake::Task[:foo].invoke - assert $executed - end - - test "i18n files are added with lower priority than application ones" do - add_to_config <<-RUBY - config.i18n.load_path << "#{app_path}/app/locales/en.yml" - RUBY - - app_file 'app/locales/en.yml', <<-YAML -en: - bar: "1" -YAML - - app_file 'config/locales/en.yml', <<-YAML -en: - foo: "2" - bar: "2" -YAML - - @plugin.write 'config/locales/en.yml', <<-YAML -en: - foo: "3" -YAML - - boot_rails - - assert_equal %W( - #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml - #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - #{app_path}/vendor/plugins/bukkits/config/locales/en.yml - #{app_path}/config/locales/en.yml - #{app_path}/app/locales/en.yml - ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } - - assert_equal "2", I18n.t(:foo) - assert_equal "1", I18n.t(:bar) - end - - test "plugin metals are added to the middleware stack" do - @plugin.write 'app/metal/foo_metal.rb', <<-RUBY - class FooMetal - def self.call(env) - [200, { "Content-Type" => "text/html"}, ["FooMetal"]] - end - end - RUBY - - boot_rails - require 'rack/test' - extend Rack::Test::Methods - - get "/" - assert_equal 200, last_response.status - assert_equal "FooMetal", last_response.body - end - - test "namespaced controllers with namespaced routes" do - @plugin.write "config/routes.rb", <<-RUBY - ActionController::Routing::Routes.draw do - namespace :admin do - match "index", :to => "admin/foo#index" - end - end - RUBY - - @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY - class Admin::FooController < ApplicationController - def index - render :text => "Rendered from namespace" - end - end - RUBY - - boot_rails - - require 'rack/test' - extend Rack::Test::Methods - - get "/admin/index" - assert_equal 200, last_response.status - assert_equal "Rendered from namespace", last_response.body - end - - test "plugin with initializers" do - $plugin_initializer = false - @plugin.write "config/initializers/foo.rb", <<-RUBY - $plugin_initializer = true - RUBY - - boot_rails - assert $plugin_initializer - end - test "plugin cannot declare an engine for it" do @plugin.write "lib/bukkits.rb", <<-RUBY class Bukkits @@ -313,22 +56,5 @@ YAML assert rescued, "Expected boot rails to fail" end - - test "use plugin middleware in application config" do - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - def initialize(app) - @app = app - end - - def call(env) - @app.call(env) - end - end - RUBY - - add_to_config "config.middleware.use \"Bukkits\"" - boot_rails - end end end diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb new file mode 100644 index 0000000000..ab6ab0a215 --- /dev/null +++ b/railties/test/railties/shared_tests.rb @@ -0,0 +1,318 @@ +module RailtiesTest + # Holds tests shared between plugin and engines + module SharedTests + def boot_rails + super + require "#{app_path}/config/environment" + end + + def app + @app ||= Rails.application + end + + def test_plugin_puts_its_lib_directory_on_load_path + boot_rails + require "bukkits" + assert_equal "Bukkits", Bukkits.name + end + + def test_plugin_init_is_ran_before_application_ones + plugin "foo", "$foo = true" do |plugin| + plugin.write "lib/foo.rb", "module Foo; end" + end + + app_file 'config/initializers/foo.rb', <<-RUBY + raise "no $foo" unless $foo + raise "no Foo" unless Foo + RUBY + + boot_rails + assert $foo + end + + def test_plugin_paths_get_added_to_as_dependency_list + boot_rails + assert_equal "Bukkits", Bukkits.name + end + + def test_plugins_constants_are_not_reloaded_by_default + boot_rails + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_nothing_raised { Bukkits } + end + + def test_plugin_constants_get_reloaded_if_config_reload_plugins + add_to_config <<-RUBY + config.reload_plugins = true + RUBY + + boot_rails + + assert_equal "Bukkits", Bukkits.name + ActiveSupport::Dependencies.clear + @plugin.delete("lib/bukkits.rb") + assert_raises(NameError) { Bukkits } + end + + def test_plugin_puts_its_models_directory_on_load_path + @plugin.write "app/models/my_bukkit.rb", "class MyBukkit ; end" + boot_rails + assert_nothing_raised { MyBukkit } + end + + def test_plugin_puts_its_controllers_directory_on_the_load_path + @plugin.write "app/controllers/bukkit_controller.rb", "class BukkitController ; end" + boot_rails + assert_nothing_raised { BukkitController } + end + + def test_plugin_adds_its_views_to_view_paths + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" + + boot_rails + + require "action_controller" + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + def test_plugin_adds_helpers_to_controller_views + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/helpers/bukkit_helper.rb", <<-RUBY + module BukkitHelper + def bukkits + "bukkits" + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello <%= bukkits %>" + + boot_rails + + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hello bukkits\n", response[2].body + end + + def test_routes_are_added_to_router + @plugin.write "config/routes.rb", <<-RUBY + class Sprokkit + def self.call(env) + [200, {'Content-Type' => 'text/html'}, ["I am a Sprokkit"]] + end + end + + ActionController::Routing::Routes.draw do + match "/sprokkit", :to => Sprokkit + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get "/sprokkit" + assert_equal "I am a Sprokkit", last_response.body + end + + def test_routes_in_plugins_have_lower_priority_than_application_ones + controller "foo", <<-RUBY + class FooController < ActionController::Base + def index + render :text => "foo" + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do |map| + match 'foo', :to => 'foo#index' + end + RUBY + + @plugin.write "app/controllers/bar_controller.rb", <<-RUBY + class BarController < ActionController::Base + def index + render :text => "bar" + end + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + ActionController::Routing::Routes.draw do |map| + match 'foo', :to => 'bar#index' + match 'bar', :to => 'bar#index' + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get '/foo' + assert_equal 'foo', last_response.body + + get '/bar' + assert_equal 'bar', last_response.body + end + + def test_rake_tasks_lib_tasks_are_loaded + $executed = false + @plugin.write "lib/tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + + def test_deprecated_tasks_are_also_loaded + $executed = false + @plugin.write "tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + + def test_i18n_files_have_lower_priority_than_application_ones + add_to_config <<-RUBY + config.i18n.load_path << "#{app_path}/app/locales/en.yml" + RUBY + + app_file 'app/locales/en.yml', <<-YAML +en: + bar: "1" +YAML + + app_file 'config/locales/en.yml', <<-YAML +en: + foo: "2" + bar: "2" +YAML + + @plugin.write 'config/locales/en.yml', <<-YAML +en: + foo: "3" +YAML + + boot_rails + + assert_equal %W( + #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml + #{app_path}/vendor/plugins/bukkits/config/locales/en.yml + #{app_path}/config/locales/en.yml + #{app_path}/app/locales/en.yml + ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } + + assert_equal "2", I18n.t(:foo) + assert_equal "1", I18n.t(:bar) + end + + def test_plugin_metals_added_to_middleware_stack + @plugin.write 'app/metal/foo_metal.rb', <<-RUBY + class FooMetal + def self.call(env) + [200, { "Content-Type" => "text/html"}, ["FooMetal"]] + end + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal 200, last_response.status + assert_equal "FooMetal", last_response.body + end + + def test_namespaced_controllers_with_namespaced_routes + @plugin.write "config/routes.rb", <<-RUBY + ActionController::Routing::Routes.draw do + namespace :admin do + match "index", :to => "admin/foo#index" + end + end + RUBY + + @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY + class Admin::FooController < ApplicationController + def index + render :text => "Rendered from namespace" + end + end + RUBY + + boot_rails + require 'rack/test' + extend Rack::Test::Methods + + get "/admin/index" + assert_equal 200, last_response.status + assert_equal "Rendered from namespace", last_response.body + end + + def test_plugin_initializers + $plugin_initializer = false + @plugin.write "config/initializers/foo.rb", <<-RUBY + $plugin_initializer = true + RUBY + + boot_rails + assert $plugin_initializer + end + + def test_plugin_midleware_referenced_in_configuration + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + def initialize(app) + @app = app + end + + def call(env) + @app.call(env) + end + end + RUBY + + add_to_config "config.middleware.use \"Bukkits\"" + boot_rails + end + end +end \ No newline at end of file -- cgit v1.2.3 From 7adb1ffc038e06a1c95030856859e183b181f94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 14:09:48 +0100 Subject: Remove old fixtures files. --- railties/test/fixtures/eager/zoo.rb | 3 -- railties/test/fixtures/eager/zoo/reptile_house.rb | 2 - .../test/fixtures/environment_with_constant.rb | 1 - .../a/generators/a_generator/a_generator.rb | 4 -- .../fixtures/plugins/alternate/a/lib/.gitignore | 0 .../acts/acts_as_chunky_bacon/lib/.gitignore | 0 .../test/fixtures/plugins/default/empty/.gitignore | 0 .../test/fixtures/plugins/default/gemlike/init.rb | 1 - .../plugins/default/gemlike/lib/gemlike.rb | 2 - .../fixtures/plugins/default/gemlike/rails/init.rb | 7 ---- .../plugins/default/plugin_with_no_lib_dir/init.rb | 0 .../test/fixtures/plugins/default/stubby/about.yml | 2 - .../test/fixtures/plugins/default/stubby/init.rb | 7 ---- .../plugins/default/stubby/lib/stubby_mixin.rb | 2 - .../engine/app/controllers/engine_controller.rb | 2 - .../engines/engine/app/metal/engine_metal.rb | 10 ----- .../engines/engine/app/models/engine_model.rb | 2 - .../plugins/engines/engine/config/locales/en.yml | 2 - .../plugins/engines/engine/config/routes.rb | 3 -- .../test/fixtures/plugins/engines/engine/init.rb | 3 -- railties/test/mocks/routes.rb | 6 --- .../vendor/gems/dummy-gem-a-0.4.0/.specification | 28 ------------- .../gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb | 1 - .../vendor/gems/dummy-gem-b-0.4.0/.specification | 28 ------------- .../gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb | 1 - .../vendor/gems/dummy-gem-b-0.6.0/.specification | 28 ------------- .../gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb | 1 - .../vendor/gems/dummy-gem-c-0.4.0/.specification | 28 ------------- .../gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb | 1 - .../vendor/gems/dummy-gem-c-0.6.0/.specification | 28 ------------- .../gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb | 1 - .../gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb | 1 - .../vendor/gems/dummy-gem-e-1.0.0/.specification | 28 ------------- .../gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb | 1 - .../vendor/gems/dummy-gem-f-1.0.0/.specification | 39 ----------------- .../gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb | 1 - .../vendor/gems/dummy-gem-g-1.0.0/.specification | 39 ----------------- .../gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb | 1 - .../vendor/gems/dummy-gem-h-1.0.0/.specification | 29 ------------- .../gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb | 1 - .../vendor/gems/dummy-gem-i-1.0.0/.specification | 41 ------------------ .../dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile | 0 .../gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb | 1 - .../vendor/gems/dummy-gem-j-1.0.0/.specification | 41 ------------------ .../gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb | 1 - .../vendor/gems/dummy-gem-k-1.0.0/.specification | 49 ---------------------- .../gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb | 1 - 47 files changed, 478 deletions(-) delete mode 100644 railties/test/fixtures/eager/zoo.rb delete mode 100644 railties/test/fixtures/eager/zoo/reptile_house.rb delete mode 100644 railties/test/fixtures/environment_with_constant.rb delete mode 100644 railties/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb delete mode 100644 railties/test/fixtures/plugins/alternate/a/lib/.gitignore delete mode 100644 railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.gitignore delete mode 100644 railties/test/fixtures/plugins/default/empty/.gitignore delete mode 100644 railties/test/fixtures/plugins/default/gemlike/init.rb delete mode 100644 railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb delete mode 100644 railties/test/fixtures/plugins/default/gemlike/rails/init.rb delete mode 100644 railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb delete mode 100644 railties/test/fixtures/plugins/default/stubby/about.yml delete mode 100644 railties/test/fixtures/plugins/default/stubby/init.rb delete mode 100644 railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb delete mode 100644 railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb delete mode 100644 railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb delete mode 100644 railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb delete mode 100644 railties/test/fixtures/plugins/engines/engine/config/locales/en.yml delete mode 100644 railties/test/fixtures/plugins/engines/engine/config/routes.rb delete mode 100644 railties/test/fixtures/plugins/engines/engine/init.rb delete mode 100644 railties/test/mocks/routes.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-a-0.4.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-b-0.4.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-b-0.6.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-c-0.4.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-c-0.6.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-e-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile delete mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb delete mode 100644 railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification delete mode 100644 railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb (limited to 'railties') diff --git a/railties/test/fixtures/eager/zoo.rb b/railties/test/fixtures/eager/zoo.rb deleted file mode 100644 index 8b10ef984b..0000000000 --- a/railties/test/fixtures/eager/zoo.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Zoo - include ReptileHouse -end \ No newline at end of file diff --git a/railties/test/fixtures/eager/zoo/reptile_house.rb b/railties/test/fixtures/eager/zoo/reptile_house.rb deleted file mode 100644 index 82bbafce79..0000000000 --- a/railties/test/fixtures/eager/zoo/reptile_house.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Zoo::ReptileHouse -end \ No newline at end of file diff --git a/railties/test/fixtures/environment_with_constant.rb b/railties/test/fixtures/environment_with_constant.rb deleted file mode 100644 index 23e1f7afd9..0000000000 --- a/railties/test/fixtures/environment_with_constant.rb +++ /dev/null @@ -1 +0,0 @@ -$initialize_test_set_from_env = 'success' diff --git a/railties/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb b/railties/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb deleted file mode 100644 index b33f2dad18..0000000000 --- a/railties/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb +++ /dev/null @@ -1,4 +0,0 @@ -class AGenerator < Rails::Generator::Base - def manifest - end -end diff --git a/railties/test/fixtures/plugins/alternate/a/lib/.gitignore b/railties/test/fixtures/plugins/alternate/a/lib/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.gitignore b/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/empty/.gitignore b/railties/test/fixtures/plugins/default/empty/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/gemlike/init.rb b/railties/test/fixtures/plugins/default/gemlike/init.rb deleted file mode 100644 index 6a771b5b68..0000000000 --- a/railties/test/fixtures/plugins/default/gemlike/init.rb +++ /dev/null @@ -1 +0,0 @@ -raise 'This init.rb should not be evaluated because rails/init.rb exists' diff --git a/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb b/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb deleted file mode 100644 index 2088103e45..0000000000 --- a/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Gemlike -end \ No newline at end of file diff --git a/railties/test/fixtures/plugins/default/gemlike/rails/init.rb b/railties/test/fixtures/plugins/default/gemlike/rails/init.rb deleted file mode 100644 index 171a293eb3..0000000000 --- a/railties/test/fixtures/plugins/default/gemlike/rails/init.rb +++ /dev/null @@ -1,7 +0,0 @@ -# I have access to my directory and the Rails config. -raise 'directory expected but undefined in init.rb' unless defined? directory -raise 'config expected but undefined in init.rb' unless defined? config - -# My lib/ dir must be in the load path. -require 'gemlike' -raise 'missing mixin from my lib/ dir' unless defined? Gemlike diff --git a/railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb b/railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/stubby/about.yml b/railties/test/fixtures/plugins/default/stubby/about.yml deleted file mode 100644 index d85a7cc0e3..0000000000 --- a/railties/test/fixtures/plugins/default/stubby/about.yml +++ /dev/null @@ -1,2 +0,0 @@ -author: Plugin Author -version: 1.0.0 \ No newline at end of file diff --git a/railties/test/fixtures/plugins/default/stubby/init.rb b/railties/test/fixtures/plugins/default/stubby/init.rb deleted file mode 100644 index 81beeb0d32..0000000000 --- a/railties/test/fixtures/plugins/default/stubby/init.rb +++ /dev/null @@ -1,7 +0,0 @@ -# I have access to my directory and the Rails config. -raise 'directory expected but undefined in init.rb' unless defined? directory -raise 'config expected but undefined in init.rb' unless defined? config - -# My lib/ dir must be in the load path. -require 'stubby_mixin' -raise 'missing mixin from my lib/ dir' unless defined? StubbyMixin diff --git a/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb b/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb deleted file mode 100644 index 2d569e5002..0000000000 --- a/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb +++ /dev/null @@ -1,2 +0,0 @@ -module StubbyMixin -end diff --git a/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb b/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb deleted file mode 100644 index 323ee1c4dc..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EngineController -end \ No newline at end of file diff --git a/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb b/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb deleted file mode 100644 index d67a127ca7..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb +++ /dev/null @@ -1,10 +0,0 @@ -class EngineMetal - def self.call(env) - if env["PATH_INFO"] =~ /^\/metal/ - [200, {"Content-Type" => "text/html"}, ["Engine metal"]] - else - [404, {"Content-Type" => "text/html"}, ["Not Found"]] - end - end -end - diff --git a/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb b/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb deleted file mode 100644 index e265712185..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EngineModel -end \ No newline at end of file diff --git a/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml b/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml deleted file mode 100644 index 641a7e035c..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml +++ /dev/null @@ -1,2 +0,0 @@ -en: - hello: "Hello from Engine" diff --git a/railties/test/fixtures/plugins/engines/engine/config/routes.rb b/railties/test/fixtures/plugins/engines/engine/config/routes.rb deleted file mode 100644 index da44595693..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/config/routes.rb +++ /dev/null @@ -1,3 +0,0 @@ -ActionController::Routing::Routes.draw do |map| - match '/engine', :to => "engine" -end diff --git a/railties/test/fixtures/plugins/engines/engine/init.rb b/railties/test/fixtures/plugins/engines/engine/init.rb deleted file mode 100644 index 64e9ae6c30..0000000000 --- a/railties/test/fixtures/plugins/engines/engine/init.rb +++ /dev/null @@ -1,3 +0,0 @@ -# My app/models dir must be in the load path. -require 'engine_model' -raise LoadError, 'missing model from my app/models dir' unless defined?(EngineModel) diff --git a/railties/test/mocks/routes.rb b/railties/test/mocks/routes.rb deleted file mode 100644 index ea12863683..0000000000 --- a/railties/test/mocks/routes.rb +++ /dev/null @@ -1,6 +0,0 @@ -module ActionController - module Routing - class Routes - end - end -end diff --git a/railties/test/vendor/gems/dummy-gem-a-0.4.0/.specification b/railties/test/vendor/gems/dummy-gem-a-0.4.0/.specification deleted file mode 100644 index 86dba2092c..0000000000 --- a/railties/test/vendor/gems/dummy-gem-a-0.4.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-a -version: !ruby/object:Gem::Version - version: 0.4.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-a.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem A diff --git a/railties/test/vendor/gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb b/railties/test/vendor/gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb deleted file mode 100644 index 0453b38ab8..0000000000 --- a/railties/test/vendor/gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_A_VERSION="0.4.0" diff --git a/railties/test/vendor/gems/dummy-gem-b-0.4.0/.specification b/railties/test/vendor/gems/dummy-gem-b-0.4.0/.specification deleted file mode 100644 index 5ea692d7a1..0000000000 --- a/railties/test/vendor/gems/dummy-gem-b-0.4.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-b -version: !ruby/object:Gem::Version - version: 0.4.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-b.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem B diff --git a/railties/test/vendor/gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb b/railties/test/vendor/gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb deleted file mode 100644 index 850b5dda83..0000000000 --- a/railties/test/vendor/gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_B_VERSION="0.4.0" diff --git a/railties/test/vendor/gems/dummy-gem-b-0.6.0/.specification b/railties/test/vendor/gems/dummy-gem-b-0.6.0/.specification deleted file mode 100644 index ab4707124a..0000000000 --- a/railties/test/vendor/gems/dummy-gem-b-0.6.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-b -version: !ruby/object:Gem::Version - version: 0.6.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-b.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem B diff --git a/railties/test/vendor/gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb b/railties/test/vendor/gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb deleted file mode 100644 index 7d6d01cd48..0000000000 --- a/railties/test/vendor/gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_B_VERSION="0.6.0" diff --git a/railties/test/vendor/gems/dummy-gem-c-0.4.0/.specification b/railties/test/vendor/gems/dummy-gem-c-0.4.0/.specification deleted file mode 100644 index f90f60424c..0000000000 --- a/railties/test/vendor/gems/dummy-gem-c-0.4.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-c -version: !ruby/object:Gem::Version - version: 0.4.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-c.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem C diff --git a/railties/test/vendor/gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb b/railties/test/vendor/gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb deleted file mode 100644 index 1a416bef82..0000000000 --- a/railties/test/vendor/gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_C_VERSION="0.4.0" diff --git a/railties/test/vendor/gems/dummy-gem-c-0.6.0/.specification b/railties/test/vendor/gems/dummy-gem-c-0.6.0/.specification deleted file mode 100644 index e75c0aa66a..0000000000 --- a/railties/test/vendor/gems/dummy-gem-c-0.6.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-c -version: !ruby/object:Gem::Version - version: 0.6.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-c.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem C diff --git a/railties/test/vendor/gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb b/railties/test/vendor/gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb deleted file mode 100644 index 9ba2ca8bb5..0000000000 --- a/railties/test/vendor/gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_C_VERSION="0.6.0" diff --git a/railties/test/vendor/gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb b/railties/test/vendor/gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb deleted file mode 100644 index e5cb007e5f..0000000000 --- a/railties/test/vendor/gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_D_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-e-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-e-1.0.0/.specification deleted file mode 100644 index ce4443c8be..0000000000 --- a/railties/test/vendor/gems/dummy-gem-e-1.0.0/.specification +++ /dev/null @@ -1,28 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-e -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -files: -- lib -- lib/dummy-gem-e.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem E diff --git a/railties/test/vendor/gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb b/railties/test/vendor/gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb deleted file mode 100644 index 48bf91a701..0000000000 --- a/railties/test/vendor/gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_E_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification deleted file mode 100644 index 70a36b9a8c..0000000000 --- a/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification +++ /dev/null @@ -1,39 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-f -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -- !ruby/object:Gem::Dependency - name: absolutely-no-such-gem - type: :runtime - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -files: -- lib -- lib/dummy-gem-f.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem F diff --git a/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb b/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb deleted file mode 100644 index 0271c8c48a..0000000000 --- a/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_F_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification deleted file mode 100644 index 27e29912a6..0000000000 --- a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification +++ /dev/null @@ -1,39 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-g -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -- !ruby/object:Gem::Dependency - name: dummy-gem-f - type: :runtime - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -files: -- lib -- lib/dummy-gem-g.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb b/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb deleted file mode 100644 index 8fc056586c..0000000000 --- a/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_G_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification deleted file mode 100644 index b3f7930948..0000000000 --- a/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification +++ /dev/null @@ -1,29 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-h -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -files: -- lib -- lib/dummy-gem-h.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem H diff --git a/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb b/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb deleted file mode 100644 index 0f91234936..0000000000 --- a/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_H_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification deleted file mode 100644 index 50b4969da5..0000000000 --- a/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification +++ /dev/null @@ -1,41 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-i -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -- !ruby/object:Gem::Dependency - name: dummy-gem-i - type: :runtime - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -extensions: -- ext/dummy-gem-i/extconf.rb -files: -- lib -- lib/dummy-gem-i.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile b/railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb b/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb deleted file mode 100644 index 2f9a376c2c..0000000000 --- a/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_I_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification deleted file mode 100644 index 2c456546fc..0000000000 --- a/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification +++ /dev/null @@ -1,41 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-j -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -- !ruby/object:Gem::Dependency - name: dummy-gem-j - type: :runtime - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -extensions: -- ext/dummy-gem-j/extconf.rb -files: -- lib -- lib/dummy-gem-j.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb b/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb deleted file mode 100644 index 8ecd363ff8..0000000000 --- a/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_J_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification deleted file mode 100644 index 20edd0f856..0000000000 --- a/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification +++ /dev/null @@ -1,49 +0,0 @@ ---- !ruby/object:Gem::Specification -name: dummy-gem-k -version: !ruby/object:Gem::Version - version: 1.3.0 -platform: ruby -authors: -- "Nobody" -date: 2008-10-03 00:00:00 -04:00 -dependencies: -- !ruby/object:Gem::Dependency - name: dummy-gem-k - type: :runtime - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -- !ruby/object:Gem::Dependency - name: dummy-gem-h - type: :development - version_requirement: - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.0 - version: -files: -- lib -- lib/dummy-gem-k.rb -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: "0" - version: -requirements: [] -specification_version: 2 -summary: Dummy Gem I diff --git a/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb b/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb deleted file mode 100644 index 97fb1d69ce..0000000000 --- a/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb +++ /dev/null @@ -1 +0,0 @@ -DUMMY_GEM_K_VERSION="1.0.0" -- cgit v1.2.3 From f8bf1982dff9cf0f35fb7a121932c794ecdc1cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 14:58:00 +0100 Subject: Add tests for explicit engines. --- railties/lib/rails/application.rb | 5 +-- railties/lib/rails/application/configurable.rb | 19 ++++++++++ railties/lib/rails/railtie.rb | 10 +---- railties/test/isolation/abstract_unit.rb | 21 +++++++++++ railties/test/railties/engine_test.rb | 23 ++++++++++++ railties/test/railties/plugin_test.rb | 41 ++++++++++++++++++++- railties/test/railties/shared_tests.rb | 51 +++++--------------------- 7 files changed, 115 insertions(+), 55 deletions(-) create mode 100644 railties/lib/rails/application/configurable.rb create mode 100644 railties/test/railties/engine_test.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index eba49e1520..12aa279959 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -6,6 +6,7 @@ require 'rails/engine' module Rails class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' + autoload :Configurable, 'rails/application/configurable' autoload :Configuration, 'rails/application/configuration' autoload :Finisher, 'rails/application/finisher' autoload :Railties, 'rails/application/railties' @@ -41,10 +42,6 @@ module Rails require environment if environment end - def config - @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) - end - def routes ::ActionController::Routing::Routes end diff --git a/railties/lib/rails/application/configurable.rb b/railties/lib/rails/application/configurable.rb new file mode 100644 index 0000000000..f598e33965 --- /dev/null +++ b/railties/lib/rails/application/configurable.rb @@ -0,0 +1,19 @@ +module Rails + class Application + module Configurable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def inherited(base) + raise "You cannot inherit from a Rails::Application child" + end + end + + def config + @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd)) + end + end + end +end \ No newline at end of file diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 3cf358d75f..c038d0ac70 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -17,7 +17,7 @@ module Rails def inherited(base) unless abstract_railtie?(base) - base.send(:include, self::Configurable) if add_configurable?(base) + base.send(:include, self::Configurable) subclasses << base end end @@ -53,14 +53,6 @@ module Rails def abstract_railtie?(base) ABSTRACT_RAILTIES.include?(base.name) end - - # Just add configurable behavior if a Configurable module is defined - # and the class is a direct child from self. This is required to avoid - # application or plugins getting class configuration method from Railties - # and/or Engines. - def add_configurable?(base) - defined?(self::Configurable) && base.ancestors[1] == self - end end def rake_tasks diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index dc5fddb19d..940585836c 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -100,6 +100,8 @@ module TestHelpers end class Bukkit + attr_reader :path + def initialize(path) @path = path end @@ -118,10 +120,29 @@ module TestHelpers def plugin(name, string = "") dir = "#{app_path}/vendor/plugins/#{name}" FileUtils.mkdir_p(dir) + File.open("#{dir}/init.rb", 'w') do |f| f.puts "::#{name.upcase} = 'loaded'" f.puts string end + + Bukkit.new(dir).tap do |bukkit| + yield bukkit if block_given? + end + end + + def engine(name) + dir = "#{app_path}/random/#{name}" + FileUtils.mkdir_p(dir) + + app = File.readlines("#{app_path}/config/application.rb") + app.insert(2, "$:.unshift(\"#{dir}/lib\")") + app.insert(3, "require #{name.inspect}") + + File.open("#{app_path}/config/application.rb", 'r+') do |f| + f.puts app + end + Bukkit.new(dir).tap do |bukkit| yield bukkit if block_given? end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb new file mode 100644 index 0000000000..374f5ea93c --- /dev/null +++ b/railties/test/railties/engine_test.rb @@ -0,0 +1,23 @@ +require "isolation/abstract_unit" +require "railties/shared_tests" + +module RailtiesTest + class EngineTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include SharedTests + + def setup + build_app + + @plugin = engine "bukkits" do |plugin| + plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < ::Rails::Engine + end + end + RUBY + plugin.write "lib/another.rb", "class Another; end" + end + end + end +end diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index adcc5431f6..0adc31e3ed 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -2,7 +2,7 @@ require "isolation/abstract_unit" require "railties/shared_tests" module RailtiesTest - class PluginSpecificTest < Test::Unit::TestCase + class PluginTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation include SharedTests @@ -11,9 +11,16 @@ module RailtiesTest @plugin = plugin "bukkits", "::LEVEL = config.log_level" do |plugin| plugin.write "lib/bukkits.rb", "class Bukkits; end" + plugin.write "lib/another.rb", "class Another; end" end end + test "plugin can load the file with the same name in lib" do + boot_rails + require "bukkits" + assert_equal "Bukkits", Bukkits.name + end + test "it loads the plugin's init.rb file" do boot_rails assert_equal "loaded", BUKKITS @@ -24,6 +31,20 @@ module RailtiesTest assert_equal :debug, LEVEL end + test "plugin_init_is_ran_before_application_ones" do + plugin "foo", "$foo = true" do |plugin| + plugin.write "lib/foo.rb", "module Foo; end" + end + + app_file 'config/initializers/foo.rb', <<-RUBY + raise "no $foo" unless $foo + raise "no Foo" unless Foo + RUBY + + boot_rails + assert $foo + end + test "plugin should work without init.rb" do @plugin.delete("init.rb") @@ -56,5 +77,23 @@ module RailtiesTest assert rescued, "Expected boot rails to fail" end + + test "deprecated tasks are also loaded" do + $executed = false + @plugin.write "tasks/foo.rake", <<-RUBY + task :foo do + $executed = true + end + RUBY + + boot_rails + require 'rake' + require 'rake/rdoctask' + require 'rake/testtask' + Rails.application.load_tasks + Rake::Task[:foo].invoke + assert $executed + end + end end diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index ab6ab0a215..a20aa5e4f5 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -12,35 +12,21 @@ module RailtiesTest def test_plugin_puts_its_lib_directory_on_load_path boot_rails - require "bukkits" - assert_equal "Bukkits", Bukkits.name - end - - def test_plugin_init_is_ran_before_application_ones - plugin "foo", "$foo = true" do |plugin| - plugin.write "lib/foo.rb", "module Foo; end" - end - - app_file 'config/initializers/foo.rb', <<-RUBY - raise "no $foo" unless $foo - raise "no Foo" unless Foo - RUBY - - boot_rails - assert $foo + require "another" + assert_equal "Another", Another.name end def test_plugin_paths_get_added_to_as_dependency_list boot_rails - assert_equal "Bukkits", Bukkits.name + assert_equal "Another", Another.name end def test_plugins_constants_are_not_reloaded_by_default boot_rails - assert_equal "Bukkits", Bukkits.name + assert_equal "Another", Another.name ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_nothing_raised { Bukkits } + @plugin.delete("lib/another.rb") + assert_nothing_raised { Another } end def test_plugin_constants_get_reloaded_if_config_reload_plugins @@ -50,10 +36,10 @@ module RailtiesTest boot_rails - assert_equal "Bukkits", Bukkits.name + assert_equal "Another", Another.name ActiveSupport::Dependencies.clear - @plugin.delete("lib/bukkits.rb") - assert_raises(NameError) { Bukkits } + @plugin.delete("lib/another.rb") + assert_raises(NameError) { Another } end def test_plugin_puts_its_models_directory_on_load_path @@ -190,23 +176,6 @@ module RailtiesTest assert $executed end - def test_deprecated_tasks_are_also_loaded - $executed = false - @plugin.write "tasks/foo.rake", <<-RUBY - task :foo do - $executed = true - end - RUBY - - boot_rails - require 'rake' - require 'rake/rdoctask' - require 'rake/testtask' - Rails.application.load_tasks - Rake::Task[:foo].invoke - assert $executed - end - def test_i18n_files_have_lower_priority_than_application_ones add_to_config <<-RUBY config.i18n.load_path << "#{app_path}/app/locales/en.yml" @@ -235,7 +204,7 @@ YAML #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml - #{app_path}/vendor/plugins/bukkits/config/locales/en.yml + #{@plugin.path}/config/locales/en.yml #{app_path}/config/locales/en.yml #{app_path}/app/locales/en.yml ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } -- cgit v1.2.3 From 517b35a2bbe5ec381fecbbc54e67ba053f9da420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 15:00:16 +0100 Subject: Middleware stack actually runs routes and not the application. --- railties/lib/rails/tasks/middleware.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake index 62e10e2beb..251da67c96 100644 --- a/railties/lib/rails/tasks/middleware.rake +++ b/railties/lib/rails/tasks/middleware.rake @@ -3,5 +3,5 @@ task :middleware => :environment do Rails.configuration.middleware.active.each do |middleware| puts "use #{middleware.inspect}" end - puts "run #{Rails::Application.instance.class.name}" + puts "run #{Rails::Application.instance.class.name}.routes" end -- cgit v1.2.3 From edb8131535c74ac215bf36c0d58d2019ed091a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 15:27:40 +0100 Subject: Move Rails::Rack::Metal to Rails::Application::Metal and just add cascade if any metal was declared. --- railties/lib/rails/application.rb | 1 + railties/lib/rails/application/metal.rb | 46 ++++++++++++++++++++++++++++ railties/lib/rails/configuration.rb | 2 +- railties/lib/rails/engine.rb | 2 +- railties/lib/rails/rack.rb | 1 - railties/lib/rails/rack/metal.rb | 41 ------------------------- railties/test/application/middleware_test.rb | 7 ++++- 7 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 railties/lib/rails/application/metal.rb delete mode 100644 railties/lib/rails/rack/metal.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 12aa279959..9e41210119 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -9,6 +9,7 @@ module Rails autoload :Configurable, 'rails/application/configurable' autoload :Configuration, 'rails/application/configuration' autoload :Finisher, 'rails/application/finisher' + autoload :Metal, 'rails/application/metal' autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' diff --git a/railties/lib/rails/application/metal.rb b/railties/lib/rails/application/metal.rb new file mode 100644 index 0000000000..17786dd4ba --- /dev/null +++ b/railties/lib/rails/application/metal.rb @@ -0,0 +1,46 @@ +require 'action_dispatch' + +module Rails + class Application + class Metal + def self.paths + @paths ||= [] + end + + def self.metals + @metals ||= [] + end + + def initialize(list=nil) + metals = [] + list = Array(list || :all).map(&:to_sym) + + self.class.paths.each do |path| + matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/ + Dir.glob("#{path}/**/*.rb").sort.each do |metal_path| + metal = metal_path.sub(matcher, '\1').to_sym + next unless list.include?(metal) || list.include?(:all) + require_dependency metal + metals << metal + end + end + + metals = metals.sort_by do |m| + [list.index(m) || list.index(:all), m.to_s] + end + + @metals = metals.map { |m| m.to_s.camelize.constantize } + self.class.metals.concat(@metals) + end + + def new(app) + ActionDispatch::Cascade.new(@metals, app) + end + + def name + ActionDispatch::Cascade.name + end + alias_method :to_s, :name + end + end +end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 3c5c1c1e16..c5cb7b2d09 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -16,7 +16,7 @@ module Rails middleware.use('::ActionDispatch::Cookies') middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) - middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.metals) }) + middleware.use(lambda { Rails::Application::Metal.new(Rails.application.config.metals) }, :if => lambda { Rails::Application::Metal.metals.any? }) middleware.use('ActionDispatch::ParamsParser') middleware.use('::Rack::MethodOverride') middleware.use('::ActionDispatch::Head') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 8cb938c2b9..ebbee67cf4 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -99,7 +99,7 @@ module Rails end initializer :add_metals do - Rails::Rack::Metal.paths.unshift(*paths.app.metals.to_a) + Rails::Application::Metal.paths.unshift(*paths.app.metals.to_a) end initializer :load_application_initializers do diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index 4bc0c2c88b..1f20ceae44 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -3,7 +3,6 @@ module Rails autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" - autoload :Metal, "rails/rack/metal" autoload :Static, "rails/rack/static" end end diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb deleted file mode 100644 index 732936da32..0000000000 --- a/railties/lib/rails/rack/metal.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'action_dispatch' - -module Rails - module Rack - class Metal - def self.paths - @paths ||= [] - end - - def initialize(list=nil) - metals = [] - list = Array(list || :all).map(&:to_sym) - - self.class.paths.each do |path| - matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/ - Dir.glob("#{path}/**/*.rb").sort.each do |metal_path| - metal = metal_path.sub(matcher, '\1').to_sym - next unless list.include?(metal) || list.include?(:all) - require_dependency metal - metals << metal - end - end - - metals = metals.sort_by do |m| - [list.index(m) || list.index(:all), m.to_s] - end - - @metals = metals.map { |m| m.to_s.camelize.constantize } - end - - def new(app) - ActionDispatch::Cascade.new(@metals, app) - end - - def name - ActionDispatch::Cascade.name - end - alias_method :to_s, :name - end - end -end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 31696598ce..0b92cdba54 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -23,7 +23,6 @@ module ApplicationTests "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", - "ActionDispatch::Cascade", "ActionDispatch::ParamsParser", "Rack::MethodOverride", "ActionDispatch::Head", @@ -70,6 +69,12 @@ module ApplicationTests assert_equal "Rack::Config", middleware.first end + test "shows cascade if any metal exists" do + app_file "app/metal/foo.rb", "class Foo; end" + boot! + assert middleware.include?("ActionDispatch::Cascade") + end + private def boot! require "#{app_path}/config/environment" -- cgit v1.2.3 From 081dfca33a7254ae86baa8feeb31f2c293b5f165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 15:37:45 +0100 Subject: Clean up Rails::Rack::Logger. --- railties/lib/rails/rack/logger.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 91a613092f..de21fb4f10 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -9,27 +9,23 @@ module Rails end def call(env) - @env = env - before_dispatch - result = @app.call(@env) - after_dispatch - result + before_dispatch(env) + @app.call(env) + ensure + after_dispatch(env) end protected - def request - @request ||= ActionDispatch::Request.new(@env) - end - - def before_dispatch + def before_dispatch(env) + request = ActionDispatch::Request.new(env) path = request.request_uri.inspect rescue "unknown" info "\n\nStarted #{request.method.to_s.upcase} #{path} " << "for #{request.remote_ip} at #{Time.now.to_s(:db)}" end - def after_dispatch + def after_dispatch(env) Rails::Subscriber.flush_all! end -- cgit v1.2.3 From d7de1c76cad28f52fc62693d415a07abf6c86ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 15:46:17 +0100 Subject: Add a test which ensures application can overwrite plugins/engines view paths. --- railties/test/railties/shared_tests.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'railties') diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index a20aa5e4f5..fc4a19e7e7 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -72,6 +72,25 @@ module RailtiesTest assert_equal "Hello bukkits\n", response[2].body end + def test_plugin_adds_its_views_to_view_paths_with_lower_proriority + @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY + class BukkitController < ActionController::Base + def index + end + end + RUBY + + @plugin.write "app/views/bukkit/index.html.erb", "Hello bukkits" + app_file "app/views/bukkit/index.html.erb", "Hi bukkits" + + boot_rails + + require "action_controller" + require "rack/mock" + response = BukkitController.action(:index).call(Rack::MockRequest.env_for("/")) + assert_equal "Hi bukkits\n", response[2].body + end + def test_plugin_adds_helpers_to_controller_views @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY class BukkitController < ActionController::Base -- cgit v1.2.3 From 458b6a7fc905a23643fc0d26146e6bf230c9c472 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Wed, 27 Jan 2010 10:35:56 +1100 Subject: Fixing mailer generators to use the right email address --- railties/lib/generators/test_unit/mailer/templates/functional_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb index fcebb40135..e1aeb2db90 100644 --- a/railties/lib/generators/test_unit/mailer/templates/functional_test.rb +++ b/railties/lib/generators/test_unit/mailer/templates/functional_test.rb @@ -4,7 +4,7 @@ class <%= class_name %>Test < ActionMailer::TestCase <% for action in actions -%> test "<%= action %>" do @expected.subject = <%= action.to_s.humanize.inspect %> - @expected.to = "to@example.com" + @expected.to = "to@example.org" @expected.from = "from@example.com" @expected.body = read_fixture("<%= action %>") @expected.date = Time.now -- cgit v1.2.3 From 04ad12d681b13569628f95b44fb13953305e4ddf Mon Sep 17 00:00:00 2001 From: "Stephen St. Martin" Date: Mon, 25 Jan 2010 17:39:00 -0500 Subject: initial jquery driver and compat, right now the only supported method is form_remote_tag --- .../templates/public/javascripts/jquery-1.4.min.js | 151 +++++++++++++++++++++ .../templates/public/javascripts/jquery.compat.js | 34 +++++ .../templates/public/javascripts/jquery.driver.js | 48 +++++++ 3 files changed, 233 insertions(+) create mode 100644 railties/lib/generators/rails/app/templates/public/javascripts/jquery-1.4.min.js create mode 100644 railties/lib/generators/rails/app/templates/public/javascripts/jquery.compat.js create mode 100644 railties/lib/generators/rails/app/templates/public/javascripts/jquery.driver.js (limited to 'railties') diff --git a/railties/lib/generators/rails/app/templates/public/javascripts/jquery-1.4.min.js b/railties/lib/generators/rails/app/templates/public/javascripts/jquery-1.4.min.js new file mode 100644 index 0000000000..5c70e4c5f3 --- /dev/null +++ b/railties/lib/generators/rails/app/templates/public/javascripts/jquery-1.4.min.js @@ -0,0 +1,151 @@ +/*! + * jQuery JavaScript Library v1.4 + * http://jquery.com/ + * + * Copyright 2010, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://docs.jquery.com/License + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2010, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Wed Jan 13 15:23:05 2010 -0500 + */ +(function(A,w){function oa(){if(!c.isReady){try{s.documentElement.doScroll("left")}catch(a){setTimeout(oa,1);return}c.ready()}}function La(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function $(a,b,d,f,e,i){var j=a.length;if(typeof b==="object"){for(var o in b)$(a,o,b[o],f,e,d);return a}if(d!==w){f=!i&&f&&c.isFunction(d);for(o=0;o-1){i=j.data;i.beforeFilter&&i.beforeFilter[a.type]&&!i.beforeFilter[a.type](a)||f.push(j.selector)}else delete t[p]}i=c(a.target).closest(f,a.currentTarget); +n=0;for(l=i.length;n)[^>]*$|^#([\w-]+)$/,Pa=/^.[^:#\[\.,]*$/,Qa=/\S/, +Ra=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,Sa=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,P=navigator.userAgent,xa=false,Q=[],M,ca=Object.prototype.toString,da=Object.prototype.hasOwnProperty,ea=Array.prototype.push,R=Array.prototype.slice,V=Array.prototype.indexOf;c.fn=c.prototype={init:function(a,b){var d,f;if(!a)return this;if(a.nodeType){this.context=this[0]=a;this.length=1;return this}if(typeof a==="string")if((d=Oa.exec(a))&&(d[1]||!b))if(d[1]){f=b?b.ownerDocument||b:s;if(a=Sa.exec(a))if(c.isPlainObject(b)){a=[s.createElement(a[1])]; +c.fn.attr.call(a,b,true)}else a=[f.createElement(a[1])];else{a=ua([d[1]],[f]);a=(a.cacheable?a.fragment.cloneNode(true):a.fragment).childNodes}}else{if(b=s.getElementById(d[2])){if(b.id!==d[2])return U.find(a);this.length=1;this[0]=b}this.context=s;this.selector=a;return this}else if(!b&&/^\w+$/.test(a)){this.selector=a;this.context=s;a=s.getElementsByTagName(a)}else return!b||b.jquery?(b||U).find(a):c(b).find(a);else if(c.isFunction(a))return U.ready(a);if(a.selector!==w){this.selector=a.selector; +this.context=a.context}return c.isArray(a)?this.setArray(a):c.makeArray(a,this)},selector:"",jquery:"1.4",length:0,size:function(){return this.length},toArray:function(){return R.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this.slice(a)[0]:this[a]},pushStack:function(a,b,d){a=c(a||null);a.prevObject=this;a.context=this.context;if(b==="find")a.selector=this.selector+(this.selector?" ":"")+d;else if(b)a.selector=this.selector+"."+b+"("+d+")";return a},setArray:function(a){this.length= +0;ea.apply(this,a);return this},each:function(a,b){return c.each(this,a,b)},ready:function(a){c.bindReady();if(c.isReady)a.call(s,c);else Q&&Q.push(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(R.apply(this,arguments),"slice",R.call(arguments).join(","))},map:function(a){return this.pushStack(c.map(this,function(b,d){return a.call(b,d,b)}))},end:function(){return this.prevObject|| +c(null)},push:ea,sort:[].sort,splice:[].splice};c.fn.init.prototype=c.fn;c.extend=c.fn.extend=function(){var a=arguments[0]||{},b=1,d=arguments.length,f=false,e,i,j,o;if(typeof a==="boolean"){f=a;a=arguments[1]||{};b=2}if(typeof a!=="object"&&!c.isFunction(a))a={};if(d===b){a=this;--b}for(;b
a";var e=d.getElementsByTagName("*"),i=d.getElementsByTagName("a")[0];if(!(!e||!e.length||!i)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length, +htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(i.getAttribute("style")),hrefNormalized:i.getAttribute("href")==="/a",opacity:/^0.55$/.test(i.style.opacity),cssFloat:!!i.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:s.createElement("select").appendChild(s.createElement("option")).selected,scriptEval:false,noCloneEvent:true,boxModel:null};b.type="text/javascript";try{b.appendChild(s.createTextNode("window."+f+"=1;"))}catch(j){}a.insertBefore(b, +a.firstChild);if(A[f]){c.support.scriptEval=true;delete A[f]}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function o(){c.support.noCloneEvent=false;d.detachEvent("onclick",o)});d.cloneNode(true).fireEvent("onclick")}c(function(){var o=s.createElement("div");o.style.width=o.style.paddingLeft="1px";s.body.appendChild(o);c.boxModel=c.support.boxModel=o.offsetWidth===2;s.body.removeChild(o).style.display="none"});a=function(o){var p=s.createElement("div");o="on"+o;var n=o in +p;if(!n){p.setAttribute(o,"return;");n=typeof p[o]==="function"}return n};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=e=i=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var H="jQuery"+K(),Ta=0,ya={},Ua={};c.extend({cache:{},expando:H,noData:{embed:true,object:true,applet:true},data:function(a, +b,d){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?ya:a;var f=a[H],e=c.cache;if(!b&&!f)return null;f||(f=++Ta);if(typeof b==="object"){a[H]=f;e=e[f]=c.extend(true,{},b)}else e=e[f]?e[f]:typeof d==="undefined"?Ua:(e[f]={});if(d!==w){a[H]=f;e[b]=d}return typeof b==="string"?e[b]:e}},removeData:function(a,b){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?ya:a;var d=a[H],f=c.cache,e=f[d];if(b){if(e){delete e[b];c.isEmptyObject(e)&&c.removeData(a)}}else{try{delete a[H]}catch(i){a.removeAttribute&& +a.removeAttribute(H)}delete f[d]}}}});c.fn.extend({data:function(a,b){if(typeof a==="undefined"&&this.length)return c.data(this[0]);else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===w){var f=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(f===w&&this.length)f=c.data(this[0],a);return f===w&&d[1]?this.data(d[0]):f}else return this.trigger("setData"+d[1]+"!",[d[0],b]).each(function(){c.data(this,a,b)})},removeData:function(a){return this.each(function(){c.removeData(this, +a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var f=c.data(a,b);if(!d)return f||[];if(!f||c.isArray(d))f=c.data(a,b,c.makeArray(d));else f.push(d);return f}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),f=d.shift();if(f==="inprogress")f=d.shift();if(f){b==="fx"&&d.unshift("inprogress");f.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===w)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this, +a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var za=/[\n\t]/g,fa=/\s+/,Va=/\r/g,Wa=/href|src|style/,Xa=/(button|input)/i,Ya=/(button|input|object|select|textarea)/i,Za=/^(a|area)$/i,Aa=/radio|checkbox/;c.fn.extend({attr:function(a, +b){return $(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(p){var n=c(this);n.addClass(a.call(this,p,n.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(fa),d=0,f=this.length;d-1)return true;return false},val:function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var i=b?d:0;for(d=b?d+1:e.length;i=0;else if(c.nodeName(this,"select")){var z=c.makeArray(t);c("option",this).each(function(){this.selected=c.inArray(c(this).val(),z)>=0});if(!z.length)this.selectedIndex= +-1}else this.value=t}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,f){if(!a||a.nodeType===3||a.nodeType===8)return w;if(f&&b in c.attrFn)return c(a)[b](d);f=a.nodeType!==1||!c.isXMLDoc(a);var e=d!==w;b=f&&c.props[b]||b;if(a.nodeType===1){var i=Wa.test(b);if(b in a&&f&&!i){if(e){if(b==="type"&&Xa.test(a.nodeName)&&a.parentNode)throw"type property can't be changed";a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue; +if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:Ya.test(a.nodeName)||Za.test(a.nodeName)&&a.href?0:w;return a[b]}if(!c.support.style&&f&&b==="style"){if(e)a.style.cssText=""+d;return a.style.cssText}e&&a.setAttribute(b,""+d);a=!c.support.hrefNormalized&&f&&i?a.getAttribute(b,2):a.getAttribute(b);return a===null?w:a}return c.style(a,b,d)}});var $a=function(a){return a.replace(/[^\w\s\.\|`]/g,function(b){return"\\"+b})};c.event={add:function(a,b,d,f){if(!(a.nodeType=== +3||a.nodeType===8)){if(a.setInterval&&a!==A&&!a.frameElement)a=A;if(!d.guid)d.guid=c.guid++;if(f!==w){d=c.proxy(d);d.data=f}var e=c.data(a,"events")||c.data(a,"events",{}),i=c.data(a,"handle"),j;if(!i){j=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(j.elem,arguments):w};i=c.data(a,"handle",j)}if(i){i.elem=a;b=b.split(/\s+/);for(var o,p=0;o=b[p++];){var n=o.split(".");o=n.shift();d.type=n.slice(0).sort().join(".");var t=e[o],z=this.special[o]||{};if(!t){t=e[o]={}; +if(!z.setup||z.setup.call(a,f,n,d)===false)if(a.addEventListener)a.addEventListener(o,i,false);else a.attachEvent&&a.attachEvent("on"+o,i)}if(z.add)if((n=z.add.call(a,d,f,n,t))&&c.isFunction(n)){n.guid=n.guid||d.guid;d=n}t[d.guid]=d;this.global[o]=true}a=null}}},global:{},remove:function(a,b,d){if(!(a.nodeType===3||a.nodeType===8)){var f=c.data(a,"events"),e,i,j;if(f){if(b===w||typeof b==="string"&&b.charAt(0)===".")for(i in f)this.remove(a,i+(b||""));else{if(b.type){d=b.handler;b=b.type}b=b.split(/\s+/); +for(var o=0;i=b[o++];){var p=i.split(".");i=p.shift();var n=!p.length,t=c.map(p.slice(0).sort(),$a);t=new RegExp("(^|\\.)"+t.join("\\.(?:.*\\.)?")+"(\\.|$)");var z=this.special[i]||{};if(f[i]){if(d){j=f[i][d.guid];delete f[i][d.guid]}else for(var B in f[i])if(n||t.test(f[i][B].type))delete f[i][B];z.remove&&z.remove.call(a,p,j);for(e in f[i])break;if(!e){if(!z.teardown||z.teardown.call(a,p)===false)if(a.removeEventListener)a.removeEventListener(i,c.data(a,"handle"),false);else a.detachEvent&&a.detachEvent("on"+ +i,c.data(a,"handle"));e=null;delete f[i]}}}}for(e in f)break;if(!e){if(B=c.data(a,"handle"))B.elem=null;c.removeData(a,"events");c.removeData(a,"handle")}}}},trigger:function(a,b,d,f){var e=a.type||a;if(!f){a=typeof a==="object"?a[H]?a:c.extend(c.Event(e),a):c.Event(e);if(e.indexOf("!")>=0){a.type=e=e.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();this.global[e]&&c.each(c.cache,function(){this.events&&this.events[e]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType=== +8)return w;a.result=w;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;var i=c.data(d,"handle");i&&i.apply(d,b);var j,o;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()])){j=d[e];o=d["on"+e]}}catch(p){}i=c.nodeName(d,"a")&&e==="click";if(!f&&j&&!a.isDefaultPrevented()&&!i){this.triggered=true;try{d[e]()}catch(n){}}else if(o&&d["on"+e].apply(d,b)===false)a.result=false;this.triggered=false;if(!a.isPropagationStopped())(d=d.parentNode||d.ownerDocument)&&c.event.trigger(a,b,d,true)}, +handle:function(a){var b,d;a=arguments[0]=c.event.fix(a||A.event);a.currentTarget=this;d=a.type.split(".");a.type=d.shift();b=!d.length&&!a.exclusive;var f=new RegExp("(^|\\.)"+d.slice(0).sort().join("\\.(?:.*\\.)?")+"(\\.|$)");d=(c.data(this,"events")||{})[a.type];for(var e in d){var i=d[e];if(b||f.test(i.type)){a.handler=i;a.data=i.data;i=i.apply(this,arguments);if(i!==w){a.result=i;if(i===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}return a.result}, +props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(a){if(a[H])return a;var b=a;a=c.Event(b);for(var d=this.props.length,f;d;){f=this.props[--d];a[f]=b[f]}if(!a.target)a.target=a.srcElement|| +s;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=s.documentElement;d=s.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(!a.which&&(a.charCode||a.charCode===0?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&& +a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==w)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a,b){c.extend(a,b||{});a.guid+=b.selector+b.live;c.event.add(this,b.live,qa,b)},remove:function(a){if(a.length){var b=0,d=new RegExp("(^|\\.)"+a[0]+"(\\.|$)");c.each(c.data(this,"events").live||{},function(){d.test(this.type)&&b++});b<1&&c.event.remove(this,a[0],qa)}},special:{}},beforeunload:{setup:function(a, +b,d){if(this.setInterval)this.onbeforeunload=d;return false},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=a;this.type=a.type}else this.type=a;this.timeStamp=K();this[H]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=ba;var a=this.originalEvent;if(a){a.preventDefault&&a.preventDefault();a.returnValue=false}},stopPropagation:function(){this.isPropagationStopped= +ba;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=ba;this.stopPropagation()},isDefaultPrevented:aa,isPropagationStopped:aa,isImmediatePropagationStopped:aa};var Ba=function(a){for(var b=a.relatedTarget;b&&b!==this;)try{b=b.parentNode}catch(d){break}if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}},Ca=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover", +mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?Ca:Ba,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?Ca:Ba)}}});if(!c.support.submitBubbles)c.event.special.submit={setup:function(a,b,d){if(this.nodeName.toLowerCase()!=="form"){c.event.add(this,"click.specialSubmit."+d.guid,function(f){var e=f.target,i=e.type;if((i==="submit"||i==="image")&&c(e).closest("form").length)return pa("submit",this,arguments)});c.event.add(this,"keypress.specialSubmit."+ +d.guid,function(f){var e=f.target,i=e.type;if((i==="text"||i==="password")&&c(e).closest("form").length&&f.keyCode===13)return pa("submit",this,arguments)})}else return false},remove:function(a,b){c.event.remove(this,"click.specialSubmit"+(b?"."+b.guid:""));c.event.remove(this,"keypress.specialSubmit"+(b?"."+b.guid:""))}};if(!c.support.changeBubbles){var ga=/textarea|input|select/i;function Da(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex> +-1?c.map(a.options,function(f){return f.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d}function ha(a,b){var d=a.target,f,e;if(!(!ga.test(d.nodeName)||d.readOnly)){f=c.data(d,"_change_data");e=Da(d);if(e!==f){if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",e);if(d.type!=="select"&&(f!=null||e)){a.type="change";return c.event.trigger(a,b,this)}}}}c.event.special.change={filters:{focusout:ha,click:function(a){var b=a.target,d=b.type;if(d=== +"radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return ha.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return ha.call(this,a)},beforeactivate:function(a){a=a.target;a.nodeName.toLowerCase()==="input"&&a.type==="radio"&&c.data(a,"_change_data",Da(a))}},setup:function(a,b,d){for(var f in W)c.event.add(this,f+".specialChange."+d.guid,W[f]);return ga.test(this.nodeName)}, +remove:function(a,b){for(var d in W)c.event.remove(this,d+".specialChange"+(b?"."+b.guid:""),W[d]);return ga.test(this.nodeName)}};var W=c.event.special.change.filters}s.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(f){f=c.event.fix(f);f.type=b;return c.event.handle.call(this,f)}c.event.special[b]={setup:function(){this.addEventListener(a,d,true)},teardown:function(){this.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d, +f,e){if(typeof d==="object"){for(var i in d)this[b](i,f,d[i],e);return this}if(c.isFunction(f)){thisObject=e;e=f;f=w}var j=b==="one"?c.proxy(e,function(o){c(this).unbind(o,j);return e.apply(this,arguments)}):e;return d==="unload"&&b!=="one"?this.one(d,f,e,thisObject):this.each(function(){c.event.add(this,d,j,f)})}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&!a.preventDefault){for(var d in a)this.unbind(d,a[d]);return this}return this.each(function(){c.event.remove(this,a,b)})},trigger:function(a, +b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){a=c.Event(a);a.preventDefault();a.stopPropagation();c.event.trigger(a,b,this[0]);return a.result}},toggle:function(a){for(var b=arguments,d=1;d0){y=u;break}}u=u[g]}m[r]=y}}}var f=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, +e=0,i=Object.prototype.toString,j=false,o=true;[0,0].sort(function(){o=false;return 0});var p=function(g,h,k,m){k=k||[];var r=h=h||s;if(h.nodeType!==1&&h.nodeType!==9)return[];if(!g||typeof g!=="string")return k;for(var q=[],v,u,y,S,I=true,N=x(h),J=g;(f.exec(""),v=f.exec(J))!==null;){J=v[3];q.push(v[1]);if(v[2]){S=v[3];break}}if(q.length>1&&t.exec(g))if(q.length===2&&n.relative[q[0]])u=ia(q[0]+q[1],h);else for(u=n.relative[q[0]]?[h]:p(q.shift(),h);q.length;){g=q.shift();if(n.relative[g])g+=q.shift(); +u=ia(g,u)}else{if(!m&&q.length>1&&h.nodeType===9&&!N&&n.match.ID.test(q[0])&&!n.match.ID.test(q[q.length-1])){v=p.find(q.shift(),h,N);h=v.expr?p.filter(v.expr,v.set)[0]:v.set[0]}if(h){v=m?{expr:q.pop(),set:B(m)}:p.find(q.pop(),q.length===1&&(q[0]==="~"||q[0]==="+")&&h.parentNode?h.parentNode:h,N);u=v.expr?p.filter(v.expr,v.set):v.set;if(q.length>0)y=B(u);else I=false;for(;q.length;){var E=q.pop();v=E;if(n.relative[E])v=q.pop();else E="";if(v==null)v=h;n.relative[E](y,v,N)}}else y=[]}y||(y=u);if(!y)throw"Syntax error, unrecognized expression: "+ +(E||g);if(i.call(y)==="[object Array]")if(I)if(h&&h.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&F(h,y[g])))k.push(u[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&k.push(u[g]);else k.push.apply(k,y);else B(y,k);if(S){p(S,r,k,m);p.uniqueSort(k)}return k};p.uniqueSort=function(g){if(D){j=o;g.sort(D);if(j)for(var h=1;h":function(g,h){var k=typeof h==="string";if(k&&!/\W/.test(h)){h=h.toLowerCase();for(var m=0,r=g.length;m=0))k||m.push(v);else if(k)h[q]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()}, +CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,k,m,r,q){h=g[1].replace(/\\/g,"");if(!q&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,k,m,r){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=p(g[3],null,null,h);else{g=p.filter(g[3],h,k,true^r);k||m.push.apply(m, +g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,k){return!!p(k[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)}, +text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}}, +setFilters:{first:function(g,h){return h===0},last:function(g,h,k,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,k){return hk[3]-0},nth:function(g,h,k){return k[3]-0===h},eq:function(g,h,k){return k[3]-0===h}},filter:{PSEUDO:function(g,h,k,m){var r=h[1],q=n.filters[r];if(q)return q(g,k,h,m);else if(r==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(r==="not"){h= +h[3];k=0;for(m=h.length;k=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var k=h[1];g=n.attrHandle[k]?n.attrHandle[k](g):g[k]!=null?g[k]:g.getAttribute(k);k=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m=== +"="?k===h:m==="*="?k.indexOf(h)>=0:m==="~="?(" "+k+" ").indexOf(h)>=0:!h?k&&g!==false:m==="!="?k!==h:m==="^="?k.indexOf(h)===0:m==="$="?k.substr(k.length-h.length)===h:m==="|="?k===h||k.substr(0,h.length+1)===h+"-":false},POS:function(g,h,k,m){var r=n.setFilters[h[2]];if(r)return r(g,k,h,m)}}},t=n.match.POS;for(var z in n.match){n.match[z]=new RegExp(n.match[z].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[z]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[z].source.replace(/\\(\d+)/g,function(g, +h){return"\\"+(h-0+1)}))}var B=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){B=function(g,h){h=h||[];if(i.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var k=0,m=g.length;k";var k=s.documentElement;k.insertBefore(g,k.firstChild);if(s.getElementById(h)){n.find.ID=function(m,r,q){if(typeof r.getElementById!=="undefined"&&!q)return(r=r.getElementById(m[1]))?r.id===m[1]||typeof r.getAttributeNode!=="undefined"&& +r.getAttributeNode("id").nodeValue===m[1]?[r]:w:[]};n.filter.ID=function(m,r){var q=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&q&&q.nodeValue===r}}k.removeChild(g);k=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,k){k=k.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;k[m];m++)k[m].nodeType===1&&h.push(k[m]);k=h}return k};g.innerHTML=""; +if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=p,h=s.createElement("div");h.innerHTML="

";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){p=function(m,r,q,v){r=r||s;if(!v&&r.nodeType===9&&!x(r))try{return B(r.querySelectorAll(m),q)}catch(u){}return g(m,r,q,v)};for(var k in g)p[k]=g[k];h=null}}(); +(function(){var g=s.createElement("div");g.innerHTML="
";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,k,m){if(typeof k.getElementsByClassName!=="undefined"&&!m)return k.getElementsByClassName(h[1])};g=null}}})();var F=s.compareDocumentPosition?function(g,h){return g.compareDocumentPosition(h)&16}:function(g, +h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ia=function(g,h){var k=[],m="",r;for(h=h.nodeType?[h]:h;r=n.match.PSEUDO.exec(g);){m+=r[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;r=0;for(var q=h.length;r=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f0)for(var i=d;i0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,i= +{},j;if(f&&a.length){e=0;for(var o=a.length;e-1:c(f).is(e)){d.push({selector:j,elem:f});delete i[j]}}f=f.parentNode}}return d}var p=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,t){for(;t&&t.ownerDocument&&t!==b;){if(p?p.index(t)>-1:c(t).is(a))return t;t=t.parentNode}return null})},index:function(a){if(!a||typeof a=== +"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(sa(a[0])||sa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode", +d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")? +a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);ab.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||cb.test(f))&&bb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||!c(a).is(d));){a.nodeType=== +1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ga=/ jQuery\d+="(?:\d+|null)"/g,Y=/^\s+/,db=/(<([\w:]+)[^>]*?)\/>/g,eb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,Ha=/<([\w:]+)/,fb=/"},G={option:[1,""], +legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]};G.optgroup=G.option;G.tbody=G.tfoot=G.colgroup=G.caption=G.thead;G.th=G.td;if(!c.support.htmlSerialize)G._default=[1,"div
","
"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=c(this); +return d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.getText(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this}, +wrapInner:function(a){return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&& +this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this.nextSibling)});else if(arguments.length){var a=this.pushStack(this, +"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ga,"").replace(Y,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ta(this,b);ta(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType=== +1?this[0].innerHTML.replace(Ga,""):null;else if(typeof a==="string"&&!/