From 9fd35fc2d892393386ca9f522d25ba0bcb9c6764 Mon Sep 17 00:00:00 2001 From: Aaron Quint Date: Sat, 27 Dec 2008 21:03:12 +0000 Subject: Adding test coverage and better logging to Rails::TemplateRunner [#1618 state:resolved] Signed-off-by: Pratik Naik --- .../generators/applications/app/template_runner.rb | 119 +++++++++------------ 1 file changed, 53 insertions(+), 66 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index c6113648e6..4af85762aa 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -8,23 +8,24 @@ require 'fileutils' module Rails class TemplateRunner attr_reader :root + attr_writer :logger def initialize(template, root = '') # :nodoc: - @root = File.join(Dir.pwd, root) + @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root)) - puts "applying template: #{template}" + log 'applying', "template: #{template}" load_template(template) - puts "#{template} applied." + log 'applied', "#{template}" end def load_template(template) begin code = open(template).read in_root { self.instance_eval(code) } - rescue LoadError - raise "The template [#{template}] could not be loaded." + rescue LoadError, Errno::ENOENT => e + raise "The template [#{template}] could not be loaded. Error: #{e}" end end @@ -41,8 +42,8 @@ module Rails # # file("config/apach.conf", "your apache config") # - def file(filename, data = nil, &block) - puts "creating file #{filename}" + def file(filename, data = nil, log_action = true, &block) + log 'file', filename if log_action dir, file = [File.dirname(filename), File.basename(filename)] inside(dir) do @@ -66,7 +67,7 @@ module Rails # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk' # def plugin(name, options) - puts "installing plugin #{name}" + log 'plugin', name if options[:git] && options[:submodule] in_root do @@ -74,18 +75,17 @@ module Rails end elsif options[:git] || options[:svn] in_root do - `script/plugin install #{options[:svn] || options[:git]}` + run("script/plugin install #{options[:svn] || options[:git]}", false) end else - puts "! no git or svn provided for #{name}. skipping..." + log "! no git or svn provided for #{name}. skipping..." end end # Adds an entry into config/environment.rb for the supplied gem : def gem(name, options = {}) - puts "adding gem #{name}" + log 'gem', name - sentinel = 'Rails::Initializer.run do |config|' gems_code = "config.gem '#{name}'" if options.any? @@ -93,9 +93,18 @@ module Rails gems_code << ", #{opts}" end + environment gems_code + end + + # Adds a line inside the Initializer block for config/environment.rb. Used by #gem + def environment(data = nil, &block) + sentinel = 'Rails::Initializer.run do |config|' + + data = block.call if !data && block_given? + in_root do gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n #{gems_code}" + "#{match}\n " << data end end end @@ -111,11 +120,11 @@ module Rails def git(command = {}) in_root do if command.is_a?(Symbol) - puts "running git #{command}" + log 'running', "git #{command}" Git.run(command.to_s) else command.each do |command, options| - puts "running git #{command} #{options}" + log 'running', "git #{command} #{options}" Git.run("#{command} #{options}") end end @@ -135,16 +144,8 @@ module Rails # vendor("foreign.rb", "# Foreign code is fun") # def vendor(filename, data = nil, &block) - puts "vendoring file #{filename}" - inside("vendor") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'vendoring', filename + file("vendor/#{filename}", data, false, &block) end # Create a new file in the lib/ directory. Code can be specified @@ -158,17 +159,9 @@ module Rails # # lib("foreign.rb", "# Foreign code is fun") # - def lib(filename, data = nil) - puts "add lib file #{filename}" - inside("lib") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + def lib(filename, data = nil, &block) + log 'lib', filename + file("lib/#{filename}", data, false, &block) end # Create a new Rakefile with the provided code (either in a block or a string). @@ -190,16 +183,8 @@ module Rails # rakefile("seed.rake", "puts 'im plantin ur seedz'") # def rakefile(filename, data = nil, &block) - puts "adding rakefile #{filename}" - inside("lib/tasks") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'rakefile', filename + file("lib/tasks/#{filename}", data, false, &block) end # Create a new initializer with the provided code (either in a block or a string). @@ -219,16 +204,8 @@ module Rails # initializer("api.rb", "API_KEY = '123456'") # def initializer(filename, data = nil, &block) - puts "adding initializer #{filename}" - inside("config/initializers") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'initializer', filename + file("config/initializers/#{filename}", data, false, &block) end # Generate something using a generator from Rails or a plugin. @@ -240,10 +217,10 @@ module Rails # generate(:authenticated, "user session") # def generate(what, *args) - puts "generating #{what}" + log 'generating', what argument = args.map(&:to_s).flatten.join(" ") - in_root { `#{root}/script/generate #{what} #{argument}` } + in_root { run("script/generate #{what} #{argument}", false) } end # Executes a command @@ -254,8 +231,8 @@ module Rails # run('ln -s ~/edge rails) # end # - def run(command) - puts "executing #{command} from #{Dir.pwd}" + def run(command, log_action = true) + log 'executing', "#{command} from #{Dir.pwd}" if log_action `#{command}` end @@ -268,10 +245,10 @@ module Rails # rake("gems:install", :sudo => true) # def rake(command, options = {}) - puts "running rake task #{command}" + log 'rake', command env = options[:env] || 'development' sudo = options[:sudo] ? 'sudo ' : '' - in_root { `#{sudo}rake #{command} RAILS_ENV=#{env}` } + in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } end # Just run the capify command in root @@ -281,7 +258,8 @@ module Rails # capify! # def capify! - in_root { `capify .` } + log 'capifying' + in_root { run('capify .', false) } end # Add Rails to /vendor/rails @@ -291,8 +269,8 @@ module Rails # freeze! # def freeze!(args = {}) - puts "vendoring rails edge" - in_root { `rake rails:freeze:edge` } + log 'vendor', 'rails edge' + in_root { run('rake rails:freeze:edge', false) } end # Make an entry in Rails routing file conifg/routes.rb @@ -302,6 +280,7 @@ module Rails # route "map.root :controller => :welcome" # def route(routing_code) + log 'route', routing_code sentinel = 'ActionController::Routing::Routes.draw do |map|' in_root do @@ -321,7 +300,7 @@ module Rails # freeze! if ask("Should I freeze the latest Rails?") == "yes" # def ask(string) - puts string + log '', string gets.strip end @@ -368,5 +347,13 @@ module Rails def destination_path(relative_destination) File.join(root, relative_destination) end + + def log(action, message = '') + logger.log(action, message) + end + + def logger + @logger ||= Rails::Generator::Base.logger + end end end \ No newline at end of file -- cgit v1.2.3 From c0c79f779c990f9e53c9b600291801fdf0bbe56b Mon Sep 17 00:00:00 2001 From: Aaron Quint Date: Sat, 27 Dec 2008 23:29:48 -0500 Subject: Use SimpleLogger for Rails::TemplateRunner outside of the Generator context [#1618 state:resolved] Signed-off-by: Pratik Naik --- .../generators/applications/app/template_runner.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index 4af85762aa..7f2e086271 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -355,5 +355,15 @@ module Rails def logger @logger ||= Rails::Generator::Base.logger end + + def logger + @logger ||= if defined?(Rails::Generator::Base) + Rails::Generator::Base.logger + else + require 'rails_generator/simple_logger' + Rails::Generator::SimpleLogger.new(STDOUT) + end + end + end end \ No newline at end of file -- cgit v1.2.3 From 1fb275541a58e6a2100261c6117e96e6c014cc6c Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Sun, 28 Dec 2008 10:57:37 -0600 Subject: Ensure template runner tests don't depend on hash ordering [#1654 state:resolved] Signed-off-by: Pratik Naik --- .../lib/rails_generator/generators/applications/app/template_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index 7f2e086271..bb7bd0e6f4 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -89,7 +89,7 @@ module Rails gems_code = "config.gem '#{name}'" if options.any? - opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.join(", ") + opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.sort.join(", ") gems_code << ", #{opts}" end -- cgit v1.2.3 From 1f0aecd931a9292b52402143be979ab4c06f06cd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 28 Dec 2008 15:10:41 -0600 Subject: Allow custom rails generators to pass in their own binding to Create command so that the corresponding erb templates get rendered with the proper binding [#1493 state:resolved] --- railties/lib/rails_generator/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index cacb3807d6..299044c3d7 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -294,7 +294,7 @@ HELP file(relative_source, relative_destination, template_options) do |file| # Evaluate any assignments in a temporary, throwaway binding. vars = template_options[:assigns] || {} - b = binding + b = template_options[:binding] || binding vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } # Render the source file with the temporary binding. -- cgit v1.2.3 From 558ab327b733717f4a8de3ed62b8dcd62e9ff9c3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 29 Dec 2008 19:27:19 -0600 Subject: Clean up view path cruft and split path implementations into Template::Path and Template::EagerPath --- railties/lib/initializer.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 637fe74313..10c2490624 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -370,8 +370,9 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + view_path = ActionView::Template::EagerPath.new(configuration.view_path) + ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) end end end @@ -473,7 +474,7 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views if configuration.frameworks.include?(:action_view) - view_path = ActionView::PathSet::Path.new(configuration.view_path, false) + view_path = ActionView::Template::Path.new(configuration.view_path) ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer) ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? end -- cgit v1.2.3 From 2f9edde142a15452eb088b8b4b2a38272dde2ba5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 30 Dec 2008 12:44:31 -0800 Subject: Clean trailing / after rails root from backtraces --- railties/lib/rails/backtrace_cleaner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 94d34cda39..ee67255289 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -15,7 +15,7 @@ module Rails def initialize super - add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub("#{RAILS_ROOT}/", '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } add_filter { |line| line.sub('./', '/') } # for tests add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 -- cgit v1.2.3 From a5004573d8d132fe079242fc082ab4661b0976e9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 30 Dec 2008 18:25:44 -0800 Subject: Only silence backtrace from plugin lib dirs --- railties/lib/rails/backtrace_cleaner.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index ee67255289..e1b422716d 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -2,7 +2,7 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ - VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + VENDOR_DIRS = %w( vendor/gems vendor/rails ) SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/passenger bin/passenger-spawn-server lib/rack ) @@ -20,6 +20,7 @@ module Rails add_filter { |line| line.sub('./', '/') } # for tests add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } end end -- cgit v1.2.3 From ed2e776bdec3f0764433a6dc4f592f9bebfea859 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 3 Jan 2009 23:02:29 -0600 Subject: Move metal above method piggybacking middleware and add some test coverage --- railties/lib/initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 10c2490624..619701460d 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -537,7 +537,7 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal - configuration.middleware.use Rails::Rack::Metal + configuration.middleware.insert_before(:"ActionController::VerbPiggybacking", Rails::Rack::Metal) end # Initializes framework-specific settings for each of the loaded frameworks -- cgit v1.2.3 From 9b96e8d1ccb5b4548896b4100004e6371633f9fb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 6 Jan 2009 15:36:08 -0800 Subject: Consolidate test_help requires --- railties/lib/test_help.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index b5c92c1790..93ba1bc216 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -3,8 +3,7 @@ silence_warnings { RAILS_ENV = "test" } require 'test/unit' -require 'active_support/test_case' -require 'action_controller/test_case' +require 'action_controller/test_process' require 'action_view/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -- cgit v1.2.3 From 35fa00731329120fa1d0c2a9d66af6813203195a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 Jan 2009 13:23:10 -0800 Subject: Include process methods in ActionController::TestCase only. No need to alias_method_chain :process either. --- railties/lib/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 93ba1bc216..ee24ea3a45 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -3,7 +3,7 @@ silence_warnings { RAILS_ENV = "test" } require 'test/unit' -require 'action_controller/test_process' +require 'action_controller/test_case' require 'action_view/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -- cgit v1.2.3 From b281a6a5b2137548501ef590379d7af5f6955d2d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 13 Jan 2009 17:26:29 -0600 Subject: Use Rack's MethodOverride lib [#1699 state:resolved] --- railties/lib/initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 619701460d..824d1d6096 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -537,7 +537,7 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal - configuration.middleware.insert_before(:"ActionController::VerbPiggybacking", Rails::Rack::Metal) + configuration.middleware.insert_before(:"ActionController::RewindableInput", Rails::Rack::Metal) end # Initializes framework-specific settings for each of the loaded frameworks -- cgit v1.2.3 From a53ad5bba37199047ba20194933e122bf6b0252f Mon Sep 17 00:00:00 2001 From: Nahum Wild Date: Thu, 15 Jan 2009 21:28:10 -0600 Subject: Added in a local per request cache to MemCacheStore. It acts as a buffer to stop unneccessary requests being sent through to memcache [#1653 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 824d1d6096..b57c46e098 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -414,6 +414,9 @@ Run `rake gems:install` to install the missing gems. def initialize_cache unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) } + if RAILS_CACHE.class.name == "ActiveSupport::Cache::MemCacheStore" + configuration.middleware.insert_after(:"ActionController::Failsafe", ActiveSupport::Cache::MemCacheStore::LocalCache) + end end end -- cgit v1.2.3 From b08c96887538cf53670bb882e79996582375e6c9 Mon Sep 17 00:00:00 2001 From: Lourens Naude Date: Sat, 17 Jan 2009 18:05:48 -0600 Subject: Decouple the local cache strategy from MemCacheStore for reuse with other remote stores [#1653 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b57c46e098..f6b8899d58 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -414,8 +414,10 @@ Run `rake gems:install` to install the missing gems. def initialize_cache unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) } - if RAILS_CACHE.class.name == "ActiveSupport::Cache::MemCacheStore" - configuration.middleware.insert_after(:"ActionController::Failsafe", ActiveSupport::Cache::MemCacheStore::LocalCache) + + if RAILS_CACHE.respond_to?(:middleware) + # Insert middleware to setup and teardown local cache for each request + configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware) end end end -- cgit v1.2.3 From 41af606db385abe429888c5aca8b2e86c8830c24 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 18 Jan 2009 05:16:39 +0000 Subject: Remove script/performance/profiler in favour of performance integration tests. To continue using script/performance/profiler, install the request_profiler plugin : script/plugin install git://github.com/rails/request_profiler.git --- railties/lib/commands/performance/request.rb | 6 ------ .../rails_generator/generators/applications/app/app_generator.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100755 railties/lib/commands/performance/request.rb (limited to 'railties/lib') diff --git a/railties/lib/commands/performance/request.rb b/railties/lib/commands/performance/request.rb deleted file mode 100755 index 1773886487..0000000000 --- a/railties/lib/commands/performance/request.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -require 'config/environment' -require 'application' -require 'action_controller/request_profiler' - -ActionController::RequestProfiler.run(ARGV) diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 795a0d7653..2c31d89538 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -151,7 +151,7 @@ class AppGenerator < Rails::Generator::Base def create_script_files(m) %w( about console dbconsole destroy generate runner server plugin - performance/benchmarker performance/profiler performance/request + performance/benchmarker performance/profiler ).each do |file| m.file "bin/#{file}", "script/#{file}", { :chmod => 0755, -- cgit v1.2.3 From 085991891e610ed0ab616ce434eabf42a9437039 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 18 Jan 2009 05:28:21 +0000 Subject: Bump up the year in MIT license files --- railties/lib/dispatcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 0bad45d9d8..9f8b59aa3d 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2008 David Heinemeier Hansson +# Copyright (c) 2004-2009 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the -- cgit v1.2.3 From 39e1ac658efc80e4c54abef4f1c7679e4b3dc2ac Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 18 Jan 2009 18:10:58 +0000 Subject: Merge docrails --- .../generators/applications/app/template_runner.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index bb7bd0e6f4..84e36ecc1b 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -338,6 +338,12 @@ module Rails !yes?(question) end + # Run a regular expression replacement on a file + # + # ==== Example + # + # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1' + # def gsub_file(relative_destination, regexp, *args, &block) path = destination_path(relative_destination) content = File.read(path).gsub(regexp, *args, &block) @@ -366,4 +372,4 @@ module Rails end end -end \ No newline at end of file +end -- cgit v1.2.3 From 82334a74311a3e0a8a1454d0a4a2ebf3c1138cea Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Jan 2009 12:37:03 -0600 Subject: Only insert metal middleware if any exist --- railties/lib/initializer.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index f6b8899d58..dd4d483233 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -542,7 +542,9 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal - configuration.middleware.insert_before(:"ActionController::RewindableInput", Rails::Rack::Metal) + configuration.middleware.insert_before( + :"ActionController::RewindableInput", + Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) end # Initializes framework-specific settings for each of the loaded frameworks -- cgit v1.2.3 From 73cc5f270a5c2a2eab76c6c02615fec608822494 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 21 Jan 2009 12:44:07 -0600 Subject: Setup ActiveRecord QueryCache middleware in the initializer --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index dd4d483233..be04873855 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -408,6 +408,7 @@ Run `rake gems:install` to install the missing gems. if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection + configuration.middleware.use ActiveRecord::QueryCache end end -- cgit v1.2.3