diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-03-12 16:00:01 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-03-12 16:00:01 +0000 |
commit | e68bfaf1fe1a7890a67af6f444281185f507cf9e (patch) | |
tree | 5e73caccdcdd65d0ac97f9eb92195928f30925f2 /railties/lib | |
parent | ef6462c73003b28c8e060a06120abb9cd67b6d52 (diff) | |
parent | 16846553b8866eab2aa3b128a2a23a221a25f7e3 (diff) | |
download | rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.gz rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.bz2 rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.zip |
Merge remote branch 'mainstream/master'
Conflicts:
activerecord/lib/active_record/base.rb
railties/lib/rails/configuration.rb
railties/lib/rails/log_subscriber.rb
Diffstat (limited to 'railties/lib')
38 files changed, 383 insertions, 296 deletions
diff --git a/railties/lib/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/generators/erb/scaffold/templates/_form.html.erb index 9c19a09616..01ec58c615 100644 --- a/railties/lib/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%% form_for(@<%= singular_name %>) do |f| %> +<%%= form_for(@<%= singular_name %>) do |f| %> <%%= f.error_messages %> <% for attribute in attributes -%> diff --git a/railties/lib/generators/erb/scaffold/templates/layout.html.erb b/railties/lib/generators/erb/scaffold/templates/layout.html.erb index 420d17f33c..3f64be0c45 100644 --- a/railties/lib/generators/erb/scaffold/templates/layout.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/layout.html.erb @@ -9,6 +9,7 @@ <body> <p class="notice"><%%= notice %></p> +<p class="alert"><%%= alert %></p> <%%= yield %> diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index c439ed89f5..92e0d37436 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -7,6 +7,10 @@ module Rails::Generators # can change in Ruby 1.8.7 when we FileUtils.cd. RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__)) + RESERVED_NAMES = %w[generate console server dbconsole + application destroy benchmarker profiler + plugin runner test] + class AppGenerator < Base DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db ) @@ -134,8 +138,11 @@ module Rails::Generators end def create_prototype_files - return if options[:skip_prototype] - directory "public/javascripts" + unless options[:skip_prototype] + directory "public/javascripts" + else + empty_directory_with_gitkeep "public/javascripts" + end end def create_script_files @@ -209,9 +216,10 @@ module Rails::Generators end def valid_app_const? - case app_const - when /^\d/ + if app_const =~ /^\d/ raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers." + elsif RESERVED_NAMES.include?(app_name) + raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words." end end diff --git a/railties/lib/generators/rails/app/templates/Gemfile b/railties/lib/generators/rails/app/templates/Gemfile index f4bce8646d..0dd10f3f2d 100644 --- a/railties/lib/generators/rails/app/templates/Gemfile +++ b/railties/lib/generators/rails/app/templates/Gemfile @@ -1,4 +1,4 @@ -source 'http://gemcutter.org' +source 'http://rubygems.org' <%- if options.dev? -%> gem 'rails', :path => '<%= Rails::Generators::RAILS_DEV_PATH %>' @@ -15,15 +15,15 @@ gem 'rails', '<%= Rails::VERSION::STRING %>' gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %> <% end -%> -# Use mongrel as the web server -# gem 'mongrel' +# Use unicorn as the web server +# gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # Bundle the extra gems: # gem 'bj' -# gem 'hpricot', '0.6' +# gem 'nokogiri', '1.4.1' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' diff --git a/railties/lib/generators/rails/app/templates/config/application.rb b/railties/lib/generators/rails/app/templates/config/application.rb index 7c555c2542..dc20ffb2fa 100644 --- a/railties/lib/generators/rails/app/templates/config/application.rb +++ b/railties/lib/generators/rails/app/templates/config/application.rb @@ -35,7 +35,7 @@ module <%= app_const_base %> # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # Configure generators values. Many other options are available, be sure to check the documentation. diff --git a/railties/lib/generators/rails/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb index 29c9d506e5..3cb561d41f 100644 --- a/railties/lib/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/generators/rails/app/templates/config/boot.rb @@ -5,13 +5,4 @@ rescue LoadError require 'rubygems' require 'bundler' Bundler.setup - - # To use 2.x style vendor/rails and RubyGems - # - # vendor_rails = File.expand_path('../../vendor/rails', __FILE__) - # if File.exist?(vendor_rails) - # Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) } - # end - # - # require 'rubygems' end diff --git a/railties/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt b/railties/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt index 451dbe1d1c..be627fbbcc 100644 --- a/railties/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +++ b/railties/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -ActionController::Base.cookie_verifier_secret = '<%= app_secret %>' +Rails.application.config.cookie_secret = '<%= app_secret %>' diff --git a/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt index baff704d3e..9e32fb930e 100644 --- a/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,15 +1,10 @@ # Be sure to restart your server when you modify this file. -# Your secret key for verifying cookie session data integrity. -# If you change this key, all old sessions will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -ActionController::Base.session = { - :key => '_<%= app_name %>_session', - :secret => '<%= app_secret %>' +Rails.application.config.session_store :cookie_store, { + :key => '_<%= app_name %>_session', } # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rake db:sessions:create") -# ActionController::Base.session_store = :active_record_store +# Rails.application.config.session_store :active_record_store diff --git a/railties/lib/generators/rails/app/templates/public/index.html b/railties/lib/generators/rails/app/templates/public/index.html index ef916f9c5a..836da1b689 100644 --- a/railties/lib/generators/rails/app/templates/public/index.html +++ b/railties/lib/generators/rails/app/templates/public/index.html @@ -181,27 +181,27 @@ } </style> - <script type="text/javascript" src="javascripts/prototype.js"></script> - <script type="text/javascript" src="javascripts/effects.js"></script> <script type="text/javascript"> function about() { - if (Element.empty('about-content')) { - new Ajax.Updater('about-content', 'rails/info/properties', { - method: 'get', - onFailure: function() {Element.classNames('about-content').add('failure')}, - onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})} - }); - } else { - new Effect[Element.visible('about-content') ? - 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25}); - } + info = document.getElementById('about-content'); + if (window.XMLHttpRequest) + { xhr = new XMLHttpRequest(); } + else + { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } + xhr.open("GET","rails/info/properties",false); + xhr.send(""); + info.innerHTML = xhr.responseText; + info.style.display = 'block' + } + + function prepend() { + search = document.getElementById('search-text'); + text = search.value; + search.value = 'site:rubyonrails.org ' + text; } window.onload = function() { - $('search-text').value = ''; - $('search').onsubmit = function() { - $('search-text').value = 'site:rubyonrails.org ' + $F('search-text'); - } + document.getElementById('search-text').value = ''; } </script> </head> @@ -210,7 +210,7 @@ <div id="sidebar"> <ul id="sidebar-items"> <li> - <form id="search" action="http://www.google.com/search" method="get"> + <form id="search" action="http://www.google.com/search" method="get" onSubmit="prepend();"> <input type="hidden" name="hl" value="en" /> <input type="text" id="search-text" name="q" value="site:rubyonrails.org " /> <input type="submit" value="Search" /> the Rails site diff --git a/railties/lib/generators/rails/app/templates/script/rails b/railties/lib/generators/rails/app/templates/script/rails index b01d1ee183..199fe1a6d3 100644 --- a/railties/lib/generators/rails/app/templates/script/rails +++ b/railties/lib/generators/rails/app/templates/script/rails @@ -1,8 +1,5 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENV_PATH = File.expand_path('../../config/environment', __FILE__) -BOOT_PATH = File.expand_path('../../config/boot', __FILE__) -APP_PATH = File.expand_path('../../config/application', __FILE__) - -require BOOT_PATH +ENV_PATH = File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css index de6669ad9e..ea3dc9b8b5 100644 --- a/railties/lib/generators/rails/stylesheets/templates/scaffold.css +++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css @@ -24,6 +24,10 @@ div.field, div.actions { color: green; } +.alert { + color: red; +} + .fieldWithErrors { padding: 2px; background-color: red; 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 e1aeb2db90..a2b1f1ed05 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,6 @@ class <%= class_name %>Test < ActionMailer::TestCase @expected.to = "to@example.org" @expected.from = "from@example.com" @expected.body = read_fixture("<%= action %>") - @expected.date = Time.now assert_equal @expected, <%= class_name %>.<%= action %> end diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index b7a39fd5a7..3d3151bd8f 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -7,7 +7,7 @@ require 'active_support/core_ext/logger' require 'rails/application' require 'rails/version' require 'rails/deprecation' -require 'rails/subscriber' +require 'rails/log_subscriber' require 'rails/ruby_version_check' require 'active_support/railtie' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index f445ef4831..49388c5060 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -52,7 +52,10 @@ module Rails class << self private :new - alias :configure :class_eval + + def configure(&block) + class_eval(&block) + end def instance if self == Rails::Application @@ -85,17 +88,13 @@ module Rails end def routes - ::ActionController::Routing::Routes + @routes ||= ActionDispatch::Routing::RouteSet.new end def railties @railties ||= Railties.new(config) end - def metal_loader - @metal_laoder ||= MetalLoader.new - end - def routes_reloader @routes_reloader ||= RoutesReloader.new end diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index b20e53f2de..06243f2e5e 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -1,3 +1,5 @@ +require "active_support/notifications" + module Rails class Application module Bootstrap @@ -49,20 +51,6 @@ module Rails end end - # Initialize rails subscriber on top of notifications. - initializer :initialize_subscriber 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 - initializer :set_clear_dependencies_hook do unless config.cache_classes ActionDispatch::Callbacks.after do diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index d6ad045294..d3a0ecb243 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -5,7 +5,7 @@ module Rails class Configuration < ::Rails::Engine::Configuration include ::Rails::Configuration::Deprecated - attr_accessor :allow_concurrency, :cache_classes, :cache_store, :colorize_logging, + attr_accessor :allow_concurrency, :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, :log_level, :logger, :metals, :plugins, :preload_frameworks, :reload_engines, :reload_plugins, @@ -14,7 +14,6 @@ module Rails def initialize(*) super @allow_concurrency = false - @colorize_logging = true @filter_parameters = [] @dependency_loading = true @serve_static_assets = true @@ -22,6 +21,10 @@ module Rails @consider_all_requests_local = true end + def middleware + @@default_middleware_stack ||= default_middleware + end + def paths @paths ||= begin paths = super @@ -81,6 +84,16 @@ module Rails def log_level @log_level ||= Rails.env.production? ? :info : :debug end + + def colorize_logging + @colorize_logging + end + + def colorize_logging=(val) + @colorize_logging = val + Rails::LogSubscriber.colorize_logging = val + self.generators.colorize_logging = val + 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 index b722679ec2..cb38d5a5db 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -31,7 +31,6 @@ module Rails app 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) diff --git a/railties/lib/rails/application/metal_loader.rb b/railties/lib/rails/application/metal_loader.rb index c0f2e4f948..2a43fa7892 100644 --- a/railties/lib/rails/application/metal_loader.rb +++ b/railties/lib/rails/application/metal_loader.rb @@ -34,7 +34,7 @@ module Rails 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 + require_dependency metal.to_s metals << metal end end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index fde6211c5d..a5154f4bba 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -27,7 +27,7 @@ module Rails routes.clear! paths.each { |path| load(path) } - routes.finalize! + ActionController.base_hook { routes.finalize! } nil ensure diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 6972e25b29..d4558be00f 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -30,19 +30,17 @@ when 'g', 'generate' require 'rails/commands/generate' when 'c', 'console' require 'rails/commands/console' - require APP_PATH + require ENV_PATH Rails::Console.start(Rails::Application) when 's', 'server' require 'rails/commands/server' - # Initialize the server first, so environment options are set server = Rails::Server.new - require APP_PATH - + require ENV_PATH Dir.chdir(Rails::Application.root) server.start when 'db', 'dbconsole' require 'rails/commands/dbconsole' - require APP_PATH + require ENV_PATH Rails::DBConsole.start(Rails::Application) when 'application' @@ -57,7 +55,7 @@ when 'profiler' require ENV_PATH require 'rails/commands/performance/profiler' when 'plugin' - require APP_PATH + require ENV_PATH require 'rails/commands/plugin' when 'runner' require 'rails/commands/runner' diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 910b26f886..73ae9bcb16 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -4,92 +4,6 @@ require 'rails/rack' module Rails module Configuration - # Holds coonfiguration shared between Railtie, Engine and Application. - 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 }) - middleware.use('::Rack::Lock', :if => lambda { !Rails.application.config.allow_concurrency }) - middleware.use('::Rack::Runtime') - middleware.use('::Rails::Rack::Logger') - middleware.use('::ActionDispatch::ShowExceptions', lambda { Rails.application.config.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.application.metal_loader.build_middleware(Rails.application.config.metals) }, :if => lambda { Rails.application.metal_loader.metals.any? }) - 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 ||= Rails::Configuration::Generators.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 - - def to_prepare_blocks - @@to_prepare_blocks ||= [] - end - - def to_prepare(&blk) - to_prepare_blocks << blk if blk - 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] - end - super - end - - def config_key_regexp - bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|') - /^(#{bits})(?:=)?$/ - end - - def config_keys - (Railtie.railtie_names + Engine.engine_names).map { |n| n.to_s }.uniq - end - - def options - @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } - end - end - - # Generators configuration which uses method missing to wrap it in a nifty DSL. - # It also allows you to set generators fallbacks and aliases. class Generators #:nodoc: attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging @@ -123,7 +37,6 @@ module Rails end end - # Holds configs deprecated in 3.0. Will be removed on 3.1. module Deprecated def frameworks(*args) raise "config.frameworks in no longer supported. See the generated " \ diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index 7e8fd027e6..4a7701081b 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -17,8 +17,8 @@ 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) + app = Rails.application + session = ActionDispatch::Integration::Session.new(app) yield session if block_given? session end @@ -26,7 +26,8 @@ end # reloads the environment def reload!(print=true) puts "Reloading..." if print - ActionDispatch::Callbacks.new(lambda {}, false) + # This triggers the to_prepare callbacks + ActionDispatch::Callbacks.new(Proc.new {}, false).call({}) true end diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb index 039db667c4..212fc6125a 100644 --- a/railties/lib/rails/console/helpers.rb +++ b/railties/lib/rails/console/helpers.rb @@ -2,4 +2,6 @@ def helper @helper ||= ApplicationController.helpers end -@controller = ApplicationController.new +def controller + @controller ||= ApplicationController.new +end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 226d1aaa88..7ee0f31359 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,5 +1,6 @@ -require 'active_support/core_ext/module/delegation' require 'rails/railtie' +require 'active_support/core_ext/module/delegation' +require 'pathname' module Rails # Rails::Engine allows you to wrap a specific Rails application and share it accross @@ -98,8 +99,9 @@ module Rails def inherited(base) 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[\w\-]*/lib/rails|rack[\w\-]*/lib/rack] }) + # Remove the line number from backtraces making sure we don't leave anything behind + call_stack = caller.map { |p| p.split(':')[0..-2].join(':') } + File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-\.]*/lib/rails|rack[\w\-\.]*/lib/rack] }) end end @@ -122,10 +124,10 @@ module Rails end end - delegate :middleware, :paths, :root, :to => :config + delegate :middleware, :paths, :metal_loader, :root, :to => :config def load_tasks - super + super config.paths.lib.tasks.to_a.sort.each { |ext| load(ext) } end @@ -159,10 +161,11 @@ module Rails end end + # DEPRECATED: Remove in 3.1 initializer :add_routing_namespaces do |app| paths.app.controllers.to_a.each do |load_path| load_path = File.expand_path(load_path) - Dir["#{load_path}/*/*_controller.rb"].collect do |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 @@ -172,13 +175,13 @@ module Rails # I18n load paths are a special case since the ones added # later have higher priority. initializer :add_locales do - config.i18n.engines_load_path.concat(paths.config.locales.to_a) + config.i18n.railties_load_path.concat(paths.config.locales.to_a) end initializer :add_view_paths do views = paths.app.views.to_a - ActionController::Base.view_paths.unshift(*views) if defined?(ActionController) - ActionMailer::Base.view_paths.unshift(*views) if defined?(ActionMailer) + ActionController.base_hook { prepend_view_path(views) } if defined?(ActionController) + ActionMailer.base_hook { prepend_view_path(views) } if defined?(ActionMailer) end initializer :add_metals do |app| @@ -214,4 +217,4 @@ module Rails app.config.reload_engines end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 93b882f874..b8f1f1009c 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -7,6 +7,7 @@ module Rails attr_writer :eager_load_paths, :load_once_paths, :load_paths def initialize(root=nil) + super() @root = root end @@ -17,8 +18,9 @@ module Rails 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.app.mailers "app/mailers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true + paths.app.views "app/views", :eager_load => true paths.lib "lib", :load_path => true paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.lib.templates "lib/templates" @@ -26,6 +28,9 @@ module Rails paths.config.initializers "config/initializers", :glob => "**/*.rb" paths.config.locales "config/locales", :glob => "*.{rb,yml}" paths.config.routes "config/routes.rb" + paths.public "public" + paths.public.javascripts "public/javascripts" + paths.public.stylesheets "public/stylesheets" paths end end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index c01018aab2..3c902ce0d4 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -3,17 +3,23 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.inc require 'active_support' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/hash/deep_merge' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/string/inflections' require 'rails/generators/base' -require 'rails/generators/named_base' module Rails module Generators + autoload :Actions, 'rails/generators/actions' + autoload :ActiveModel, 'rails/generators/active_model' + autoload :Migration, 'rails/generators/migration' + autoload :NamedBase, 'rails/generators/named_base' + autoload :ResourceHelpers, 'rails/generators/resource_helpers' + autoload :TestCase, 'rails/generators/test_case' + DEFAULT_ALIASES = { :rails => { :actions => '-a', @@ -291,4 +297,4 @@ end # If the application was already defined, configure generators, # otherwise you have to configure it by hand. -Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application
\ No newline at end of file +Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index d41da773c6..7dec4d446a 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -89,12 +89,12 @@ module Rails # # ==== Example # - # source "http://gems.github.com/" + # add_source "http://gems.github.com/" def add_source(source, options={}) log :source, source in_root do - prepend_file "Gemfile", "source #{source.inspect}", :verbose => false + prepend_file "Gemfile", "source #{source.inspect}\n", :verbose => false end end @@ -280,6 +280,16 @@ module Rails end end + # Reads the given file at the source root and prints it in the console. + # + # === Example + # + # readme "README" + # + def readme(path) + say File.read(find_in_source_paths(path)) + end + protected # Define log for backwards compatibility. If just one argument is sent, diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/log_subscriber.rb index 9bf22f27a4..42697d2e32 100644 --- a/railties/lib/rails/subscriber.rb +++ b/railties/lib/rails/log_subscriber.rb @@ -2,15 +2,15 @@ require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/notifications' module Rails - # Rails::Subscriber is an object set to consume ActiveSupport::Notifications - # on initialization with the sole purpose of logging. The subscriber dispatches - # notifications to a registered object based on it's given namespace. + # Rails::LogSubscriber is an object set to consume ActiveSupport::Notifications + # on initialization with solely purpose of logging. The log subscriber dispatches + # notifications to a regirested object based on its given namespace. # - # An example would be an Active Record subscriber responsible for logging queries: + # An example would be ActiveRecord log subscriber responsible for logging queries: # # module ActiveRecord # class Railtie - # class Subscriber < Rails::Subscriber + # class LogSubscriber < Rails::LogSubscriber # def sql(event) # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}" # end @@ -18,21 +18,21 @@ module Rails # end # end # - # Which would be registed as: + # It's finally registed as: # - # Rails::Subscriber.add :active_record, ActiveRecord::Railtie::Subscriber.new + # Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new # - # So whenever an +active_record.sql+ notification arrives to Rails::Subscriber, + # So whenever a "active_record.sql" notification arrive to Rails::LogSubscriber, # it will properly dispatch the event (ActiveSupport::Notifications::Event) to # the sql method. # - # This avoids spanning several subscribers just for logging purposes - # (which slows down the main thread). It also provides a centralized + # This is useful because it avoids spanning several log subscribers just for logging + # purposes(which slows down the main thread). Besides of providing a centralized # facility on top of Rails.logger. - # - # Subscriber also has some helpers to deal with logging and automatically flushes - # all logs when the request finishes. - class Subscriber + # + # Log subscriber also has some helpers to deal with logging and automatically flushes + # all logs when the request finishes (via action_dispatch.callback notification). + class LogSubscriber mattr_accessor :colorize_logging self.colorize_logging = true @@ -50,30 +50,29 @@ module Rails CYAN = "\e[36m" WHITE = "\e[37m" - def self.add(namespace, subscriber) - subscribers[namespace.to_sym] = subscriber - end - - def self.subscribers - @subscribers ||= {} - end + def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications) + log_subscribers << log_subscriber - def self.dispatch(args) - namespace, name = args[0].split(".") - subscriber = subscribers[namespace.to_sym] + log_subscriber.public_methods(false).each do |event| + notifier.subscribe("#{namespace}.#{event}") do |*args| + next if log_subscriber.logger.nil? - if subscriber.respond_to?(name) && subscriber.logger - begin - subscriber.send(name, ActiveSupport::Notifications::Event.new(*args)) - rescue Exception => e - Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}" + begin + log_subscriber.send(event, ActiveSupport::Notifications::Event.new(*args)) + rescue Exception => e + Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}" + end end end end - # Flush all subscribers' logger. + def self.log_subscribers + @log_subscribers ||= [] + end + + # Flush all log_subscribers' logger. def self.flush_all! - loggers = subscribers.values.map(&:logger) + loggers = log_subscribers.map(&:logger) loggers.uniq! loggers.each { |l| l.flush if l.respond_to?(:flush) } end @@ -88,6 +87,7 @@ module Rails %w(info debug warn error fatal unknown).each do |level| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{level}(*args, &block) + return unless logger logger.#{level}(*args, &block) end METHOD @@ -97,6 +97,7 @@ module Rails # option is set to true, it also adds bold to the string. This is based # on Highline implementation and it automatically appends CLEAR to the end # of the returned String. + # def color(text, color, bold=false) return text unless colorize_logging color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol) diff --git a/railties/lib/rails/subscriber/test_helper.rb b/railties/lib/rails/log_subscriber/test_helper.rb index 39b4117372..02f5079462 100644 --- a/railties/lib/rails/subscriber/test_helper.rb +++ b/railties/lib/rails/log_subscriber/test_helper.rb @@ -1,13 +1,13 @@ -require 'rails/subscriber' +require 'rails/log_subscriber' module Rails - class Subscriber - # Provides some helpers to deal with testing subscribers by setting up + class LogSubscriber + # Provides some helpers to deal with testing log subscribers by setting up # notifications. Take for instance ActiveRecord subscriber tests: # - # class SyncSubscriberTest < ActiveSupport::TestCase - # include Rails::Subscriber::TestHelper - # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new) + # class SyncLogSubscriberTest < ActiveSupport::TestCase + # include Rails::LogSubscriber::TestHelper + # Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new) # # def test_basic_query_logging # Developer.all @@ -17,18 +17,18 @@ module Rails # assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last # end # - # class SyncSubscriberTest < ActiveSupport::TestCase - # include Rails::Subscriber::SyncTestHelper - # include SubscriberTest + # class SyncLogSubscriberTest < ActiveSupport::TestCase + # include Rails::LogSubscriber::SyncTestHelper + # include LogSubscriberTest # end # - # class AsyncSubscriberTest < ActiveSupport::TestCase - # include Rails::Subscriber::AsyncTestHelper - # include SubscriberTest + # class AsyncLogSubscriberTest < ActiveSupport::TestCase + # include Rails::LogSubscriber::AsyncTestHelper + # include LogSubscriberTest # end # end # - # All you need to do is to ensure that your subscriber is added to Rails::Subscriber, + # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber, # as in the second line of the code above. The test helpers is reponsible for setting # up the queue, subscriptions and turning colors in logs off. # @@ -42,8 +42,7 @@ module Rails @logger = MockLogger.new @notifier = ActiveSupport::Notifications::Notifier.new(queue) - Rails::Subscriber.colorize_logging = false - @notifier.subscribe { |*args| Rails::Subscriber.dispatch(args) } + Rails::LogSubscriber.colorize_logging = false set_logger(@logger) ActiveSupport::Notifications.notifier = @notifier @@ -80,7 +79,7 @@ module Rails @notifier.wait end - # Overwrite if you use another logger in your subscriber: + # Overwrite if you use another logger in your log subscriber: # # def logger # ActiveRecord::Base.logger = @logger diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 2a746e0fa6..0997be1b6f 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,4 +1,5 @@ require 'rails/engine' +require 'active_support/core_ext/array/conversions' module Rails # Rails::Plugin is nothing more than a Rails::Engine, but since it's loaded too late @@ -40,12 +41,14 @@ module Rails def load_tasks super - extra_tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"] + load_deprecated_tasks + end - 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) } + def load_deprecated_tasks + tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"].sort + if tasks.any? + ActiveSupport::Deprecation.warn "Rake tasks in #{tasks.to_sentence} are deprecated. Use lib/tasks instead" + tasks.each { |ext| load(ext) } end end @@ -59,9 +62,14 @@ module Rails end initializer :load_init_rb, :before => :load_application_initializers do |app| - file = Dir["#{root}/{rails/init,init}.rb"].first - config = app.config - eval(File.read(file), binding, file) if file && File.file?(file) + files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root } + if initrb = files.find { |path| File.file? path } + if initrb == files.first + ActiveSupport::Deprecation.warn "Use toplevel init.rb; rails/init.rb is deprecated: #{initrb}" + end + config = app.config + eval(File.read(initrb), binding, initrb) + end end initializer :sanity_check_railties_collision do diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index de21fb4f10..dd8b342f59 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -1,9 +1,9 @@ -require 'rails/subscriber' +require 'rails/log_subscriber' module Rails module Rack # Log the request started and flush all loggers after it. - class Logger < Rails::Subscriber + class Logger < Rails::LogSubscriber def initialize(app) @app = app end @@ -19,14 +19,14 @@ module Rails def before_dispatch(env) request = ActionDispatch::Request.new(env) - path = request.request_uri.inspect rescue "unknown" + path = request.fullpath.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(env) - Rails::Subscriber.flush_all! + Rails::LogSubscriber.flush_all! end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index b817f6b71e..96a07844e5 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,5 +1,6 @@ require 'rails/initializable' require 'rails/configuration' +require 'active_support/inflector' module Rails # Railtie is the core of the Rails Framework and provides several hooks to extend @@ -193,17 +194,16 @@ module Rails end def railtie_name(railtie_name = nil) - @railtie_name ||= name.demodulize.underscore @railtie_name = railtie_name if railtie_name - @railtie_name + @railtie_name ||= default_name end def railtie_names subclasses.map { |p| p.railtie_name } end - def subscriber(subscriber) - Rails::Subscriber.add(railtie_name, subscriber) + def log_subscriber(log_subscriber) + Rails::LogSubscriber.add(railtie_name, log_subscriber) end def rake_tasks(&blk) @@ -223,6 +223,10 @@ module Rails def abstract_railtie?(base) ABSTRACT_RAILTIES.include?(base.name) end + + def default_name + ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name)) + end end def rake_tasks diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index bfb43f7041..828ccec3d0 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -3,7 +3,123 @@ require 'rails/configuration' module Rails class Railtie class Configuration - include Rails::Configuration::Shared + attr_accessor :cookie_secret + + def initialize + @session_store = :cookie_store + @session_options = {} + 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 ||= Rails::Configuration::Generators.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 + + def to_prepare_blocks + @@to_prepare_blocks ||= [] + end + + def to_prepare(&blk) + to_prepare_blocks << blk if blk + end + + def respond_to?(name) + super || name.to_s =~ config_key_regexp + end + + def metal_loader + @metal_loader ||= Rails::Application::MetalLoader.new + end + + def session_store(*args) + if args.empty? + case @session_store + when :disabled + nil + when :active_record_store + ActiveRecord::SessionStore + when Symbol + ActionDispatch::Session.const_get(@session_store.to_s.camelize) + else + @session_store + end + else + @session_store = args.shift + @session_options = args.shift || {} + end + 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 session_options + return @session_options unless @session_store == :cookie_store + @session_options.merge(:secret => @cookie_secret) + end + + def config_key_regexp + bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|') + /^(#{bits})(?:=)?$/ + end + + def config_keys + (Railtie.railtie_names + Engine.engine_names).map { |n| n.to_s }.uniq + end + + def options + @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new } + end + + def default_middleware + require 'action_dispatch' + ActionDispatch::MiddlewareStack.new.tap do |middleware| + middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { serve_static_assets }) + middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency }) + middleware.use('::Rack::Runtime') + middleware.use('::Rails::Rack::Logger') + middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local }) + middleware.use("::ActionDispatch::RemoteIp", lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies }) + middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header }) + middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes }) + middleware.use('::ActionDispatch::Cookies') + middleware.use(lambda { session_store }, lambda { session_options }) + middleware.use('::ActionDispatch::Flash', :if => lambda { session_store }) + middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? }) + middleware.use('ActionDispatch::ParamsParser') + middleware.use('::Rack::MethodOverride') + middleware.use('::ActionDispatch::Head') + end + end end end end
\ No newline at end of file diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index f7cc6ff4be..abf9b33ae5 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -11,44 +11,54 @@ namespace :doc do rdoc.rdoc_files.include('lib/**/*.rb') } - 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.0.beta1' 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') - - %w(README CHANGELOG lib/action_mailer/base.rb).each do |file| - rdoc.rdoc_files.include("#{path}/actionmailer#{version}/#{file}") + desc 'Generate documentation for the Rails framework. Specify path with RAILS_PATH="/path/to/rails"' + path = ENV['RAILS_PATH'] + unless path && File.directory?(path) + task :rails do + if path + $stderr.puts "Skipping doc:rails, missing Rails directory at #{path}" + else + $stderr.puts "Skipping doc:rails, RAILS_PATH environment variable is not set" + end end + else + Rake::RDocTask.new("rails") { |rdoc| + version = "-#{Rails::VERSION::STRING}" 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') + + %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/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_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_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_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 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 - } + %w(README CHANGELOG MIT-LICENSE lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file| + rdoc.rdoc_files.include("#{path}/railties#{version}/#{file}") + end + } + end plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) } diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 65d3c48f2d..dbe2ac54ed 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -32,12 +32,18 @@ namespace :rails do namespace :update do def invoke_from_app_generator(method) - require 'rails/generators' - require 'generators/rails/app/app_generator' + app_generator.invoke(method) + end - generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, - :destination_root => Rails.root - generator.invoke(method) + def app_generator + @app_generator ||= begin + require 'rails/generators' + require 'generators/rails/app/app_generator' + gen = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, + :destination_root => Rails.root + gen.send(:valid_app_const?) + gen + end end desc "Update config/boot.rb from your current rails install" diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index ac0f440896..42e01d5e51 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,9 +1,9 @@ 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 + all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes routes = all_routes.collect do |route| - name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s + name = Rails.application.routes.named_routes.routes.index(route).to_s reqs = route.requirements.empty? ? "" : route.requirements.inspect {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index f9aa018cab..2ed5353755 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -1,6 +1,6 @@ # Make double-sure the RAILS_ENV is set to test, # so fixtures are loaded to the right database -exit("Abort testing: Your Rails environment is not running in test mode!") unless Rails.env.test? +abort("Abort testing: Your Rails environment is not running in test mode!") unless Rails.env.test? require 'test/unit' require 'active_support/core_ext/kernel/requires' @@ -24,6 +24,16 @@ if defined?(ActiveRecord) end end +class ActionController::TestCase + setup do + @router = Rails.application.routes + end +end + +class ActionDispatch::IntegrationTest + include Rails.application.routes.url_helpers +end + begin require_library_or_gem 'ruby-debug' Debugger.start diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index d0c7cb45db..1dd8fa0ec7 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -2,8 +2,9 @@ module Rails module VERSION #:nodoc: MAJOR = 3 MINOR = 0 - TINY = "0.beta1" + TINY = 0 + BUILD = "beta1" - STRING = [MAJOR, MINOR, TINY].join('.') + STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end end |