diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
commit | efd0bd3b7390ebb8526b981169025f2860f6a113 (patch) | |
tree | 1cb3bcd8f9534f64e8a764af1010ce65303b42b0 /railties | |
parent | f4571e3617ccd9cc9e5ee9f7431066bd80395e22 (diff) | |
parent | 8ff2fb6f3aa6140f5a8bd018d5919a8a1e707cda (diff) | |
download | rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.gz rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.bz2 rails-efd0bd3b7390ebb8526b981169025f2860f6a113.zip |
Merge remote branch 'mainstream/master'
Diffstat (limited to 'railties')
36 files changed, 234 insertions, 132 deletions
diff --git a/railties/builtin/rails_info/rails/info.rb b/railties/builtin/rails_info/rails/info.rb index 269fe488b0..90c9015fcf 100644 --- a/railties/builtin/rails_info/rails/info.rb +++ b/railties/builtin/rails_info/rails/info.rb @@ -114,7 +114,7 @@ module Rails end property 'Middleware' do - Rails.configuration.middleware.active.map { |middle| middle.inspect } + Rails.configuration.middleware.active.map(&:inspect) end # The Rails Git revision, if it's checked out into vendor/rails. diff --git a/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb b/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb index 2cdf4eae54..e8065d9505 100644 --- a/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb +++ b/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb @@ -1,4 +1,3 @@ class ApplicationController < ActionController::Base protect_from_forgery - filter_parameter_logging :password end diff --git a/railties/lib/generators/rails/app/templates/config.ru b/railties/lib/generators/rails/app/templates/config.ru index 2ab821e38d..fcfbc6b07a 100644 --- a/railties/lib/generators/rails/app/templates/config.ru +++ b/railties/lib/generators/rails/app/templates/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run <%= app_const %>.instance +run <%= app_const %> diff --git a/railties/lib/generators/rails/app/templates/config/application.rb b/railties/lib/generators/rails/app/templates/config/application.rb index 334820826f..78a355d2f4 100644 --- a/railties/lib/generators/rails/app/templates/config/application.rb +++ b/railties/lib/generators/rails/app/templates/config/application.rb @@ -30,5 +30,8 @@ module <%= app_const_base %> # g.template_engine :erb # g.test_framework :test_unit, :fixture => true # end + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters << :password end end diff --git a/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml b/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml index a9716ddb44..2cecb5c879 100644 --- a/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml +++ b/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml @@ -59,4 +59,4 @@ production: #account: my_account #app_user: my_app_user #application: my_application - #workstation: my_workstation
\ No newline at end of file + #workstation: my_workstation diff --git a/railties/lib/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/generators/rails/app/templates/config/environments/development.rb.tt index b10103b436..177ce44d41 100644 --- a/railties/lib/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/generators/rails/app/templates/config/environments/development.rb.tt @@ -16,4 +16,4 @@ # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false -end
\ No newline at end of file +end diff --git a/railties/lib/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/generators/rails/app/templates/config/environments/production.rb.tt index 543a40108c..ee071df63b 100644 --- a/railties/lib/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/generators/rails/app/templates/config/environments/production.rb.tt @@ -30,4 +30,4 @@ # Enable threaded mode # config.threadsafe! -end
\ No newline at end of file +end diff --git a/railties/lib/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/generators/rails/app/templates/config/environments/test.rb.tt index 428fa35633..f6c38f3c0d 100644 --- a/railties/lib/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/generators/rails/app/templates/config/environments/test.rb.tt @@ -26,4 +26,4 @@ # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql -end
\ No newline at end of file +end diff --git a/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb b/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb index 839d4cde19..59385cdf37 100644 --- a/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +++ b/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb @@ -4,4 +4,4 @@ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers!
\ No newline at end of file +# Rails.backtrace_cleaner.remove_silencers! diff --git a/railties/lib/generators/rails/app/templates/config/locales/en.yml b/railties/lib/generators/rails/app/templates/config/locales/en.yml index f265c068d8..a747bfa698 100644 --- a/railties/lib/generators/rails/app/templates/config/locales/en.yml +++ b/railties/lib/generators/rails/app/templates/config/locales/en.yml @@ -2,4 +2,4 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: - hello: "Hello world"
\ No newline at end of file + hello: "Hello world" diff --git a/railties/lib/generators/rails/app/templates/db/seeds.rb b/railties/lib/generators/rails/app/templates/db/seeds.rb index bc8695e6f0..664d8c74c8 100644 --- a/railties/lib/generators/rails/app/templates/db/seeds.rb +++ b/railties/lib/generators/rails/app/templates/db/seeds.rb @@ -2,6 +2,6 @@ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: -# +# # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first) diff --git a/railties/lib/generators/rails/app/templates/script/console.tt b/railties/lib/generators/rails/app/templates/script/console.tt index daba8ba2f1..915c5b8294 100755 --- a/railties/lib/generators/rails/app/templates/script/console.tt +++ b/railties/lib/generators/rails/app/templates/script/console.tt @@ -2,4 +2,4 @@ require File.expand_path('../../config/boot', __FILE__) require 'rails/commands/console' require File.expand_path('../../config/application', __FILE__) -Rails::Console.start(<%= app_const %>.instance) +Rails::Console.start(<%= app_const %>) diff --git a/railties/lib/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/generators/rails/app/templates/script/dbconsole.tt index a7f114a97f..a92f6f2844 100755 --- a/railties/lib/generators/rails/app/templates/script/dbconsole.tt +++ b/railties/lib/generators/rails/app/templates/script/dbconsole.tt @@ -2,4 +2,4 @@ require File.expand_path('../../config/boot', __FILE__) require 'rails/commands/dbconsole' require File.expand_path('../../config/application', __FILE__) -Rails::DBConsole.start(<%= app_const %>.instance) +Rails::DBConsole.start(<%= app_const %>) diff --git a/railties/lib/generators/rails/metal/templates/metal.rb b/railties/lib/generators/rails/metal/templates/metal.rb index e94982b69a..2f5d4e7593 100644 --- a/railties/lib/generators/rails/metal/templates/metal.rb +++ b/railties/lib/generators/rails/metal/templates/metal.rb @@ -1,12 +1,12 @@ # Allow the metal piece to run in isolation -require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) +require File.expand_path('../../../config/environment', __FILE__) class <%= class_name %> def self.call(env) if env["PATH_INFO"] =~ /^\/<%= file_name %>/ [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] else - [404, {"Content-Type" => "text/html"}, ["Not Found"]] + [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]] end end end diff --git a/railties/lib/generators/rails/plugin/templates/Rakefile.tt b/railties/lib/generators/rails/plugin/templates/Rakefile.tt index 23c2245a41..e94c0bfc77 100644 --- a/railties/lib/generators/rails/plugin/templates/Rakefile.tt +++ b/railties/lib/generators/rails/plugin/templates/Rakefile.tt @@ -1,22 +1,10 @@ -require 'rake' require 'rake/testtask' -require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the <%= file_name %> plugin.' Rake::TestTask.new(:test) do |t| - t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' end - -desc 'Generate documentation for the <%= file_name %> plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = '<%= class_name %>' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css index d9fa2cf2dc..de6669ad9e 100644 --- a/railties/lib/generators/rails/stylesheets/templates/scaffold.css +++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css @@ -59,4 +59,3 @@ div.field, div.actions { font-size: 12px; list-style: square; } - diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 4d05f8115c..8366127476 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -8,7 +8,13 @@ module Rails class << self attr_writer :config alias configure class_eval - delegate :initialize!, :load_tasks, :root, :to => :instance + delegate :call, + :initialize!, + :load_generators, + :load_tasks, + :middleware, + :root, + :to => :instance private :new def instance @@ -82,6 +88,10 @@ module Rails end end + def load_generators + plugins.each { |p| p.load_generators } + end + def initializers initializers = Bootstrap.new(self).initializers plugins.each { |p| initializers += p.initializers } @@ -89,13 +99,12 @@ module Rails initializers end - # TODO: Fix this method + # TODO: Fix this method. It loads all railties independent if :all is given + # or not, otherwise frameworks are never loaded. def plugins @plugins ||= begin plugin_names = (config.plugins || [:all]).map { |p| p.to_sym } - Railtie.plugins.select { |p| - plugin_names.include?(:all) || plugin_names.include?(p.plugin_name) - }.map { |p| p.new } + Plugin.all(plugin_names, config.paths.vendor.plugins) + Railtie.plugins.map(&:new) + Plugin.all(plugin_names, config.paths.vendor.plugins) end end @@ -107,6 +116,7 @@ module Rails end def call(env) + env["action_dispatch.parameter_filter"] = config.filter_parameters app.call(env) end diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 115499db05..b21ae2a17b 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -46,7 +46,6 @@ module Rails trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] - initialize_log_tailer! unless options[:daemonize] super ensure puts 'Exiting' unless options[:daemonize] @@ -54,6 +53,7 @@ module Rails def middleware middlewares = [] + middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize] middlewares << [Rails::Rack::Debugger] if options[:debugger] Hash.new(middlewares) end @@ -71,14 +71,5 @@ module Rails :pid => "tmp/pids/server.pid" }) end - - protected - - # LogTailer should not be used as a middleware since the logging happens - # async in a request and the middleware calls are sync. So we send it - # to subscriber which will be responsible for calling tail! in the log tailer. - def initialize_log_tailer! - Rails::Subscriber.log_tailer = Rails::Rack::LogTailer.new(nil, log_path) - end end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index b76a7ac2d8..7f1783a6b9 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -10,15 +10,15 @@ module Rails def self.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('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets }) middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency }) middleware.use('::Rack::Runtime') - middleware.use('ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local }) - middleware.use('ActionDispatch::Notifications') - middleware.use('ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes }) - middleware.use('ActionDispatch::Cookies') + middleware.use('::Rails::Rack::Logger') + middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local }) + middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes }) + middleware.use('::ActionDispatch::Cookies') middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options }) - middleware.use('ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) + middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store }) middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) }) middleware.use('ActionDispatch::ParamsParser') middleware.use('::Rack::MethodOverride') @@ -69,7 +69,7 @@ module Rails class Configuration < Railtie::Configuration attr_accessor :after_initialize_blocks, :cache_classes, :colorize_logging, - :consider_all_requests_local, :dependency_loading, + :consider_all_requests_local, :dependency_loading, :filter_parameters, :load_once_paths, :logger, :metals, :plugins, :preload_frameworks, :reload_plugins, :serve_static_assets, :time_zone, :whiny_nils @@ -83,6 +83,7 @@ module Rails super @load_once_paths = [] @after_initialize_blocks = [] + @filter_parameters = [] @dependency_loading = true @serve_static_assets = true end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 736c36c0dc..83b8c74966 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -134,9 +134,14 @@ module Rails lookups = [] lookups << "#{base}:#{name}" if base lookups << "#{name}:#{context}" if context - lookups << "#{name}:#{name}" unless name.to_s.include?(?:) - lookups << "#{name}" - lookups << "rails:#{name}" unless base || context || name.to_s.include?(?:) + + unless base || context + unless name.to_s.include?(?:) + lookups << "#{name}:#{name}" + lookups << "rails:#{name}" + end + lookups << "#{name}" + end lookup(lookups) @@ -168,7 +173,7 @@ module Rails # Show help message with available generators. def self.help - traverse_load_paths! + lookup! namespaces = subclasses.map{ |k| k.namespace } namespaces.sort! @@ -226,27 +231,15 @@ module Rails nil end - # This will try to load any generator in the load path to show in help. - def self.traverse_load_paths! #:nodoc: - $LOAD_PATH.each do |base| - Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| - begin - require path - rescue Exception => e - # No problem - end - end - end - end - # Receives namespaces in an array and tries to find matching generators # in the load path. def self.lookup(namespaces) #:nodoc: + load_generators_from_railties! paths = namespaces_to_paths(namespaces) - paths.each do |path| - ["generators", "rails_generators"].each do |base| - path = "#{base}/#{path}_generator" + paths.each do |raw_path| + ["rails_generators", "generators"].each do |base| + path = "#{base}/#{raw_path}_generator" begin require path @@ -255,12 +248,36 @@ module Rails raise unless e.message =~ /#{Regexp.escape(path)}$/ rescue NameError => e raise unless e.message =~ /Rails::Generator([\s(::)]|$)/ - warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}" + warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}.\n#{e.backtrace.join("\n")}" + rescue Exception => e + warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}" end end end end + # This will try to load any generator in the load path to show in help. + def self.lookup! #:nodoc: + load_generators_from_railties! + + $LOAD_PATH.each do |base| + Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| + begin + require path + rescue Exception => e + # No problem + end + end + end + end + + # Allow generators to be loaded from custom paths. + def self.load_generators_from_railties! #:nodoc: + return if defined?(@generators_from_railties) || Rails.application.nil? + @generators_from_railties = true + Rails.application.load_generators + end + # Convert namespaces to paths by replacing ":" for "/" and adding # an extra lookup. For example, "rails:model" should be searched # in both: "rails/model/model_generator" and "rails/model_generator". @@ -268,7 +285,7 @@ module Rails paths = [] namespaces.each do |namespace| pieces = namespace.split(":") - paths << pieces.dup.push(pieces.last).join("/") + paths << pieces.dup.push(pieces.last).join("/") unless pieces.uniq.size == 1 paths << pieces.join("/") end paths.uniq! diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 0c09730963..c3b81bcd3e 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -27,7 +27,7 @@ module Rails end def load_tasks - Dir["#{path}/**/tasks/**/*.rake"].sort.each { |ext| load ext } + Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext } end initializer :add_to_load_path, :after => :set_autoload_paths do |app| diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index 36945a6b0f..4bc0c2c88b 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,6 +1,7 @@ module Rails module Rack autoload :Debugger, "rails/rack/debugger" + autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" autoload :Metal, "rails/rack/metal" autoload :Static, "rails/rack/static" diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb new file mode 100644 index 0000000000..91a613092f --- /dev/null +++ b/railties/lib/rails/rack/logger.rb @@ -0,0 +1,38 @@ +require 'rails/subscriber' + +module Rails + module Rack + # Log the request started and flush all loggers after it. + class Logger < Rails::Subscriber + def initialize(app) + @app = app + end + + def call(env) + @env = env + before_dispatch + result = @app.call(@env) + after_dispatch + result + end + + protected + + def request + @request ||= ActionDispatch::Request.new(@env) + end + + def before_dispatch + path = request.request_uri.inspect rescue "unknown" + + info "\n\nStarted #{request.method.to_s.upcase} #{path} " << + "for #{request.remote_ip} at #{Time.now.to_s(:db)}" + end + + def after_dispatch + Rails::Subscriber.flush_all! + end + + end + end +end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 49a4d22319..611688cef1 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -150,13 +150,28 @@ module Rails @rake_tasks end + def self.generators(&blk) + @generators ||= [] + @generators << blk if blk + @generators + end + def rake_tasks self.class.rake_tasks end + def generators + self.class.generators + end + def load_tasks return unless rake_tasks rake_tasks.each { |blk| blk.call } end + + def load_generators + return unless generators + generators.each { |blk| blk.call } + end end end diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/subscriber.rb index a0cc5b86df..6638ff28c1 100644 --- a/railties/lib/rails/subscriber.rb +++ b/railties/lib/rails/subscriber.rb @@ -33,7 +33,7 @@ module Rails # Subscriber also has some helpers to deal with logging and automatically flushes # all logs when the request finishes (via action_dispatch.callback notification). class Subscriber - mattr_accessor :colorize_logging, :log_tailer + mattr_accessor :colorize_logging self.colorize_logging = true # Embed in a String to clear all previous ANSI sequences. @@ -63,12 +63,11 @@ module Rails subscriber = subscribers[namespace.to_sym] if subscriber.respond_to?(name) && subscriber.logger - subscriber.send(name, ActiveSupport::Notifications::Event.new(*args)) - end - - if args[0] == "action_dispatch.after_dispatch" && !subscribers.empty? - flush_all! - log_tailer.tail! if log_tailer + 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}" + end end end diff --git a/railties/lib/rails/subscriber/test_helper.rb b/railties/lib/rails/subscriber/test_helper.rb index 1464767ed9..39b4117372 100644 --- a/railties/lib/rails/subscriber/test_helper.rb +++ b/railties/lib/rails/subscriber/test_helper.rb @@ -1,12 +1,12 @@ require 'rails/subscriber' -require 'active_support/notifications' module Rails class Subscriber # Provides some helpers to deal with testing subscribers by setting up # notifications. Take for instance ActiveRecord subscriber tests: # - # module SubscriberTest + # class SyncSubscriberTest < ActiveSupport::TestCase + # include Rails::Subscriber::TestHelper # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new) # # def test_basic_query_logging @@ -39,8 +39,6 @@ module Rails # module TestHelper def setup - Thread.abort_on_exception = true - @logger = MockLogger.new @notifier = ActiveSupport::Notifications::Notifier.new(queue) @@ -54,7 +52,6 @@ module Rails def teardown set_logger(nil) ActiveSupport::Notifications.notifier = nil - Thread.abort_on_exception = false end class MockLogger @@ -92,26 +89,9 @@ module Rails def set_logger(logger) Rails.logger = logger end - end - - module SyncTestHelper - include TestHelper - - def queue - ActiveSupport::Notifications::Fanout.new(true) - end - end - - module AsyncTestHelper - include TestHelper def queue - ActiveSupport::Notifications::Fanout.new(false) - end - - def wait - sleep(0.01) - super + ActiveSupport::Notifications::Fanout.new end end end diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake index e1ab309157..5a5bd7a7e9 100644 --- a/railties/lib/rails/tasks/middleware.rake +++ b/railties/lib/rails/tasks/middleware.rake @@ -3,5 +3,5 @@ task :middleware => :environment do Rails.configuration.middleware.active.each do |middleware| puts "use #{middleware.inspect}" end - puts "run ActionController::Routing::Routes" + puts "run #{Rails.application.class.name}" end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 79dfacdcdb..6968e87986 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -122,5 +122,17 @@ module ApplicationTests require "#{app_path}/config/environment" end end + + test "filter_parameters should be able to set via config.filter_parameters" do + add_to_config <<-RUBY + config.filter_parameters += [ :foo, 'bar', lambda { |key, value| + value = value.reverse if key =~ /baz/ + }] + RUBY + + assert_nothing_raised do + require "#{app_path}/config/application" + end + end end end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 1c5cc62ecd..31696598ce 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -17,8 +17,8 @@ module ApplicationTests "ActionDispatch::Static", "Rack::Lock", "Rack::Runtime", + "Rails::Rack::Logger", "ActionDispatch::ShowExceptions", - "ActionDispatch::Notifications", "ActionDispatch::Callbacks", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", @@ -76,7 +76,7 @@ module ApplicationTests end def middleware - AppTemplate::Application.instance.middleware.active.map(&:klass).map(&:name) + AppTemplate::Application.middleware.active.map(&:klass).map(&:name) end end end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 725dd06929..50cb9e3acc 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -176,5 +176,33 @@ module ApplicationTests get '/foo' assert_equal 'baz', last_response.body end + + test 'resource routing with irrigular inflection' do + app_file 'config/initializers/inflection.rb', <<-RUBY + ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'yazi', 'yazilar' + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + resources :yazilar + end + RUBY + + controller 'yazilar', <<-RUBY + class YazilarController < ActionController::Base + def index + render :text => 'yazilar#index' + end + end + RUBY + + get '/yazilars' + assert_equal 404, last_response.status + + get '/yazilar' + assert_equal 200, last_response.status + end end end diff --git a/railties/test/fixtures/lib/generators/model_generator.rb b/railties/test/fixtures/lib/generators/model_generator.rb new file mode 100644 index 0000000000..9098a8a354 --- /dev/null +++ b/railties/test/fixtures/lib/generators/model_generator.rb @@ -0,0 +1 @@ +raise "I should never be loaded"
\ No newline at end of file diff --git a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb index d1de8c56fa..d1de8c56fa 100644 --- a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb +++ b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 4bfe210efb..0a79e2cfb8 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -17,11 +17,11 @@ class PluginGeneratorTest < Rails::Generators::TestCase vendor/plugins/plugin_fu/uninstall.rb vendor/plugins/plugin_fu/lib vendor/plugins/plugin_fu/lib/plugin_fu.rb + vendor/plugins/plugin_fu/Rakefile ).each{ |path| assert_file path } %w( vendor/plugins/plugin_fu/README - vendor/plugins/plugin_fu/Rakefile ).each{ |path| assert_file path, /PluginFu/ } %w( diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 60c81a813f..f37b684f73 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -16,6 +16,7 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_simple_invoke + assert File.exists?(File.join(@path, 'generators', 'model_generator.rb')) TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {}) Rails::Generators.invoke("test_unit:model", ["Account"]) end @@ -30,6 +31,13 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /Description:/, output end + def test_should_give_higher_preference_to_rails_generators + assert File.exists?(File.join(@path, 'generators', 'model_generator.rb')) + Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) + warnings = capture(:stderr){ Rails::Generators.invoke :model, ["Account"] } + assert warnings.empty? + end + def test_invoke_with_default_values Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) Rails::Generators.invoke :model, ["Account"] @@ -148,6 +156,13 @@ class GeneratorsTest < Rails::Generators::TestCase Rails::Generators.subclasses.delete(klass) end + def test_load_generators_from_railties + Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) + Rails::Generators.send(:remove_instance_variable, :@generators_from_railties) + Rails.application.expects(:load_generators) + Rails::Generators.invoke("model", ["Account"]) + end + def test_rails_root_templates template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb") diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index c920db77aa..d57fd4e635 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -30,6 +30,22 @@ module PluginsTest AppTemplate::Application.load_tasks assert $ran_block end + + test "generators block is executed when MyApp.load_generators is called" do + $ran_block = false + + class MyTie < Rails::Railtie + generators do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + AppTemplate::Application.load_generators + assert $ran_block + end end class ActiveRecordExtensionTest < Test::Unit::TestCase diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb index fa3f7bfabb..f6c895093f 100644 --- a/railties/test/subscriber_test.rb +++ b/railties/test/subscriber_test.rb @@ -18,9 +18,15 @@ class MySubscriber < Rails::Subscriber def bar(event) info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}" end + + def puke(event) + raise "puke" + end end -module SubscriberTest +class SyncSubscriberTest < ActiveSupport::TestCase + include Rails::Subscriber::TestHelper + def setup super @subscriber = MySubscriber.new @@ -90,41 +96,24 @@ module SubscriberTest assert_equal 1, @logger.flush_count end - def test_flushes_loggers_when_action_dispatch_callback_is_received - Rails::Subscriber.add :my_subscriber, @subscriber - instrument "action_dispatch.after_dispatch" - wait - 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 - instrument "action_dispatch.after_dispatch" + Rails::Subscriber.flush_all! wait assert_equal 1, @logger.flush_count end - def test_tails_logs_when_action_dispatch_callback_is_received - log_tailer = mock() - log_tailer.expects(:tail!) - Rails::Subscriber.log_tailer = log_tailer - + def test_logging_does_not_die_on_failures Rails::Subscriber.add :my_subscriber, @subscriber - instrument "action_dispatch.after_dispatch" + instrument "my_subscriber.puke" + instrument "my_subscriber.some_event" wait - ensure - Rails::Subscriber.log_tailer = nil - end - class SyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::SyncTestHelper - include SubscriberTest - end + assert_equal 1, @logger.logged(:info).size + assert_equal 'my_subscriber.some_event', @logger.logged(:info).last - class AsyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::AsyncTestHelper - include SubscriberTest + 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 |