aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/Rakefile14
-rwxr-xr-xrailties/bin/rails37
-rw-r--r--railties/builtin/routes.rb4
-rw-r--r--railties/guides/source/3_0_release_notes.textile2
-rw-r--r--railties/guides/source/configuring.textile2
-rw-r--r--railties/guides/source/security.textile2
-rw-r--r--railties/lib/generators/erb/scaffold/templates/_form.html.erb2
-rw-r--r--railties/lib/generators/erb/scaffold/templates/layout.html.erb1
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb16
-rw-r--r--railties/lib/generators/rails/app/templates/Gemfile8
-rw-r--r--railties/lib/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/lib/generators/rails/app/templates/config/boot.rb9
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt2
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt11
-rw-r--r--railties/lib/generators/rails/app/templates/public/index.html34
-rw-r--r--railties/lib/generators/rails/app/templates/script/rails7
-rw-r--r--railties/lib/generators/rails/stylesheets/templates/scaffold.css4
-rw-r--r--railties/lib/generators/test_unit/mailer/templates/functional_test.rb1
-rw-r--r--railties/lib/rails.rb2
-rw-r--r--railties/lib/rails/application.rb11
-rw-r--r--railties/lib/rails/application/bootstrap.rb16
-rw-r--r--railties/lib/rails/application/configuration.rb17
-rw-r--r--railties/lib/rails/application/finisher.rb1
-rw-r--r--railties/lib/rails/application/metal_loader.rb2
-rw-r--r--railties/lib/rails/application/routes_reloader.rb2
-rw-r--r--railties/lib/rails/commands.rb10
-rw-r--r--railties/lib/rails/configuration.rb87
-rw-r--r--railties/lib/rails/console/app.rb7
-rw-r--r--railties/lib/rails/console/helpers.rb4
-rw-r--r--railties/lib/rails/engine.rb23
-rw-r--r--railties/lib/rails/engine/configuration.rb9
-rw-r--r--railties/lib/rails/generators.rb12
-rw-r--r--railties/lib/rails/generators/actions.rb14
-rw-r--r--railties/lib/rails/log_subscriber.rb (renamed from railties/lib/rails/subscriber.rb)63
-rw-r--r--railties/lib/rails/log_subscriber/test_helper.rb (renamed from railties/lib/rails/subscriber/test_helper.rb)31
-rw-r--r--railties/lib/rails/plugin.rb24
-rw-r--r--railties/lib/rails/rack/logger.rb8
-rw-r--r--railties/lib/rails/railtie.rb12
-rw-r--r--railties/lib/rails/railtie/configuration.rb118
-rw-r--r--railties/lib/rails/tasks/documentation.rake72
-rw-r--r--railties/lib/rails/tasks/framework.rake16
-rw-r--r--railties/lib/rails/tasks/routes.rake4
-rw-r--r--railties/lib/rails/test_help.rb12
-rw-r--r--railties/lib/rails/version.rb5
-rw-r--r--railties/railties.gemspec14
-rw-r--r--railties/test/application/configuration_test.rb57
-rw-r--r--railties/test/application/console_test.rb32
-rw-r--r--railties/test/application/initializers/frameworks_test.rb17
-rw-r--r--railties/test/application/initializers/initializers_test.rb26
-rw-r--r--railties/test/application/initializers/notifications_test.rb2
-rw-r--r--railties/test/application/metal_test.rb4
-rw-r--r--railties/test/application/middleware_stack_defaults_test.rb54
-rw-r--r--railties/test/application/middleware_test.rb2
-rw-r--r--railties/test/application/paths_test.rb11
-rw-r--r--railties/test/application/routing_test.rb3
-rw-r--r--railties/test/application/url_generation_test.rb43
-rw-r--r--railties/test/generators/actions_test.rb6
-rw-r--r--railties/test/generators/app_generator_test.rb6
-rw-r--r--railties/test/generators_test.rb15
-rw-r--r--railties/test/isolation/abstract_unit.rb2
-rw-r--r--railties/test/log_subscriber_test.rb123
-rw-r--r--railties/test/rails_info_controller_test.rb7
-rw-r--r--railties/test/railties/plugin_test.rb9
-rw-r--r--railties/test/railties/railtie_test.rb8
-rw-r--r--railties/test/railties/shared_tests.rb20
-rw-r--r--railties/test/subscriber_test.rb119
66 files changed, 833 insertions, 487 deletions
diff --git a/railties/Rakefile b/railties/Rakefile
index f32a794544..fe049d565f 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -8,20 +8,6 @@ require 'rake/gempackagetask'
require 'date'
require 'rbconfig'
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib"
-require 'rails/version'
-
-PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
-PKG_NAME = 'railties'
-PKG_VERSION = Rails::VERSION::STRING + PKG_BUILD
-PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
-PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
-
-RELEASE_NAME = "REL #{PKG_VERSION}"
-
-RUBY_FORGE_PROJECT = "rails"
-RUBY_FORGE_USER = "webster132"
-
task :default => :test
task :test => 'test:isolated'
diff --git a/railties/bin/rails b/railties/bin/rails
index 72c47b533f..173f122445 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -1,11 +1,30 @@
-if File.exists?(Dir.getwd + '/script/rails')
- exec(Dir.getwd + '/script/rails', *ARGV)
-else
- railties_path = File.expand_path('../../lib', __FILE__)
- $:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
+require 'rbconfig'
- require 'rails/ruby_version_check'
- Signal.trap("INT") { puts; exit }
+module Rails
+ module ScriptRailsLoader
+ RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
+ SCRIPT_RAILS = File.join('script', 'rails')
- require 'rails/commands/application'
-end \ No newline at end of file
+ def self.exec_script_rails!
+ cwd = Dir.pwd
+ exec RUBY, SCRIPT_RAILS, *ARGV if File.exists?(SCRIPT_RAILS)
+ Dir.chdir("..") do
+ # Recurse in a chdir block: if the search fails we want to be sure
+ # the application is generated in the original working directory.
+ exec_script_rails! unless cwd == Dir.pwd
+ end
+ rescue SystemCallError
+ # could not chdir, no problem just return
+ end
+ end
+end
+
+Rails::ScriptRailsLoader.exec_script_rails!
+
+railties_path = File.expand_path('../../lib', __FILE__)
+$:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
+
+require 'rails/ruby_version_check'
+Signal.trap("INT") { puts; exit }
+
+require 'rails/commands/application'
diff --git a/railties/builtin/routes.rb b/railties/builtin/routes.rb
index ef9d9e756d..bd58034d8f 100644
--- a/railties/builtin/routes.rb
+++ b/railties/builtin/routes.rb
@@ -1,3 +1,3 @@
-ActionController::Routing::Routes.draw do |map|
+Rails.application.routes.draw do |map|
match '/rails/info/properties' => "rails/info#properties"
-end \ No newline at end of file
+end
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 55fc610a53..9c6e7863f4 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -443,7 +443,7 @@ As well as the following deprecations:
* I18n error messages for ActiveRecord should be changed from :en.activerecord.errors.template to <tt>:en.errors.template</tt>.
* <tt>model.errors.on</tt> is deprecated in favour of <tt>model.errors[]</tt>
* validates_presence_of => validates... :presence => true
-* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::Subscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
+* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::LogSubscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
NOTE: While an implementation of State Machine has been in Active Record edge for some months now, it has been removed from the Rails 3.0 release.
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 0e6f981168..5418ad7dd4 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -159,7 +159,7 @@ WARNING: Threadsafe operation in incompatible with the normal workings of develo
* +config.action_controller.relative_url_root+ can be used to tell Rails that you are deploying to a subdirectory. The default is +ENV['RAILS_RELATIVE_URL_ROOT']+.
-* +config.action_controller.session_store+ sets the name of the store for session data. The default is +:cookie_store+; other valid options include +:active_record_store+, +:mem_cache_store+ or the name of your own custom class.
+* +config.action_dispatch.session_store+ sets the name of the store for session data. The default is +:cookie_store+; other valid options include +:active_record_store+, +:mem_cache_store+ or the name of your own custom class.
The caching code adds two additional settings:
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index ecf68b56f9..b62ff8cb38 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -92,7 +92,7 @@ Rails 2 introduced a new default session storage, CookieStore. CookieStore saves
That means the security of this storage depends on this secret (and on the digest algorithm, which defaults to SHA512, which has not been compromised, yet). So _(highlight)don't use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters_. Put the secret in your environment.rb:
<ruby>
-config.action_controller.session = {
+config.action_dispatch.session = {
:key => '_app_session',
:secret => '0x0dkfj3927dkc7djdh36rkckdfzsg...'
}
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
diff --git a/railties/railties.gemspec b/railties/railties.gemspec
index 65d2dde89f..b9d2739539 100644
--- a/railties/railties.gemspec
+++ b/railties/railties.gemspec
@@ -1,9 +1,11 @@
+version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
+
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'railties'
- s.version = '3.0.0.beta1'
- s.summary = 'Controls boot-up, rake tasks and generators for the Rails framework.'
- s.description = 'Controls boot-up, rake tasks and generators for the Rails framework.'
+ s.version = version
+ s.summary = 'Tools for creating, working with, and running Rails applications.'
+ s.description = 'Rails internals: application bootup, plugins, generators, and rake tasks.'
s.required_ruby_version = '>= 1.8.7'
s.author = 'David Heinemeier Hansson'
@@ -21,7 +23,7 @@ Gem::Specification.new do |s|
s.has_rdoc = false
s.add_dependency('rake', '>= 0.8.3')
- s.add_dependency('thor', '~> 0.13')
- s.add_dependency('activesupport', '= 3.0.0.beta1')
- s.add_dependency('actionpack', '= 3.0.0.beta1')
+ s.add_dependency('thor', '~> 0.13.4')
+ s.add_dependency('activesupport', version)
+ s.add_dependency('actionpack', version)
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 56f45582c8..54cd751f4e 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -171,5 +171,62 @@ module ApplicationTests
get "/"
assert $prepared
end
+
+ test "config.action_dispatch.x_sendfile_header defaults to X-Sendfile" do
+ require "rails"
+ require "action_controller/railtie"
+
+ class MyApp < Rails::Application
+ config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
+ config.session_store :cookie_store, :key => "_myapp_session"
+ end
+
+ MyApp.initialize!
+
+ class ::OmgController < ActionController::Base
+ def index
+ send_file __FILE__
+ end
+ end
+
+ MyApp.routes.draw do
+ match "/" => "omg#index"
+ end
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/"
+ assert_equal File.expand_path(__FILE__), last_response.headers["X-Sendfile"]
+ end
+
+ test "config.action_dispatch.x_sendfile_header is sent to Rack::Sendfile" do
+ require "rails"
+ require "action_controller/railtie"
+
+ class MyApp < Rails::Application
+ config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
+ config.session_store :cookie_store, :key => "_myapp_session"
+ config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File'
+ end
+
+ MyApp.initialize!
+
+ class ::OmgController < ActionController::Base
+ def index
+ send_file __FILE__
+ end
+ end
+
+ MyApp.routes.draw do
+ match "/" => "omg#index"
+ end
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/"
+ assert_equal File.expand_path(__FILE__), last_response.headers["X-Lighttpd-Send-File"]
+ end
end
end
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index 22ab60f4a0..8ff69f0208 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -6,7 +6,9 @@ class ConsoleTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ end
+ def load_environment
# Load steps taken from rails/commands/console.rb
require "#{rails_root}/config/environment"
require 'rails/console/app'
@@ -14,18 +16,21 @@ class ConsoleTest < Test::Unit::TestCase
end
def test_app_method_should_return_integration_session
+ load_environment
console_session = app
assert_not_nil console_session
assert_instance_of ActionController::Integration::Session, console_session
end
def test_new_session_should_return_integration_session
+ load_environment
session = new_session
assert_not_nil session
assert_instance_of ActionController::Integration::Session, session
end
def test_reload_should_fire_preparation_callbacks
+ load_environment
a = b = c = nil
# TODO: These should be defined on the initializer
@@ -34,16 +39,37 @@ class ConsoleTest < Test::Unit::TestCase
ActionDispatch::Callbacks.to_prepare { c = 3 }
# Hide Reloading... output
- silence_stream(STDOUT) do
- reload!
- end
+ silence_stream(STDOUT) { reload! }
assert_equal 1, a
assert_equal 2, b
assert_equal 3, c
end
+ def test_reload_should_reload_constants
+ app_file "app/models/user.rb", <<-MODEL
+ class User
+ attr_accessor :name
+ end
+ MODEL
+
+ load_environment
+ assert User.new.respond_to?(:name)
+ assert !User.new.respond_to?(:age)
+
+ app_file "app/models/user.rb", <<-MODEL
+ class User
+ attr_accessor :name, :age
+ end
+ MODEL
+
+ assert !User.new.respond_to?(:age)
+ silence_stream(STDOUT) { reload! }
+ assert User.new.respond_to?(:age)
+ end
+
def test_access_to_helpers
+ load_environment
assert_not_nil helper
assert_instance_of ActionView::Base, helper
assert_equal 'Once upon a time in a world...',
diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb
index 1e7b9c9997..8e57022e5b 100644
--- a/railties/test/application/initializers/frameworks_test.rb
+++ b/railties/test/application/initializers/frameworks_test.rb
@@ -32,6 +32,17 @@ module ApplicationTests
ActionMailer::Base.view_paths.include?(File.expand_path("app/views", app_path))
end
+ test "allows me to configure default url options for ActionMailer" do
+ app_file "config/environments/development.rb", <<-RUBY
+ Rails::Application.configure do
+ config.action_mailer.default_url_options = { :host => "test.rails" }
+ end
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert "test.rails", ActionMailer::Base.default_url_options[:host]
+ end
+
# AS
test "if there's no config.active_support.bare, all of ActiveSupport is required" do
use_frameworks []
@@ -54,7 +65,7 @@ module ApplicationTests
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
+ config.session_store :cookie_store, { :key => "blahblahblah" }
RUBY
require "#{app_path}/config/environment"
@@ -62,7 +73,7 @@ module ApplicationTests
end
test "database middleware initializes when session store is active record" do
- add_to_config "config.action_controller.session_store = :active_record_store"
+ add_to_config "config.session_store :active_record_store"
require "#{app_path}/config/environment"
@@ -80,7 +91,7 @@ module ApplicationTests
test "database middleware doesn't initialize when activerecord is not in frameworks" do
use_frameworks []
require "#{app_path}/config/environment"
- assert_nil defined?(ActiveRecord)
+ assert_nil defined?(ActiveRecord::Base)
end
end
end
diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb
index 0c3de7ce33..2e6a707175 100644
--- a/railties/test/application/initializers/initializers_test.rb
+++ b/railties/test/application/initializers/initializers_test.rb
@@ -51,5 +51,31 @@ module ApplicationTests
assert $activerecord_configurations
assert $activerecord_configurations['development']
end
+
+ test "after_initialize happens after to_prepare in development" do
+ $order = []
+ add_to_config <<-RUBY
+ config.cache_classes = false
+ config.after_initialize { $order << :after_initialize }
+ config.to_prepare { $order << :to_prepare }
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert [:to_prepare, :after_initialize], $order
+ end
+
+ test "after_initialize happens after to_prepare in production" do
+ $order = []
+ add_to_config <<-RUBY
+ config.cache_classes = true
+ config.after_initialize { $order << :after_initialize }
+ config.to_prepare { $order << :to_prepare }
+ RUBY
+
+ require "#{app_path}/config/application"
+ Rails.env.replace "production"
+ require "#{app_path}/config/environment"
+ assert [:to_prepare, :after_initialize], $order
+ end
end
end
diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb
index 061bb34c19..b99cf5bb4f 100644
--- a/railties/test/application/initializers/notifications_test.rb
+++ b/railties/test/application/initializers/notifications_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
ActiveSupport::Notifications.notifier.wait
end
- test "rails subscribers are added" do
+ test "rails log_subscribers are added" do
add_to_config <<-RUBY
config.colorize_logging = false
RUBY
diff --git a/railties/test/application/metal_test.rb b/railties/test/application/metal_test.rb
index 225bede117..1ec62282c8 100644
--- a/railties/test/application/metal_test.rb
+++ b/railties/test/application/metal_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
end
RUBY
- get "/"
+ get "/not/slash"
assert_equal 200, last_response.status
assert_equal "FooMetal", last_response.body
end
@@ -50,7 +50,7 @@ module ApplicationTests
end
RUBY
- get "/"
+ get "/not/slash"
assert_equal 200, last_response.status
assert_equal "Metal B", last_response.body
end
diff --git a/railties/test/application/middleware_stack_defaults_test.rb b/railties/test/application/middleware_stack_defaults_test.rb
new file mode 100644
index 0000000000..284f7e2e5b
--- /dev/null
+++ b/railties/test/application/middleware_stack_defaults_test.rb
@@ -0,0 +1,54 @@
+require 'isolation/abstract_unit'
+
+class MiddlewareStackDefaultsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ boot_rails
+ require "rails"
+ require "action_controller/railtie"
+
+ Object.const_set(:MyApplication, Class.new(Rails::Application))
+ MyApplication.class_eval do
+ config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
+ config.session_store :cookie_store, :key => "_myapp_session"
+ end
+ end
+
+ def remote_ip(env = {})
+ remote_ip = nil
+ env = Rack::MockRequest.env_for("/").merge(env).merge('action_dispatch.show_exceptions' => false)
+
+ endpoint = Proc.new do |e|
+ remote_ip = ActionDispatch::Request.new(e).remote_ip
+ [200, {}, ["Hello"]]
+ end
+
+ out = MyApplication.middleware.build(endpoint).call(env)
+ remote_ip
+ end
+
+ test "remote_ip works" do
+ assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "1.1.1.1")
+ end
+
+ test "checks IP spoofing by default" do
+ assert_raises(ActionDispatch::RemoteIp::IpSpoofAttackError) do
+ remote_ip("HTTP_X_FORWARDED_FOR" => "1.1.1.1", "HTTP_CLIENT_IP" => "1.1.1.2")
+ end
+ end
+
+ test "can disable IP spoofing check" do
+ MyApplication.config.action_dispatch.ip_spoofing_check = false
+
+ assert_nothing_raised(ActionDispatch::RemoteIp::IpSpoofAttackError) do
+ assert_equal "1.1.1.2", remote_ip("HTTP_X_FORWARDED_FOR" => "1.1.1.1", "HTTP_CLIENT_IP" => "1.1.1.2")
+ end
+ end
+
+ test "the user can set trusted proxies" do
+ MyApplication.config.action_dispatch.trusted_proxies = /^4\.2\.42\.42$/
+
+ assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1")
+ end
+end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index ce9cd510a3..9a359d20b1 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -19,6 +19,8 @@ module ApplicationTests
"Rack::Runtime",
"Rails::Rack::Logger",
"ActionDispatch::ShowExceptions",
+ "ActionDispatch::RemoteIp",
+ "Rack::Sendfile",
"ActionDispatch::Callbacks",
"ActionDispatch::Cookies",
"ActionDispatch::Session::CookieStore",
diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb
index ac0aa27c64..511b8b629a 100644
--- a/railties/test/application/paths_test.rb
+++ b/railties/test/application/paths_test.rb
@@ -11,8 +11,8 @@ module ApplicationTests
app_file "config/environments/development.rb", ""
add_to_config <<-RUBY
config.root = "#{app_path}"
- config.after_initialize do
- ActionController::Base.session_store = nil
+ config.after_initialize do |app|
+ app.config.session_store nil
end
RUBY
use_frameworks [:action_controller, :action_view, :action_mailer, :active_record]
@@ -56,9 +56,10 @@ module ApplicationTests
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?
+ eager_load = @paths.eager_load
+ assert eager_load.include?(root("app/controllers"))
+ assert eager_load.include?(root("app/helpers"))
+ assert eager_load.include?(root("app/models"))
end
test "environments has a glob equal to the current environment" do
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index b93e349a46..dcac1a87d9 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -120,7 +120,8 @@ module ApplicationTests
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
- match ':controller(/:action)'
+ match 'admin/foo', :to => 'admin/foo#index'
+ match 'foo', :to => 'foo#index'
end
RUBY
diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb
new file mode 100644
index 0000000000..04f5454e09
--- /dev/null
+++ b/railties/test/application/url_generation_test.rb
@@ -0,0 +1,43 @@
+require 'isolation/abstract_unit'
+
+module ApplicationTests
+ class UrlGenerationTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def app
+ Rails.application
+ end
+
+ test "it works" do
+ boot_rails
+ require "rails"
+ require "action_controller/railtie"
+
+ class MyApp < Rails::Application
+ config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
+ config.session_store :cookie_store, :key => "_myapp_session"
+ end
+
+ MyApp.initialize!
+
+ class ::ApplicationController < ActionController::Base
+ end
+
+ class ::OmgController < ::ApplicationController
+ def index
+ render :text => omg_path
+ end
+ end
+
+ MyApp.routes.draw do
+ match "/" => "omg#index", :as => :omg
+ end
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/"
+ assert_equal "/", last_response.body
+ end
+ end
+end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 5929db6318..3585e6e7c0 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -210,6 +210,12 @@ class ActionsTest < Rails::Generators::TestCase
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end
+ def test_readme
+ run_generator
+ Rails::Generators::AppGenerator.expects(:source_root).returns(destination_root)
+ assert_match(/Welcome to Rails/, action(:readme, "README"))
+ end
+
protected
def action(*args, &block)
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 0a746b200f..412034029e 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -50,6 +50,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
).each{ |path| assert_file path }
end
+ def test_name_collision_raises_an_error
+ content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] }
+ assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content
+ end
+
def test_invalid_database_option_raises_an_error
content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) }
assert_match /Invalid value for \-\-database option/, content
@@ -102,6 +107,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_prototype_and_test_unit_are_skipped_if_required
run_generator [destination_root, "--skip-prototype", "--skip-testunit"]
assert_no_file "public/javascripts/prototype.js"
+ assert_file "public/javascripts"
assert_no_file "test"
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 33cc27bd84..dd17f8f756 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -145,16 +145,17 @@ class GeneratorsTest < Rails::Generators::TestCase
end
def test_developer_options_are_overwriten_by_user_options
- Rails::Generators.options[:new_generator] = { :generate => false }
+ Rails::Generators.options[:with_options] = { :generate => false }
- klass = Class.new(Rails::Generators::Base) do
- def self.name() 'NewGenerator' end
- class_option :generate, :default => true
- end
+ self.class.class_eval <<-end_eval
+ class WithOptionsGenerator < Rails::Generators::Base
+ class_option :generate, :default => true
+ end
+ end_eval
- assert_equal false, klass.class_options[:generate].default
+ assert_equal false, WithOptionsGenerator.class_options[:generate].default
ensure
- Rails::Generators.subclasses.delete(klass)
+ Rails::Generators.subclasses.delete(WithOptionsGenerator)
end
def test_load_generators_from_railties
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 364dbd8e55..8f2f15b49e 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -100,7 +100,7 @@ module TestHelpers
end
end
- add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
+ add_to_config 'config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"'
end
class Bukkit
diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb
new file mode 100644
index 0000000000..49288cfaa8
--- /dev/null
+++ b/railties/test/log_subscriber_test.rb
@@ -0,0 +1,123 @@
+require 'abstract_unit'
+require 'rails/log_subscriber/test_helper'
+
+class MyLogSubscriber < Rails::LogSubscriber
+ attr_reader :event
+
+ def some_event(event)
+ @event = event
+ info event.name
+ end
+
+ def foo(event)
+ debug "debug"
+ info "info"
+ warn "warn"
+ end
+
+ def bar(event)
+ info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
+ end
+
+ def puke(event)
+ raise "puke"
+ end
+end
+
+class SyncLogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+
+ def setup
+ super
+ @log_subscriber = MyLogSubscriber.new
+ end
+
+ def teardown
+ super
+ Rails::LogSubscriber.log_subscribers.clear
+ end
+
+ def instrument(*args, &block)
+ ActiveSupport::Notifications.instrument(*args, &block)
+ end
+
+ def test_proxies_method_to_rails_logger
+ @log_subscriber.foo(nil)
+ assert_equal %w(debug), @logger.logged(:debug)
+ assert_equal %w(info), @logger.logged(:info)
+ assert_equal %w(warn), @logger.logged(:warn)
+ end
+
+ def test_set_color_for_messages
+ Rails::LogSubscriber.colorize_logging = true
+ @log_subscriber.bar(nil)
+ assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
+ end
+
+ def test_does_not_set_color_if_colorize_logging_is_set_to_false
+ @log_subscriber.bar(nil)
+ assert_equal "cool, isn't it?", @logger.logged(:info).last
+ end
+
+ def test_event_is_sent_to_the_registered_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_equal %w(my_log_subscriber.some_event), @logger.logged(:info)
+ end
+
+ def test_event_is_an_active_support_notifications_event
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_kind_of ActiveSupport::Notifications::Event, @log_subscriber.event
+ end
+
+ def test_does_not_send_the_event_if_it_doesnt_match_the_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.unknown_event"
+ wait
+ # If we get here, it means that NoMethodError was not raised.
+ end
+
+ def test_does_not_send_the_event_if_logger_is_nil
+ Rails.logger = nil
+ @log_subscriber.expects(:some_event).never
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ end
+
+ def test_does_not_fail_with_non_namespaced_events
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "whatever"
+ wait
+ end
+
+ def test_flushes_loggers
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_flushes_the_same_logger_just_once
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.add :another, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ wait
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_logging_does_not_die_on_failures
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.puke"
+ instrument "my_log_subscriber.some_event"
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_log_subscriber.some_event', @logger.logged(:info).last
+
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_log_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
+ end
+end \ No newline at end of file
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 4163fb2c6d..d904d7b461 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -14,10 +14,13 @@ class InfoControllerTest < ActionController::TestCase
tests Rails::InfoController
def setup
- ActionController::Routing::Routes.draw do |map|
- match ':controller/:action'
+ Rails.application.routes.draw do |map|
+ match '/rails/info/properties' => "rails/info#properties"
end
@controller.stubs(:consider_all_requests_local? => false, :local_request? => true)
+ @router = Rails.application.routes
+
+ Rails::InfoController.send(:include, @router.url_helpers)
end
test "info controller does not allow remote requests" do
diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb
index 09b859dcdd..0f5f29468c 100644
--- a/railties/test/railties/plugin_test.rb
+++ b/railties/test/railties/plugin_test.rb
@@ -94,6 +94,15 @@ module RailtiesTest
assert rescued, "Expected boot rails to fail"
end
+ test "loads deprecated rails/init.rb" do
+ @plugin.write "rails/init.rb", <<-RUBY
+ $loaded = true
+ RUBY
+
+ boot_rails
+ assert $loaded
+ end
+
test "deprecated tasks are also loaded" do
$executed = false
@plugin.write "tasks/foo.rake", <<-RUBY
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index b723e08281..9fefb285b4 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -51,12 +51,12 @@ module RailtiesTest
assert_equal "bar", Bar.config.foo.bar
end
- test "railtie can add subscribers" do
+ test "railtie can add log subscribers" do
begin
- class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end
- assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo]
+ class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end
+ assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[0]
ensure
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
end
end
diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb
index d51a0d153c..83d25be5db 100644
--- a/railties/test/railties/shared_tests.rb
+++ b/railties/test/railties/shared_tests.rb
@@ -133,7 +133,7 @@ module RailtiesTest
end
end
- ActionController::Routing::Routes.draw do
+ Rails.application.routes.draw do
match "/sprokkit", :to => Sprokkit
end
RUBY
@@ -170,7 +170,7 @@ module RailtiesTest
RUBY
@plugin.write "config/routes.rb", <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ Rails.application.routes.draw do |map|
match 'foo', :to => 'bar#index'
match 'bar', :to => 'bar#index'
end
@@ -254,22 +254,24 @@ YAML
require 'rack/test'
extend Rack::Test::Methods
- get "/"
+ get "/not/slash"
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
+ Rails.application.routes.draw do
namespace :admin do
- match "index", :to => "admin/foo#index"
+ namespace :foo do
+ match "bar", :to => "admin/foo/bar#index"
+ end
end
end
RUBY
- @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY
- class Admin::FooController < ApplicationController
+ @plugin.write "app/controllers/admin/foo/bar_controller.rb", <<-RUBY
+ class Admin::Foo::BarController < ApplicationController
def index
render :text => "Rendered from namespace"
end
@@ -280,7 +282,7 @@ YAML
require 'rack/test'
extend Rack::Test::Methods
- get "/admin/index"
+ get "/admin/foo/bar"
assert_equal 200, last_response.status
assert_equal "Rendered from namespace", last_response.body
end
@@ -312,4 +314,4 @@ YAML
boot_rails
end
end
-end \ No newline at end of file
+end
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
deleted file mode 100644
index f6c895093f..0000000000
--- a/railties/test/subscriber_test.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-require 'abstract_unit'
-require 'rails/subscriber/test_helper'
-
-class MySubscriber < Rails::Subscriber
- attr_reader :event
-
- def some_event(event)
- @event = event
- info event.name
- end
-
- def foo(event)
- debug "debug"
- info "info"
- warn "warn"
- end
-
- def bar(event)
- info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
- end
-
- def puke(event)
- raise "puke"
- end
-end
-
-class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
-
- def setup
- super
- @subscriber = MySubscriber.new
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def teardown
- super
- Rails::Subscriber.subscribers.clear
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def instrument(*args, &block)
- ActiveSupport::Notifications.instrument(*args, &block)
- end
-
- def test_proxies_method_to_rails_logger
- @subscriber.foo(nil)
- assert_equal %w(debug), @logger.logged(:debug)
- assert_equal %w(info), @logger.logged(:info)
- assert_equal %w(warn), @logger.logged(:warn)
- end
-
- def test_set_color_for_messages
- Rails::Subscriber.colorize_logging = true
- @subscriber.bar(nil)
- assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
- end
-
- def test_does_not_set_color_if_colorize_logging_is_set_to_false
- @subscriber.bar(nil)
- assert_equal "cool, isn't it?", @logger.logged(:info).last
- end
-
- def test_event_is_sent_to_the_registered_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_equal %w(my_subscriber.some_event), @logger.logged(:info)
- end
-
- def test_event_is_an_active_support_notifications_event
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_kind_of ActiveSupport::Notifications::Event, @subscriber.event
- end
-
- def test_does_not_send_the_event_if_it_doesnt_match_the_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.unknown_event"
- wait
- # If we get here, it means that NoMethodError was raised.
- end
-
- def test_does_not_send_the_event_if_logger_is_nil
- Rails.logger = nil
- @subscriber.expects(:some_event).never
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- end
-
- def test_flushes_loggers
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.flush_all!
- assert_equal 1, @logger.flush_count
- end
-
- def test_flushes_the_same_logger_just_once
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.add :another, @subscriber
- Rails::Subscriber.flush_all!
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_logging_does_not_die_on_failures
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.puke"
- instrument "my_subscriber.some_event"
- wait
-
- assert_equal 1, @logger.logged(:info).size
- assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
-
- assert_equal 1, @logger.logged(:error).size
- assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
- end
-end \ No newline at end of file