From 8a4239fc7e6669da9843e5aa28b5ba2a47f26b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 7 Oct 2011 22:25:03 +0200 Subject: testing.rake should set the default task, closes #2564 --- railties/lib/rails/tasks/misc.rake | 2 -- railties/lib/rails/test_unit/testing.rake | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index 8b4775d1d3..0dcca36d8b 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -1,5 +1,3 @@ -task :default => :test - task :rails_env do # TODO Do we really need this? unless defined? RAILS_ENV diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 33da2c0f5a..fa01f42c5b 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -71,6 +71,8 @@ module Kernel end end +task :default => :test + desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)' task :test do tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units test:functionals test:integration) -- cgit v1.2.3 From 6c9090d19299f25c4768fccf4920444d470a9ea7 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 8 Oct 2011 14:39:19 +0530 Subject: Sqlnet should also be ignored into the app gitignore --- railties/lib/rails/generators/rails/app/templates/gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 923b697662..c376100cfe 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -3,3 +3,4 @@ db/*.sqlite3 log/*.log tmp/ .sass-cache/ +sqlnet.log \ No newline at end of file -- cgit v1.2.3 From 96e1dc3440e055e2b1403b0cecaab4f778c13d30 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 8 Oct 2011 12:54:24 -0200 Subject: Revert "Merge pull request #3254 from arunagw/app_gitignore_sqlnet_log" This reverts commit bb8e0673299899c913d664c0fd3c483d8569846c, reversing changes made to 11687382db08ec1523f71e485c48d6039de25324. --- railties/lib/rails/generators/rails/app/templates/gitignore | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index c376100cfe..923b697662 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -3,4 +3,3 @@ db/*.sqlite3 log/*.log tmp/ .sass-cache/ -sqlnet.log \ No newline at end of file -- cgit v1.2.3 From 1851791803e58dfa19dfe1cb686cf5870e655b27 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 8 Oct 2011 08:04:05 -0700 Subject: Add comments to our generated .gitignore, including a note about when to use a global gitignore. Remove .sass-cache since we use /tmp/sass-cache, which is already ignored. --- .../rails/generators/rails/app/templates/gitignore | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 923b697662..eb3489a986 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -1,5 +1,15 @@ -.bundle -db/*.sqlite3 -log/*.log -tmp/ -.sass-cache/ +# See http://help.github.com/ignore-files/ for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile ~/.gitignore_global + +# Ignore bundler config +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 + +# Ignore all logfiles and tempfiles. +/log/*.log +/tmp -- cgit v1.2.3 From ca219a21b60ea20868deab20afaa0335d32f1c17 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 9 Oct 2011 17:15:55 +0530 Subject: Warnings removed when running with 1.9.3 --- railties/lib/rails/generators/resource_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index de01c858dd..b34bc4a524 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -65,7 +65,7 @@ module Rails begin "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize - rescue NameError => e + rescue NameError Rails::Generators::ActiveModel end end -- cgit v1.2.3 From 44fc397c801aa09f2b5438f65ab7adb4482d58be Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 10 Oct 2011 20:10:35 +1100 Subject: Fix rails/generators/base.rb documentation for generator lookup --- railties/lib/rails/generators/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index b9dc31457a..911f80cf3a 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -91,7 +91,7 @@ module Rails # # The lookup in this case for test_unit as input is: # - # "test_unit:awesome", "test_unit" + # "test_framework:awesome", "test_framework" # # Which is not the desired the lookup. You can change it by providing the # :as option: @@ -102,7 +102,7 @@ module Rails # # And now it will lookup at: # - # "test_unit:controller", "test_unit" + # "test_framework:controller", "test_framework" # # Similarly, if you want it to also lookup in the rails namespace, you just # need to provide the :base value: @@ -113,7 +113,7 @@ module Rails # # And the lookup is exactly the same as previously: # - # "rails:test_unit", "test_unit:controller", "test_unit" + # "rails:test_framework", "test_framework:controller", "test_framework" # # ==== Switches # -- cgit v1.2.3 From 43c01ef8b1a49ccb85700d8e248fd10742ede014 Mon Sep 17 00:00:00 2001 From: Sasha Gerrand Date: Tue, 11 Oct 2011 17:04:24 +1100 Subject: Added method to create vendor/assets/javascripts, added it to methods called within vendor method --- railties/lib/rails/generators/rails/app/app_generator.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 9cbda6649d..c8648d19f8 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -122,10 +122,15 @@ module Rails end def vendor + vendor_javascripts vendor_stylesheets vendor_plugins end + def vendor_javascripts + empty_directory_with_gitkeep "vendor/assets/javascripts" + end + def vendor_stylesheets empty_directory_with_gitkeep "vendor/assets/stylesheets" end -- cgit v1.2.3 From d32a90b9b77d3f7d8098ee6ddb5bf62cb8da0ed7 Mon Sep 17 00:00:00 2001 From: "Suraj N. Kurapati" Date: Thu, 13 Oct 2011 10:16:50 -0700 Subject: fix inconsistent alignment in Gemfile generator --- railties/lib/rails/generators/app_base.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 294563ad06..134d86fab0 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -150,7 +150,7 @@ module Rails gem 'rails', '#{Rails::VERSION::STRING}' # Bundle edge Rails instead: - # gem 'rails', :git => 'git://github.com/rails/rails.git' + # gem 'rails', :git => 'git://github.com/rails/rails.git' GEMFILE end end @@ -158,11 +158,11 @@ module Rails def gem_for_database # %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql ) case options[:database] - when "oracle" then "ruby-oci8" - when "postgresql" then "pg" - when "frontbase" then "ruby-frontbase" - when "mysql" then "mysql2" - when "sqlserver" then "activerecord-sqlserver-adapter" + when "oracle" then "ruby-oci8" + when "postgresql" then "pg" + when "frontbase" then "ruby-frontbase" + when "mysql" then "mysql2" + when "sqlserver" then "activerecord-sqlserver-adapter" when "jdbcmysql" then "activerecord-jdbcmysql-adapter" when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter" when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter" -- cgit v1.2.3 From c547e968f5709f174ee13818b35429cbe585b5dd Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Mon, 17 Oct 2011 16:28:00 +0100 Subject: Added environment rake task to engines --- railties/lib/rails/tasks/engine.rake | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index 2152e811f5..eea8abe7d2 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -2,6 +2,7 @@ task "load_app" do namespace :app do load APP_RAKEFILE end + task :environment => "app:environment" if !defined?(ENGINE_PATH) || !ENGINE_PATH ENGINE_PATH = find_engine_path(APP_RAKEFILE) -- cgit v1.2.3 From 7f184aaf4352140c7e3bd33761058bb05737e11b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 18 Oct 2011 16:03:58 -0200 Subject: Use again Rack's ContentLength middleware --- railties/lib/rails/commands/server.rb | 1 - railties/lib/rails/rack.rb | 1 - railties/lib/rails/rack/content_length.rb | 38 ------------------------------- 3 files changed, 40 deletions(-) delete mode 100644 railties/lib/rails/rack/content_length.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 23392276d5..71e3711ba1 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -78,7 +78,6 @@ module Rails middlewares = [] middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize] middlewares << [Rails::Rack::Debugger] if options[:debugger] - middlewares << [Rails::Rack::ContentLength] Hash.new(middlewares) end diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index d4a41b217e..d1ee96f7fd 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,6 +1,5 @@ module Rails module Rack - autoload :ContentLength, "rails/rack/content_length" autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" diff --git a/railties/lib/rails/rack/content_length.rb b/railties/lib/rails/rack/content_length.rb deleted file mode 100644 index 6839af4152..0000000000 --- a/railties/lib/rails/rack/content_length.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'action_dispatch' -require 'rack/utils' - -module Rails - module Rack - # Sets the Content-Length header on responses with fixed-length bodies. - class ContentLength - include ::Rack::Utils - - def initialize(app, sendfile=nil) - @app = app - @sendfile = sendfile - end - - def call(env) - status, headers, body = @app.call(env) - headers = HeaderHash.new(headers) - - if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) && - !headers['Content-Length'] && - !headers['Transfer-Encoding'] && - !(@sendfile && headers[@sendfile]) - - old_body = body - body, length = [], 0 - old_body.each do |part| - body << part - length += bytesize(part) - end - old_body.close if old_body.respond_to?(:close) - headers['Content-Length'] = length.to_s - end - - [status, headers, body] - end - end - end -end \ No newline at end of file -- cgit v1.2.3 From d44702c830669e2647c073133bd6b09d7016424d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 18 Oct 2011 16:14:38 -0200 Subject: Use again Rack's ContentLength middleware part 2 --- railties/lib/rails/commands/server.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 71e3711ba1..33f9ac017c 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -78,6 +78,7 @@ module Rails middlewares = [] middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize] middlewares << [Rails::Rack::Debugger] if options[:debugger] + middlewares << [Rack::ContentLength] Hash.new(middlewares) end -- cgit v1.2.3 From 3a746f7c48936bac1c08dcf229c7c8fc74fdfc13 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 19 Oct 2011 12:31:06 -0500 Subject: Use toplevel Rack::ContentLength --- railties/lib/rails/commands/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 33f9ac017c..20484a10c8 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -78,7 +78,7 @@ module Rails middlewares = [] middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize] middlewares << [Rails::Rack::Debugger] if options[:debugger] - middlewares << [Rack::ContentLength] + middlewares << [::Rack::ContentLength] Hash.new(middlewares) end -- cgit v1.2.3 From afde6fdd5ef3e6b0693a7e330777e85ef4cffddb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Oct 2011 12:59:33 -0500 Subject: Added X-Request-Id tracking and TaggedLogging to easily log that and other production concerns --- railties/lib/rails/application.rb | 2 ++ railties/lib/rails/application/bootstrap.rb | 4 +-- railties/lib/rails/application/configuration.rb | 2 +- railties/lib/rails/rack.rb | 1 + railties/lib/rails/rack/logger.rb | 4 +-- railties/lib/rails/rack/tagged_logging.rb | 39 +++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 railties/lib/rails/rack/tagged_logging.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index cbb2d23238..a097cfd1be 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -164,6 +164,8 @@ module Rails middleware.use ::Rack::Lock unless config.allow_concurrency middleware.use ::Rack::Runtime middleware.use ::Rack::MethodOverride + middleware.use ::ActionDispatch::RequestId + middleware.use ::Rails::Rack::TaggedLogging, config.log_tags middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 0aff05b681..c2cb121e42 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -24,12 +24,12 @@ module Rails initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin path = config.paths["log"].first - logger = ActiveSupport::BufferedLogger.new(path) + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(path)) logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) logger.auto_flushing = false if Rails.env.production? logger rescue StandardError - logger = ActiveSupport::BufferedLogger.new(STDERR) + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) logger.level = ActiveSupport::BufferedLogger::WARN logger.warn( "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 448521d2f0..8f5b28faf8 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, - :force_ssl, :helpers_paths, :logger, :preload_frameworks, + :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :whiny_nils diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index d1ee96f7fd..b78293e570 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -3,5 +3,6 @@ module Rails autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" + autoload :TaggedLogging, "rails/rack/tagged_logging" end end diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 3be262de08..4d388c4d10 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -21,8 +21,8 @@ module Rails request = ActionDispatch::Request.new(env) path = request.filtered_path - info "\n\nStarted #{request.request_method} \"#{path}\" " \ - "for #{request.ip} at #{Time.now.to_default_s}" + info "\n\n" + info "Started #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}" end def after_dispatch(env) diff --git a/railties/lib/rails/rack/tagged_logging.rb b/railties/lib/rails/rack/tagged_logging.rb new file mode 100644 index 0000000000..7980319b37 --- /dev/null +++ b/railties/lib/rails/rack/tagged_logging.rb @@ -0,0 +1,39 @@ +module Rails + module Rack + # Enables easy tagging of any logging activity that occurs within the Rails request cycle. The tags are configured via the + # config.log_tags setting. The tags can either be strings, procs taking a request argument, or the symbols :uuid or :subdomain. + # The latter two are then automatically expanded to request.uuid and request.subdaomins.first -- the two most common tags + # desired in production logs. + class TaggedLogging + def initialize(app, tags = nil) + @app, @tags = app, tags + end + + def call(env) + if @tags + Rails.logger.tagged(compute_tags(env)) { @app.call(env) } + else + @app.call(env) + end + end + + private + def compute_tags(env) + request = ActionDispatch::Request.new(env) + + @tags.collect do |tag| + case tag + when Proc + tag.call(request) + when :uuid + request.uuid + when :subdomain + request.subdomains.first + else + tag + end + end + end + end + end +end -- cgit v1.2.3 From 4a4927f753d7f41c0903ab3adfb73be8490c382e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Oct 2011 13:24:28 -0500 Subject: Simplify TaggedLogging symbol shortcuts (thanks Jose!) --- railties/lib/rails/rack/tagged_logging.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/rack/tagged_logging.rb b/railties/lib/rails/rack/tagged_logging.rb index 7980319b37..c519d7c3e6 100644 --- a/railties/lib/rails/rack/tagged_logging.rb +++ b/railties/lib/rails/rack/tagged_logging.rb @@ -1,9 +1,8 @@ module Rails module Rack # Enables easy tagging of any logging activity that occurs within the Rails request cycle. The tags are configured via the - # config.log_tags setting. The tags can either be strings, procs taking a request argument, or the symbols :uuid or :subdomain. - # The latter two are then automatically expanded to request.uuid and request.subdaomins.first -- the two most common tags - # desired in production logs. + # config.log_tags setting. The tags can either be strings, procs taking a request argument, or symbols representing method + # names on request (so :uuid will result in request.uuid being added as a tag). class TaggedLogging def initialize(app, tags = nil) @app, @tags = app, tags @@ -25,10 +24,8 @@ module Rails case tag when Proc tag.call(request) - when :uuid - request.uuid - when :subdomain - request.subdomains.first + when Symbol + request.send(tag) else tag end -- cgit v1.2.3 From c83d9a11c00bc13e1f8f0fa0e8fb6185cacd5fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 19 Oct 2011 22:39:11 +0200 Subject: Unify logger and taggedlogging middleware as both address logging concerns. --- railties/lib/rails/application.rb | 3 +-- railties/lib/rails/rack.rb | 1 - railties/lib/rails/rack/logger.rb | 38 +++++++++++++++++++++---------- railties/lib/rails/rack/tagged_logging.rb | 36 ----------------------------- 4 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 railties/lib/rails/rack/tagged_logging.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index a097cfd1be..82fffe86bb 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -165,8 +165,7 @@ module Rails middleware.use ::Rack::Runtime middleware.use ::Rack::MethodOverride middleware.use ::ActionDispatch::RequestId - middleware.use ::Rails::Rack::TaggedLogging, config.log_tags - middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods + middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies if config.action_dispatch.x_sendfile_header.present? diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index b78293e570..d1ee96f7fd 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -3,6 +3,5 @@ module Rails autoload :Debugger, "rails/rack/debugger" autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" - autoload :TaggedLogging, "rails/rack/tagged_logging" end end diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 4d388c4d10..89de10c83d 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -1,32 +1,46 @@ require 'active_support/core_ext/time/conversions' +require 'active_support/core_ext/object/blank' module Rails module Rack # Log the request started and flush all loggers after it. class Logger < ActiveSupport::LogSubscriber - def initialize(app) - @app = app + def initialize(app, tags=nil) + @app, @tags = app, tags.presence end def call(env) - before_dispatch(env) - @app.call(env) - ensure - after_dispatch(env) + if @tags + Rails.logger.tagged(compute_tags(env)) { call_app(env) } + else + call_app(env) + end end protected - def before_dispatch(env) + def call_app(env) request = ActionDispatch::Request.new(env) path = request.filtered_path - - info "\n\n" - info "Started #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}" + Rails.logger.info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}" + @app.call(env) + ensure + ActiveSupport::LogSubscriber.flush_all! end - def after_dispatch(env) - ActiveSupport::LogSubscriber.flush_all! + def compute_tags(env) + request = ActionDispatch::Request.new(env) + + @tags.collect do |tag| + case tag + when Proc + tag.call(request) + when Symbol + request.send(tag) + else + tag + end + end end end end diff --git a/railties/lib/rails/rack/tagged_logging.rb b/railties/lib/rails/rack/tagged_logging.rb deleted file mode 100644 index c519d7c3e6..0000000000 --- a/railties/lib/rails/rack/tagged_logging.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Rails - module Rack - # Enables easy tagging of any logging activity that occurs within the Rails request cycle. The tags are configured via the - # config.log_tags setting. The tags can either be strings, procs taking a request argument, or symbols representing method - # names on request (so :uuid will result in request.uuid being added as a tag). - class TaggedLogging - def initialize(app, tags = nil) - @app, @tags = app, tags - end - - def call(env) - if @tags - Rails.logger.tagged(compute_tags(env)) { @app.call(env) } - else - @app.call(env) - end - end - - private - def compute_tags(env) - request = ActionDispatch::Request.new(env) - - @tags.collect do |tag| - case tag - when Proc - tag.call(request) - when Symbol - request.send(tag) - else - tag - end - end - end - end - end -end -- cgit v1.2.3 From be27bf17e309fcb43fab45cfa1d31cea074a6a72 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Oct 2011 16:24:00 -0500 Subject: Fix the proper production.rb --- .../rails/app/templates/config/environments/production.rb.tt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 64e2c09467..50f2df3d35 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -33,8 +33,11 @@ # See everything in the log (default is :info) # config.log_level = :debug + # Prepend all log lines with the following tags + # config.log_tags = [ :subdomain, :uuid ] + # Use a different logger for distributed setups - # config.logger = SyslogLogger.new + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production # config.cache_store = :mem_cache_store -- cgit v1.2.3 From 4e9729df3f03ee16445082b7d386ee14b4370461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 20 Oct 2011 00:38:20 +0200 Subject: Don't use :path in Gemfile for --dev except for Rails. --- railties/lib/rails/generators/app_base.rb | 2 +- railties/lib/rails/generators/rails/app/app_generator.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 134d86fab0..40961f0c3e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -138,7 +138,7 @@ module Rails if options.dev? <<-GEMFILE.strip_heredoc gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}' - gem 'journey', :path => '#{Rails::Generators::JOURNEY_DEV_PATH}' + gem 'journey', :git => 'git://github.com/rails/journey.git' GEMFILE elsif options.edge? <<-GEMFILE.strip_heredoc diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index c8648d19f8..3e32f758a4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -144,8 +144,6 @@ module Rails # We need to store the RAILS_DEV_PATH in a constant, otherwise the path # can change in Ruby 1.8.7 when we FileUtils.cd. RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__)) - JOURNEY_DEV_PATH = File.expand_path("../../../../../../../journey", File.dirname(__FILE__)) - RESERVED_NAMES = %w[application destroy benchmarker profiler plugin runner test] class AppGenerator < AppBase -- cgit v1.2.3 From bc5d334c7a340c29a4f9a594101832e1abe831a5 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 22 Oct 2011 19:16:43 +0530 Subject: Using middleware name to show proper name in the info --- railties/lib/rails/info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index a1e15092b2..2ba09d7b90 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -91,7 +91,7 @@ module Rails end property 'Middleware' do - Rails.configuration.middleware.map(&:inspect) + Rails.configuration.middleware.map(&:name) end # The application's location on the filesystem. -- cgit v1.2.3 From 259741ae7324c18782bf97f236230c496bccf948 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 22 Oct 2011 12:28:06 -0700 Subject: Revert "Merge pull request #3405 from arunagw/middleware_name" This reverts commit c33090523c3504a2a125d7f725a7f2a4b99ff3c0, reversing changes made to 1c1c3fc2c06fc02e67a8272adf2c2d2381e005b4. --- railties/lib/rails/info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index 2ba09d7b90..a1e15092b2 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -91,7 +91,7 @@ module Rails end property 'Middleware' do - Rails.configuration.middleware.map(&:name) + Rails.configuration.middleware.map(&:inspect) end # The application's location on the filesystem. -- cgit v1.2.3 From a458833705cd3e9a0909d0710da84e2009f097ba Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 22 Oct 2011 14:34:05 -0500 Subject: Remove Turn from default Gemfile. We still looking for a best presentation for tests output. --- railties/lib/rails/generators/app_base.rb | 11 ----------- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 -- 2 files changed, 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 40961f0c3e..10fdfdd8a9 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -190,17 +190,6 @@ module Rails end end - def turn_gemfile_entry - unless RUBY_VERSION < "1.9.2" || options[:skip_test_unit] - <<-GEMFILE.strip_heredoc - group :test do - # Pretty printed test output - gem 'turn', :require => false - end - GEMFILE - end - end - def assets_gemfile_entry <<-GEMFILE.strip_heredoc # Gems used only for assets and not required diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 910cd16950..d3b8f4d595 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -21,5 +21,3 @@ source 'http://rubygems.org' # To use debugger # <%= ruby_debugger_gemfile_entry %> - -<%= turn_gemfile_entry -%> -- cgit v1.2.3 From 98fbb50ebf531af28deb1312baf943c24990ad25 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Mon, 24 Oct 2011 22:38:10 +0400 Subject: Remove needless to_param in scaffold functional test --- .../generators/test_unit/scaffold/templates/functional_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb index 01fe6dda7a..9ec2e34545 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -26,23 +26,23 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase end test "should show <%= singular_table_name %>" do - get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %> + get :show, <%= key_value :id, "@#{singular_table_name}" %> assert_response :success end test "should get edit" do - get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %> + get :edit, <%= key_value :id, "@#{singular_table_name}" %> assert_response :success end test "should update <%= singular_table_name %>" do - put :update, <%= key_value :id, "@#{singular_table_name}.to_param" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %> + put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %> assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>)) end test "should destroy <%= singular_table_name %>" do assert_difference('<%= class_name %>.count', -1) do - delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %> + delete :destroy, <%= key_value :id, "@#{singular_table_name}" %> end assert_redirected_to <%= index_helper %>_path -- cgit v1.2.3 From aef62c4b4e89e7fa91973c188c9e7f281a44ecd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 26 Oct 2011 09:29:38 +0200 Subject: Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. --- .../generators/rails/scaffold_controller/templates/controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index 32b961d9fc..4ff15fd288 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -62,7 +62,7 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %> format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %> } - format.json { head :ok } + format.json { head :no_content } else format.html { render <%= key_value :action, '"edit"' %> } format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> } @@ -78,7 +78,7 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| format.html { redirect_to <%= index_helper %>_url } - format.json { head :ok } + format.json { head :no_content } end end end -- cgit v1.2.3 From 3fa8f362ad09a6f94ab012094014e31513ee36e0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 29 Oct 2011 15:45:04 +0530 Subject: method redefined warning removed! --- railties/lib/rails/test_unit/testing.rake | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index fa01f42c5b..3d87529ad4 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -61,6 +61,7 @@ end # Recreated here from Active Support because :uncommitted needs it before Rails is available module Kernel + remove_method :silence_stderr # Removing old method to prevent method redefined warning def silence_stderr old_stderr = STDERR.dup STDERR.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') -- cgit v1.2.3 From 010622bb989cb9fa3aac600a7fa7bcb894bb081a Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sat, 15 Oct 2011 17:20:54 +0800 Subject: On inpsect routes, show :controller and :action to indicate dynamic. --- railties/lib/rails/application/route_inspector.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8c6911e6bb..8252f21aa7 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -10,20 +10,21 @@ module Rails end routes = all_routes.collect do |route| + route_reqs = route.requirements - reqs = route.requirements.dup rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ - endpoint = rack_app ? rack_app.inspect : "#{reqs[:controller]}##{reqs[:action]}" - constraints = reqs.except(:controller, :action) + controller = route_reqs[:controller] || ':controller' + action = route_reqs[:action] || ':action' - reqs = endpoint == '#' ? '' : endpoint + endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}" + constraints = route_reqs.except(:controller, :action) - unless constraints.empty? - reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}" - end + reqs = endpoint + reqs += " #{constraints.inspect}" unless constraints.empty? verb = route.verb.source.gsub(/[$^]/, '') + {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs} end -- cgit v1.2.3 From eabda416b7c66f3b8d03237e7334bd2d14ff9190 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 29 Oct 2011 14:14:13 -0700 Subject: Removing db/seeds.rb is fine. Don't blow up. --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 2d25273050..1c9627734e 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -488,7 +488,7 @@ module Rails # Blog::Engine.load_seed def load_seed seed_file = paths["db/seeds"].existent.first - load(seed_file) if File.exist?(seed_file) + load(seed_file) if seed_file && File.exist?(seed_file) end # Add configured load paths to ruby load paths and remove duplicates. -- cgit v1.2.3 From 5745a5e85e1900c52d169f79ec0802060e110e21 Mon Sep 17 00:00:00 2001 From: Colin MacKenzie IV Date: Wed, 2 Nov 2011 09:00:18 -0400 Subject: treat USAGE as an ERB template --- railties/lib/rails/generators/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 911f80cf3a..f38a487a4e 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -34,7 +34,7 @@ module Rails usage = source_root && File.expand_path("../USAGE", source_root) @desc ||= if usage && File.exist?(usage) - File.read(usage) + ERB.new(File.read(usage)).result(binding) else "Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator." end -- cgit v1.2.3 From 7102a3d7fc55067b6cda1a7eeb3b3452050d9b6b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 4 Nov 2011 04:50:53 +0900 Subject: move Rails console top level methods to IRB context --- railties/lib/rails/console/app.rb | 48 +++++++++++++++++++---------------- railties/lib/rails/console/helpers.rb | 14 ++++++---- 2 files changed, 35 insertions(+), 27 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index 95c74baae2..cf081473a3 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -5,28 +5,32 @@ require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) -# reference the global "app" instance, created on demand. To recreate the -# instance, pass a non-false value as the parameter. -def app(create=false) - @app_integration_instance = nil if create - @app_integration_instance ||= new_session do |sess| - sess.host! "www.example.com" - end -end +module IRB + module ExtendCommandBundle + # reference the global "app" instance, created on demand. To recreate the + # instance, pass a non-false value as the parameter. + def app(create=false) + @app_integration_instance = nil if create + @app_integration_instance ||= new_session do |sess| + sess.host! "www.example.com" + end + end -# create a new session. If a block is given, the new session will be yielded -# to the block before being returned. -def new_session - app = Rails.application - session = ActionDispatch::Integration::Session.new(app) - yield session if block_given? - session -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 = Rails.application + session = ActionDispatch::Integration::Session.new(app) + yield session if block_given? + session + end -# reloads the environment -def reload!(print=true) - puts "Reloading..." if print - ActionDispatch::Reloader.cleanup! - ActionDispatch::Reloader.prepare! - true + # reloads the environment + def reload!(print=true) + puts "Reloading..." if print + ActionDispatch::Reloader.cleanup! + ActionDispatch::Reloader.prepare! + true + end + end end diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb index 212fc6125a..070d3c2bbf 100644 --- a/railties/lib/rails/console/helpers.rb +++ b/railties/lib/rails/console/helpers.rb @@ -1,7 +1,11 @@ -def helper - @helper ||= ApplicationController.helpers -end +module IRB + module ExtendCommandBundle + def helper + @helper ||= ApplicationController.helpers + end -def controller - @controller ||= ApplicationController.new + def controller + @controller ||= ApplicationController.new + end + end end -- cgit v1.2.3 From 44e751fdd4bcb60bba667ec641a4febbf1133e0f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 5 Nov 2011 19:26:23 -0500 Subject: Add arel to Gemfile on apps generated in edge Rails --- railties/lib/rails/generators/app_base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 10fdfdd8a9..0a79d6e86e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -139,11 +139,13 @@ module Rails <<-GEMFILE.strip_heredoc gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}' gem 'journey', :git => 'git://github.com/rails/journey.git' + gem 'arel', :git => 'git://github.com/rails/arel.git' GEMFILE elsif options.edge? <<-GEMFILE.strip_heredoc gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'journey', :git => 'git://github.com/rails/journey.git' + gem 'arel', :git => 'git://github.com/rails/arel.git' GEMFILE else <<-GEMFILE.strip_heredoc -- cgit v1.2.3 From 42cf5eba260f97e6da0ef66b954d95b9e7c2b102 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 7 Nov 2011 14:31:12 +0900 Subject: Remove redundant blank line at the bottom --- railties/lib/rails/generators/rails/controller/templates/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index 8f5f78556f..52243f4a2f 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -3,7 +3,7 @@ class <%= class_name %>Controller < ApplicationController <% actions.each do |action| -%> def <%= action %> end - +<%= "\n" unless action == actions.last -%> <% end -%> end <% end -%> -- cgit v1.2.3 From b53f77ec99ee179d66cca5efa9b68a659b161841 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Tue, 8 Nov 2011 12:56:51 +0530 Subject: CHANGELOG to CHANGELOG.md --- railties/lib/rails/tasks/documentation.rake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index ca8875ad9b..2072a2b947 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -66,31 +66,31 @@ namespace :doc do rdoc.rdoc_files.include('README') gem_path('actionmailer') do |actionmailer| - %w(README.rdoc CHANGELOG MIT-LICENSE lib/action_mailer/base.rb).each do |file| + %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_mailer/base.rb).each do |file| rdoc.rdoc_files.include("#{actionmailer}/#{file}") end end gem_path('actionpack') do |actionpack| - %w(README.rdoc CHANGELOG MIT-LICENSE lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file| + %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file| rdoc.rdoc_files.include("#{actionpack}/#{file}") end end gem_path('activemodel') do |activemodel| - %w(README.rdoc CHANGELOG MIT-LICENSE lib/active_model/**/*.rb).each do |file| + %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/active_model/**/*.rb).each do |file| rdoc.rdoc_files.include("#{activemodel}/#{file}") end end gem_path('activerecord') do |activerecord| - %w(README.rdoc CHANGELOG lib/active_record/**/*.rb).each do |file| + %w(README.rdoc CHANGELOG.md lib/active_record/**/*.rb).each do |file| rdoc.rdoc_files.include("#{activerecord}/#{file}") end end gem_path('activeresource') do |activeresource| - %w(README.rdoc CHANGELOG lib/active_resource.rb lib/active_resource/*).each do |file| + %w(README.rdoc CHANGELOG.md lib/active_resource.rb lib/active_resource/*).each do |file| rdoc.rdoc_files.include("#{activeresource}/#{file}") end end -- cgit v1.2.3 From fe67501e62429a8d9c666837740cf9c1de1d4f87 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Tue, 8 Nov 2011 14:10:44 +0530 Subject: Should be checking if file exists or not. I found this bug when running rake test:uncommitted on a newly generated rails app which don't have test file for application_controller. Can see detail here #3461 --- railties/lib/rails/test_unit/testing.rake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 3d87529ad4..8bcceb9b2c 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -121,10 +121,16 @@ namespace :test do models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ } controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ } - unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } - functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } + unit_tests = models.map do |model| + file = "test/unit/#{File.basename(model, '.rb')}_test.rb" + file if File.exist?(file) + end + functional_tests = controllers.map do |controller| + file = "test/functional/#{File.basename(controller, '.rb')}_test.rb" + file if File.exist?(file) + end - unit_tests.uniq + functional_tests.uniq + (unit_tests.uniq + functional_tests.uniq).compact end t.libs << 'test' -- cgit v1.2.3 From 5f826ea26f048df941325427c841608ced86f7a1 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 9 Nov 2011 09:46:06 +0530 Subject: Refactor test:uncommitted task. Thanks to @sobrinho (Gabriel Sobrinho) --- railties/lib/rails/test_unit/testing.rake | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 8bcceb9b2c..52d92cdd96 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -121,16 +121,9 @@ namespace :test do models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ } controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ } - unit_tests = models.map do |model| - file = "test/unit/#{File.basename(model, '.rb')}_test.rb" - file if File.exist?(file) - end - functional_tests = controllers.map do |controller| - file = "test/functional/#{File.basename(controller, '.rb')}_test.rb" - file if File.exist?(file) - end - - (unit_tests.uniq + functional_tests.uniq).compact + unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } + functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } + (unit_tests + functional_tests).uniq.select { |file| File.exist?(file) } end t.libs << 'test' -- cgit v1.2.3 From f642724f27af5b16290f56795563eaa194e20301 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 9 Nov 2011 09:59:17 +0530 Subject: CHANGELOG => CHANGELOG.md I missed these in previous commit --- railties/lib/rails/tasks/documentation.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 2072a2b947..1e7da5ccae 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -96,13 +96,13 @@ namespace :doc do end gem_path('activesupport') do |activesupport| - %w(README.rdoc CHANGELOG lib/active_support/**/*.rb).each do |file| + %w(README.rdoc CHANGELOG.md lib/active_support/**/*.rb).each do |file| rdoc.rdoc_files.include("#{activesupport}/#{file}") end end gem_path('railties') do |railties| - %w(README.rdoc CHANGELOG lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file| + %w(README.rdoc CHANGELOG.md lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file| rdoc.rdoc_files.include("#{railties}/#{file}") end end -- cgit v1.2.3 From 6d09f275c6e3224a8ea9a738512c90ee5334e20d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 9 Nov 2011 15:42:19 +0900 Subject: Modulize Rails console methods so that other console libraries such as Pry can include these methods --- railties/lib/rails/application.rb | 2 ++ railties/lib/rails/console/app.rb | 4 ++-- railties/lib/rails/console/helpers.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 82fffe86bb..e8b160448b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -205,6 +205,8 @@ module Rails require "pp" require "rails/console/app" require "rails/console/helpers" + + IRB::ExtendCommandBundle.send :include, Rails::ConsoleMethods end end end diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index cf081473a3..23d57379ba 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -5,8 +5,8 @@ require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) -module IRB - module ExtendCommandBundle +module Rails + module ConsoleMethods # reference the global "app" instance, created on demand. To recreate the # instance, pass a non-false value as the parameter. def app(create=false) diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb index 070d3c2bbf..230d3d9d04 100644 --- a/railties/lib/rails/console/helpers.rb +++ b/railties/lib/rails/console/helpers.rb @@ -1,5 +1,5 @@ -module IRB - module ExtendCommandBundle +module Rails + module ConsoleMethods def helper @helper ||= ApplicationController.helpers end -- cgit v1.2.3 From a658fd2ffa2fd2019696ddd10b12aa5490b1668e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 10 Nov 2011 06:47:35 +0900 Subject: Extend IRB right before starting IRB to remove dependency on IRB from Rails::Application --- railties/lib/rails/application.rb | 2 -- railties/lib/rails/commands/console.rb | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index e8b160448b..82fffe86bb 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -205,8 +205,6 @@ module Rails require "pp" require "rails/console/app" require "rails/console/helpers" - - IRB::ExtendCommandBundle.send :include, Rails::ConsoleMethods end end end diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 32e361d421..7733a8f116 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -42,6 +42,8 @@ module Rails else puts "Loading #{Rails.env} environment (Rails #{Rails.version})" end + + IRB::ExtendCommandBundle.send :include, Rails::ConsoleMethods IRB.start end end -- cgit v1.2.3 From 49349089ad38b403bf3f395ebf8fbc44cd232b49 Mon Sep 17 00:00:00 2001 From: Tyler Coville Date: Wed, 9 Nov 2011 23:22:26 -0800 Subject: Fixed error with 'rails generate new plugin' where the .gitignore was not properly generated if --dummy-path was used and added test case --- .../lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 2 +- railties/lib/rails/generators/rails/plugin_new/templates/gitignore | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 4baa2110e7..f5c8ccf940 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -39,7 +39,7 @@ module Rails end def gitignore - copy_file "gitignore", ".gitignore" + template "gitignore", ".gitignore" end def lib diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore index 1463de6dfb..92bd3c614b 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore +++ b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore @@ -1,6 +1,6 @@ .bundle/ log/*.log pkg/ -test/dummy/db/*.sqlite3 -test/dummy/log/*.log -test/dummy/tmp/ \ No newline at end of file +<%= dummy_path %>/db/*.sqlite3 +<%= dummy_path %>/log/*.log +<%= dummy_path %>/tmp/ \ No newline at end of file -- cgit v1.2.3 From 9ce5d5155bc394fbd076203b14fbd8d83d10caf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Thu, 10 Nov 2011 18:52:39 +0100 Subject: fixed example code indentation --- railties/lib/rails/engine.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 1c9627734e..d652c6b7fe 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -296,16 +296,16 @@ module Rails # If you want to share just a few specific helpers you can add them to application's # helpers in ApplicationController: # - # class ApplicationController < ActionController::Base - # helper MyEngine::SharedEngineHelper - # end + # class ApplicationController < ActionController::Base + # helper MyEngine::SharedEngineHelper + # end # # If you want to include all of the engine's helpers, you can use #helpers method on an engine's # instance: # - # class ApplicationController < ActionController::Base - # helper MyEngine::Engine.helpers - # end + # class ApplicationController < ActionController::Base + # helper MyEngine::Engine.helpers + # end # # It will include all of the helpers from engine's directory. Take into account that this does # not include helpers defined in controllers with helper_method or other similar solutions, -- cgit v1.2.3 From 49cd6a0ff7a3f5b0e85707961c952bdc3b0a178f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 14 Nov 2011 07:07:38 -0500 Subject: Added therubyrhino to default Gemfile under JRuby --- railties/lib/rails/generators/app_base.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 0a79d6e86e..3fbde0d989 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -199,6 +199,7 @@ module Rails group :assets do gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' + #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} gem 'uglifier', '>= 1.0.3' end GEMFILE -- cgit v1.2.3 From 21c5a0a104bf04e3e7b63aa5f0104f1c666655c3 Mon Sep 17 00:00:00 2001 From: Daniel Dyba Date: Sat, 16 Jul 2011 16:54:03 -0700 Subject: Changed Commands module to RailsCommands. This is to avoid a conflict that occurs when you add Rake to your Gemfile. There is a Commands Object in Rake that conflicts with the Commands module in plugin.rb. See rails issue #1866. --- railties/lib/rails/commands/plugin.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 4df849447d..aa4551c806 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -274,7 +274,7 @@ end # load default environment and parse arguments require 'optparse' -module Commands +module RailsCommands class Plugin attr_reader :environment, :script_name def initialize @@ -327,7 +327,7 @@ module Commands command = general.shift if command =~ /^(install|remove)$/ - command = Commands.const_get(command.capitalize).new(self) + command = RailsCommands.const_get(command.capitalize).new(self) command.parse!(sub) else puts "Unknown command: #{command}" unless command.blank? @@ -539,4 +539,4 @@ class RecursiveHTTPFetcher end end -Commands::Plugin.parse! +RailsCommands::Plugin.parse! -- cgit v1.2.3 From 325abe9fbad58b6a0e119a678039b195247a57bc Mon Sep 17 00:00:00 2001 From: Daniel Dyba Date: Sun, 17 Jul 2011 23:09:51 -0700 Subject: Substituted RailsCommands for Rails::Commands --- railties/lib/rails/commands/plugin.rb | 320 +++++++++++++++++----------------- 1 file changed, 161 insertions(+), 159 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index aa4551c806..c99a2e6685 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -274,198 +274,200 @@ end # load default environment and parse arguments require 'optparse' -module RailsCommands - class Plugin - attr_reader :environment, :script_name - def initialize - @environment = RailsEnvironment.default - @rails_root = RailsEnvironment.default.root - @script_name = File.basename($0) - end +module Rails + module Commands + class Plugin + attr_reader :environment, :script_name + def initialize + @environment = RailsEnvironment.default + @rails_root = RailsEnvironment.default.root + @script_name = File.basename($0) + end - def environment=(value) - @environment = value - RailsEnvironment.default = value - end + def environment=(value) + @environment = value + RailsEnvironment.default = value + end - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: plugin [OPTIONS] command" - o.define_head "Rails plugin manager." + def options + OptionParser.new do |o| + o.set_summary_indent(' ') + o.banner = "Usage: plugin [OPTIONS] command" + o.define_head "Rails plugin manager." - o.separator "" - o.separator "GENERAL OPTIONS" + o.separator "" + o.separator "GENERAL OPTIONS" - o.on("-r", "--root=DIR", String, - "Set an explicit rails app directory.", - "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) } + o.on("-r", "--root=DIR", String, + "Set an explicit rails app directory.", + "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) } - o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose } - o.on("-h", "--help", "Show this help message.") { puts o; exit } + o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose } + o.on("-h", "--help", "Show this help message.") { puts o; exit } - o.separator "" - o.separator "COMMANDS" + o.separator "" + o.separator "COMMANDS" - o.separator " install Install plugin(s) from known repositories or URLs." - o.separator " remove Uninstall plugins." + o.separator " install Install plugin(s) from known repositories or URLs." + o.separator " remove Uninstall plugins." - o.separator "" - o.separator "EXAMPLES" - o.separator " Install a plugin from a subversion URL:" - o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n" - o.separator " Install a plugin from a git URL:" - o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n" - o.separator " Install a plugin and add a svn:externals entry to vendor/plugins" - o.separator " #{@script_name} plugin install -x my_svn_plugin\n" + o.separator "" + o.separator "EXAMPLES" + o.separator " Install a plugin from a subversion URL:" + o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n" + o.separator " Install a plugin from a git URL:" + o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n" + o.separator " Install a plugin and add a svn:externals entry to vendor/plugins" + o.separator " #{@script_name} plugin install -x my_svn_plugin\n" + end end - end - def parse!(args=ARGV) - general, sub = split_args(args) - options.parse!(general) + def parse!(args=ARGV) + general, sub = split_args(args) + options.parse!(general) - command = general.shift - if command =~ /^(install|remove)$/ - command = RailsCommands.const_get(command.capitalize).new(self) - command.parse!(sub) - else - puts "Unknown command: #{command}" unless command.blank? - puts options - exit 1 + command = general.shift + if command =~ /^(install|remove)$/ + command = Commands.const_get(command.capitalize).new(self) + command.parse!(sub) + else + puts "Unknown command: #{command}" unless command.blank? + puts options + exit 1 + end end - end - def split_args(args) - left = [] - left << args.shift while args[0] and args[0] =~ /^-/ - left << args.shift if args[0] - [left, args] - end - - def self.parse!(args=ARGV) - Plugin.new.parse!(args) - end - end + def split_args(args) + left = [] + left << args.shift while args[0] and args[0] =~ /^-/ + left << args.shift if args[0] + [left, args] + end - class Install - def initialize(base_command) - @base_command = base_command - @method = :http - @options = { :quiet => false, :revision => nil, :force => false } + def self.parse!(args=ARGV) + Plugin.new.parse!(args) + end end - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]" - o.define_head "Install one or more plugins." - o.separator "" - o.separator "Options:" - o.on( "-x", "--externals", - "Use svn:externals to grab the plugin.", - "Enables plugin updates and plugin versioning.") { |v| @method = :externals } - o.on( "-o", "--checkout", - "Use svn checkout to grab the plugin.", - "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout } - o.on( "-e", "--export", - "Use svn export to grab the plugin.", - "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export } - o.on( "-q", "--quiet", - "Suppresses the output from installation.", - "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true } - o.on( "-r REVISION", "--revision REVISION", - "Checks out the given revision from subversion or git.", - "Ignored if subversion/git is not used.") { |v| @options[:revision] = v } - o.on( "-f", "--force", - "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true } - o.separator "" - o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to " - o.separator "a plugin repository." + class Install + def initialize(base_command) + @base_command = base_command + @method = :http + @options = { :quiet => false, :revision => nil, :force => false } end - end - def determine_install_method - best = @base_command.environment.best_install_method - @method = :http if best == :http and @method == :export - case - when (best == :http and @method != :http) - msg = "Cannot install using subversion because `svn' cannot be found in your PATH" - when (best == :export and (@method != :export and @method != :http)) - msg = "Cannot install using #{@method} because this project is not under subversion." - when (best != :externals and @method == :externals) - msg = "Cannot install using externals because vendor/plugins is not under subversion." + def options + OptionParser.new do |o| + o.set_summary_indent(' ') + o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]" + o.define_head "Install one or more plugins." + o.separator "" + o.separator "Options:" + o.on( "-x", "--externals", + "Use svn:externals to grab the plugin.", + "Enables plugin updates and plugin versioning.") { |v| @method = :externals } + o.on( "-o", "--checkout", + "Use svn checkout to grab the plugin.", + "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout } + o.on( "-e", "--export", + "Use svn export to grab the plugin.", + "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export } + o.on( "-q", "--quiet", + "Suppresses the output from installation.", + "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true } + o.on( "-r REVISION", "--revision REVISION", + "Checks out the given revision from subversion or git.", + "Ignored if subversion/git is not used.") { |v| @options[:revision] = v } + o.on( "-f", "--force", + "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true } + o.separator "" + o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to " + o.separator "a plugin repository." + end end - if msg - puts msg - exit 1 + + def determine_install_method + best = @base_command.environment.best_install_method + @method = :http if best == :http and @method == :export + case + when (best == :http and @method != :http) + msg = "Cannot install using subversion because `svn' cannot be found in your PATH" + when (best == :export and (@method != :export and @method != :http)) + msg = "Cannot install using #{@method} because this project is not under subversion." + when (best != :externals and @method == :externals) + msg = "Cannot install using externals because vendor/plugins is not under subversion." + end + if msg + puts msg + exit 1 + end + @method end - @method - end - def parse!(args) - options.parse!(args) - if args.blank? - puts options + def parse!(args) + options.parse!(args) + if args.blank? + puts options + exit 1 + end + environment = @base_command.environment + install_method = determine_install_method + puts "Plugins will be installed using #{install_method}" if $verbose + args.each do |name| + ::Plugin.find(name).install(install_method, @options) + end + rescue StandardError => e + puts "Plugin not found: #{args.inspect}" + puts e.inspect if $verbose exit 1 end - environment = @base_command.environment - install_method = determine_install_method - puts "Plugins will be installed using #{install_method}" if $verbose - args.each do |name| - ::Plugin.find(name).install(install_method, @options) - end - rescue StandardError => e - puts "Plugin not found: #{args.inspect}" - puts e.inspect if $verbose - exit 1 - end - end - - class Remove - def initialize(base_command) - @base_command = base_command end - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} remove name [name]..." - o.define_head "Remove plugins." + class Remove + def initialize(base_command) + @base_command = base_command end - end - def parse!(args) - options.parse!(args) - if args.blank? - puts options - exit 1 + def options + OptionParser.new do |o| + o.set_summary_indent(' ') + o.banner = "Usage: #{@base_command.script_name} remove name [name]..." + o.define_head "Remove plugins." + end end - root = @base_command.environment.root - args.each do |name| - ::Plugin.new(name).uninstall + + def parse!(args) + options.parse!(args) + if args.blank? + puts options + exit 1 + end + root = @base_command.environment.root + args.each do |name| + ::Plugin.new(name).uninstall + end end end - end - class Info - def initialize(base_command) - @base_command = base_command - end + class Info + def initialize(base_command) + @base_command = base_command + end - def options - OptionParser.new do |o| - o.set_summary_indent(' ') - o.banner = "Usage: #{@base_command.script_name} info name [name]..." - o.define_head "Shows plugin info at {url}/about.yml." + def options + OptionParser.new do |o| + o.set_summary_indent(' ') + o.banner = "Usage: #{@base_command.script_name} info name [name]..." + o.define_head "Shows plugin info at {url}/about.yml." + end end - end - def parse!(args) - options.parse!(args) - args.each do |name| - puts ::Plugin.find(name).info - puts + def parse!(args) + options.parse!(args) + args.each do |name| + puts ::Plugin.find(name).info + puts + end end end end @@ -539,4 +541,4 @@ class RecursiveHTTPFetcher end end -RailsCommands::Plugin.parse! +Rails::Commands::Plugin.parse! -- cgit v1.2.3 From 0af93089deaf6dc9428c0f2f7a376cdb6f81daee Mon Sep 17 00:00:00 2001 From: Alex Tambellini Date: Thu, 17 Nov 2011 09:44:17 -0500 Subject: Move schema_format :sql config setting from test.rb to application.rb I've moved the schema_format :sql config setting to application.rb because you would never enable this only for the test environment. If you use database constraints or database specific data types you would want all of your environments to use them. --- .../lib/rails/generators/rails/app/templates/config/application.rb | 5 +++++ .../generators/rails/app/templates/config/environments/test.rb.tt | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 13fbe9e526..40fd843b1b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -49,6 +49,11 @@ module <%= app_const_base %> # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] + # Use SQL instead of Active Record's schema dumper when creating the database. + # 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 + <% unless options.skip_sprockets? -%> # Enable the asset pipeline config.assets.enabled = true diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 80198cc21e..37a8b81dad 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -29,11 +29,6 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Use SQL instead of Active Record's schema dumper when creating the test database. - # 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 - <%- unless options.skip_active_record? -%> # Raise exception on mass assignment protection for ActiveRecord models config.active_record.mass_assignment_sanitizer = :strict -- cgit v1.2.3 From 39d2251d8a3e50bf004b6361e0079679466b2280 Mon Sep 17 00:00:00 2001 From: lest Date: Sat, 19 Nov 2011 19:03:44 +0200 Subject: fix rails plugin new CamelCasedName bug refs #3684 --- .../rails/plugin_new/plugin_new_generator.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index f5c8ccf940..ff523fc26f 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -246,8 +246,20 @@ task :default => :test "rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]" end + def original_name + @original_name ||= File.basename(destination_root) + end + def name - @name ||= File.basename(destination_root) + unless @name + # same as ActiveSupport::Inflector#underscore except not replacing '-' + @name = original_name.dup + @name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + @name.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + @name.downcase! + end + + @name end def camelized @@ -256,11 +268,11 @@ task :default => :test def valid_const? if camelized =~ /^\d/ - raise Error, "Invalid plugin name #{name}. Please give a name which does not start with numbers." + raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers." elsif RESERVED_NAMES.include?(name) - raise Error, "Invalid plugin name #{name}. Please give a name which does not match one of the reserved rails words." + raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words." elsif Object.const_defined?(camelized) - raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another plugin name." + raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name." end end -- cgit v1.2.3 From c220b4d833fcefb4f60fd021875c05e07dfff77d Mon Sep 17 00:00:00 2001 From: lest Date: Sat, 19 Nov 2011 21:51:37 +0300 Subject: fix warning about instance variable in plugin generator --- .../generators/rails/plugin_new/plugin_new_generator.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index ff523fc26f..cd7d51e628 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -251,15 +251,15 @@ task :default => :test end def name - unless @name + @name ||= begin # same as ActiveSupport::Inflector#underscore except not replacing '-' - @name = original_name.dup - @name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') - @name.gsub!(/([a-z\d])([A-Z])/,'\1_\2') - @name.downcase! - end + underscored = original_name.dup + underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + underscored.downcase! - @name + underscored + end end def camelized -- cgit v1.2.3 From 4c872c017b47120b95eb2acf1d3401bd937b0647 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 22 Nov 2011 00:05:46 +0530 Subject: Remove the -h option to dbconsole which is the shorter form of --header This is done since the -h option to dbconsole hides the conventional -h for help and forces users to use --help to see the usage options for dbconsole. --- railties/lib/rails/commands/dbconsole.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index b0ba76217a..4b0acc9d88 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -33,7 +33,7 @@ module Rails options['mode'] = mode end - opt.on("-h", "--header") do |h| + opt.on("--header") do |h| options['header'] = h end -- cgit v1.2.3 From a9e8cf78fda696738f63e726796f6232c3751603 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 21 Nov 2011 20:13:54 +0300 Subject: add ActionController::Metal#show_detailed_exceptions? --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 82fffe86bb..817fa39cab 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -166,7 +166,7 @@ module Rails middleware.use ::Rack::MethodOverride middleware.use ::ActionDispatch::RequestId middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods - middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local + middleware.use ::ActionDispatch::ShowExceptions middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies if config.action_dispatch.x_sendfile_header.present? middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header -- cgit v1.2.3 From 05e02deb686fc21f99c2d1dcf3abc987796e0e19 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 22 Nov 2011 15:16:23 -0500 Subject: Make explicit the default media when calling stylesheet_tag and change the default generators. --- .../rails/app/templates/app/views/layouts/application.html.erb.tt | 2 +- .../templates/app/views/layouts/%name%/application.html.erb.tt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt index c63d1b6ac5..bba96a7431 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt @@ -2,7 +2,7 @@ <%= camelized %> - <%%= stylesheet_link_tag "application" %> + <%%= stylesheet_link_tag "application", :media => "all" %> <%%= javascript_include_tag "application" %> <%%= csrf_meta_tags %> diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt index 01550dec2f..bd983fb90f 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +++ b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt @@ -2,7 +2,7 @@ <%= camelized %> - <%%= stylesheet_link_tag "<%= name %>/application" %> + <%%= stylesheet_link_tag "<%= name %>/application", :media => "all" %> <%%= javascript_include_tag "<%= name %>/application" %> <%%= csrf_meta_tags %> -- cgit v1.2.3 From d78a7026fcd5eb0cd91e3da2a125ddfcf53e7a7a Mon Sep 17 00:00:00 2001 From: Sergey Parizhskiy Date: Wed, 23 Nov 2011 14:10:30 +0200 Subject: improved code stats calculation, check on multiline comments and rewrite regexps according to a class naming convention --- railties/lib/rails/code_statistics.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index e6822b75b7..435ea83ad8 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -38,11 +38,22 @@ class CodeStatistics #:nodoc: next unless file_name =~ pattern f = File.open(directory + "/" + file_name) - + comment_started = false while line = f.gets stats["lines"] += 1 - stats["classes"] += 1 if line =~ /class [A-Z]/ - stats["methods"] += 1 if line =~ /def [a-z]/ + if(comment_started) + if line =~ /^=end/ + comment_started = false + end + next + else + if line =~ /^=begin/ + comment_started = true + next + end + end + stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/ + stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/ stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/ end end -- cgit v1.2.3 From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 19:06:45 +0000 Subject: Rely on a public contract between railties instead of accessing railtie methods directly. --- railties/lib/rails/application.rb | 4 ++++ railties/lib/rails/engine.rb | 43 +++++++++++++++++++++++---------------- railties/lib/rails/railtie.rb | 2 +- 3 files changed, 31 insertions(+), 18 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 817fa39cab..0b72a7ed84 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -141,6 +141,10 @@ module Rails self end + def helpers_paths + config.helpers_paths + end + protected alias :build_middleware_stack :app diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index d652c6b7fe..335a0fb1b5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -371,20 +371,28 @@ module Rails self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) } self.isolated = true - unless mod.respond_to?(:_railtie) - name = engine_name - _railtie = self + unless mod.respond_to?(:railtie_namespace) + name, railtie = engine_name, self + mod.singleton_class.instance_eval do - define_method(:_railtie) do - _railtie - end + define_method(:railtie_namespace) { railtie } unless mod.respond_to?(:table_name_prefix) - define_method(:table_name_prefix) do - "#{name}_" - end + define_method(:table_name_prefix) { "#{name}_" } + end + + unless mod.respond_to?(:use_relative_model_naming?) + class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__ + end + + unless mod.respond_to?(:railtie_helpers_paths) + define_method(:railtie_helpers_paths) { railtie.helpers_paths } + end + + unless mod.respond_to?(:railtie_routes_url_helpers) + define_method(:railtie_routes_url_helpers) { railtie.routes_url_helpers } end - end + end end end @@ -429,13 +437,6 @@ module Rails def helpers @helpers ||= begin helpers = Module.new - - helpers_paths = if config.respond_to?(:helpers_paths) - config.helpers_paths - else - paths["app/helpers"].existent - end - all = ActionController::Base.all_helpers_from_path(helpers_paths) ActionController::Base.modules_for_helpers(all).each do |mod| helpers.send(:include, mod) @@ -444,6 +445,14 @@ module Rails end end + def helpers_paths + paths["app/helpers"].existent + end + + def routes_url_helpers + routes.url_helpers + end + def app @app ||= begin config.middleware = config.middleware.merge_into(default_middleware_stack) diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index e8fb1f3d98..f0991b99af 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -196,7 +196,7 @@ module Rails end def railtie_namespace - @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:_railtie) } + @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) } end end end -- cgit v1.2.3 From 40b19e063592fc30705f17aafe6a458e7b622ff2 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 22 Nov 2011 23:26:27 +0100 Subject: Allow to change engine's loading priority with config.railties_order= --- railties/lib/rails/application.rb | 22 ++++++++++++++++++++++ railties/lib/rails/application/configuration.rb | 5 +++-- railties/lib/rails/engine.rb | 24 ++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0b72a7ed84..847445d29f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -127,6 +127,28 @@ module Rails }) end + def ordered_railties + @ordered_railties ||= begin + order = config.railties_order.map do |railtie| + if railtie == :main_app + self + elsif railtie.respond_to?(:instance) + railtie.instance + else + railtie + end + end + + all = (railties.all - order) + all.push(self) unless all.include?(self) + order.push(:all) unless order.include?(:all) + + index = order.index(:all) + order[index] = all + order.reverse.flatten + end + end + def initializers Bootstrap.initializers_for(self) + super + diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8f5b28faf8..e95b0f5495 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -10,8 +10,8 @@ module Rails :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, - :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils + :ssl_options, :static_cache_control, :session_options, + :time_zone, :whiny_nils, :railties_order attr_writer :log_level attr_reader :encoding @@ -35,6 +35,7 @@ module Rails @middleware = app_middleware @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 335a0fb1b5..5c1af99fe2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -330,6 +330,17 @@ module Rails # # MyEngine::Engine.load_seed # + # == Loading priority + # + # In order to change engine's priority you can use config.railties_order in main application. + # It will affect the priority of loading views, helpers, assets and all the other files + # related to engine or application. + # + # Example: + # + # # load Blog::Engine with highest priority, followed by application and other railties + # config.railties_order = [Blog::Engine, :main_app, :all] + # class Engine < Railtie autoload :Configuration, "rails/engine/configuration" autoload :Railties, "rails/engine/railties" @@ -480,10 +491,19 @@ module Rails @routes end + def ordered_railties + railties.all + [self] + end + def initializers initializers = [] - railties.all { |r| initializers += r.initializers } - initializers += super + ordered_railties.each do |r| + if r == self + initializers += super + else + initializers += r.initializers + end + end initializers end -- cgit v1.2.3 From 0cd3bf84068dd2b2d0bbb26062f2cdc7093a1b04 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 24 Nov 2011 01:45:50 +0100 Subject: Allow to display engine's routes when running `rake routes ENGINES=true` --- railties/lib/rails/application/route_inspector.rb | 37 +++++++++++++++++++++-- railties/lib/rails/tasks/routes.rake | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8252f21aa7..8da7de2584 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -4,12 +4,23 @@ module Rails # This class is just used for displaying route information when someone # executes `rake routes`. People should not use this class. class RouteInspector # :nodoc: + def initialize + @engines = ActiveSupport::OrderedHash.new + end + def format all_routes, filter = nil if filter all_routes = all_routes.select{ |route| route.defaults[:controller] == filter } end - routes = all_routes.collect do |route| + routes = collect_routes(all_routes) + + formatted_routes(routes) + + formatted_routes_for_engines + end + + def collect_routes(routes) + routes = routes.collect do |route| route_reqs = route.requirements rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ @@ -25,12 +36,32 @@ module Rails verb = route.verb.source.gsub(/[$^]/, '') - {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs} + collect_engine_routes(reqs, rack_app) + + {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs } end # Skip the route if it's internal info route - routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } + routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } + end + + def collect_engine_routes(name, rack_app) + return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes) + return if @engines[name] + + routes = rack_app.routes + if routes.is_a?(ActionDispatch::Routing::RouteSet) + @engines[name] = collect_routes(routes.routes) + end + end + + def formatted_routes_for_engines + @engines.map do |name, routes| + ["\nRoutes for #{name}:"] + formatted_routes(routes) + end.flatten + end + def formatted_routes(routes) name_width = routes.map{ |r| r[:name].length }.max verb_width = routes.map{ |r| r[:verb].length }.max path_width = routes.map{ |r| r[:path].length }.max diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 7dc54144da..df72baef67 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,4 +1,4 @@ -desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' +desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x. Include engine\'s routes with ENGINES=true' task :routes => :environment do Rails.application.reload_routes! all_routes = Rails.application.routes.routes -- cgit v1.2.3 From ebb8ea22f30dc029f4a868a550828443b160f639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:13:19 +0000 Subject: Add generators for serializers. --- .../lib/rails/generators/rails/serializer/USAGE | 9 +++++ .../rails/serializer/serializer_generator.rb | 39 ++++++++++++++++++++++ .../rails/serializer/templates/serializer.rb | 9 +++++ .../test_unit/serializer/serializer_generator.rb | 13 ++++++++ .../test_unit/serializer/templates/unit_test.rb | 9 +++++ 5 files changed, 79 insertions(+) create mode 100644 railties/lib/rails/generators/rails/serializer/USAGE create mode 100644 railties/lib/rails/generators/rails/serializer/serializer_generator.rb create mode 100644 railties/lib/rails/generators/rails/serializer/templates/serializer.rb create mode 100644 railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/serializer/USAGE b/railties/lib/rails/generators/rails/serializer/USAGE new file mode 100644 index 0000000000..a49f7ea1fb --- /dev/null +++ b/railties/lib/rails/generators/rails/serializer/USAGE @@ -0,0 +1,9 @@ +Description: + Generates a serializer for the given resource with tests. + +Example: + `rails generate serializer Account name created_at` + + For TestUnit it creates: + Serializer: app/serializers/account_serializer.rb + TestUnit: test/unit/account_serializer_test.rb diff --git a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb new file mode 100644 index 0000000000..2118906227 --- /dev/null +++ b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb @@ -0,0 +1,39 @@ +module Rails + module Generators + class SerializerGenerator < NamedBase + check_class_collision :suffix => "Serializer" + + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + + class_option :parent, :type => :string, :desc => "The parent class for the generated serializer" + + def create_serializer_file + template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb") + end + + hook_for :test_framework + + private + + def attributes_names + attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym } + end + + def association_names + attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym } + end + + def parent_class_name + if options[:parent] + options[:parent] + elsif (n = Rails::Generators.namespace) && n.const_defined?(:ApplicationSerializer) + "ApplicationSerializer" + elsif Object.const_defined?(:ApplicationSerializer) + "ApplicationSerializer" + else + "ActiveModel::Serializer" + end + end + end + end +end diff --git a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb new file mode 100644 index 0000000000..30c058c7e9 --- /dev/null +++ b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb @@ -0,0 +1,9 @@ +<% module_namespacing do -%> +class <%= class_name %>Serializer < <%= parent_class_name %> +<% if attributes.any? -%> attributes <%= attributes_names.map(&:inspect).join(", ") %> +<% end -%> +<% association_names.each do |attribute| -%> + has_one :<%= attribute %> +<% end -%> +end +<% end -%> \ No newline at end of file diff --git a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb new file mode 100644 index 0000000000..533c032c3b --- /dev/null +++ b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class SerializerGenerator < Base + check_class_collision :suffix => "SerializerTest" + + def create_test_files + template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_serializer_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb new file mode 100644 index 0000000000..0b1bbdcaa5 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +<% module_namespacing do -%> +class <%= class_name %>SerializerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end +<% end -%> -- cgit v1.2.3 From 6d9f9b3b05f6ea55aad9853888912bcca4d81c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:17:32 +0000 Subject: Add a hook for serializers in the scaffold generator (off for now). --- railties/lib/rails/generators.rb | 4 +++- railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 27f8d13ce8..f1ca9080ff 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -33,7 +33,8 @@ module Rails :stylesheets => '-y', :stylesheet_engine => '-se', :template_engine => '-e', - :test_framework => '-t' + :test_framework => '-t', + :serializer => '-z' }, :test_unit => { @@ -58,6 +59,7 @@ module Rails :performance_tool => nil, :resource_controller => :controller, :scaffold_controller => :scaffold_controller, + :serializer => false, :stylesheets => true, :stylesheet_engine => :css, :test_framework => false, diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 03a61a035e..7353a67c83 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -10,6 +10,7 @@ module Rails class_option :stylesheet_engine, :desc => "Engine for Stylesheets" hook_for :scaffold_controller, :required => true + hook_for :serializer hook_for :assets do |assets| invoke assets, [controller_name] -- cgit v1.2.3 From c8d7291b6b5736562b112007365317648ae2b790 Mon Sep 17 00:00:00 2001 From: ganesh Date: Fri, 25 Nov 2011 14:55:28 +0530 Subject: Added tests for #3751 --- railties/lib/rails/generators/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index b26839644e..184cb2866b 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -68,7 +68,7 @@ module Rails end in_root do - str = "gem #{parts.join(", ")}\n" + str = "\ngem #{parts.join(", ")}\n" str = " " + str if @in_group append_file "Gemfile", str, :verbose => false end -- cgit v1.2.3 From cd9d28d6fdff6819dac3c6643fe882eb568b5a39 Mon Sep 17 00:00:00 2001 From: lest Date: Thu, 24 Nov 2011 22:37:48 +0300 Subject: middlewares should use logger from env --- railties/lib/rails/application.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 847445d29f..25ff74506a 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -123,7 +123,8 @@ module Rails @env_config ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.secret_token" => config.secret_token, - "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions + "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions, + "action_dispatch.logger" => Rails.logger }) end -- cgit v1.2.3 From c9bb099318dd3bc293a6cb4672333147c1cce4b9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Nov 2011 12:42:11 +0100 Subject: Display mounted engines in `rake routes` by default --- railties/lib/rails/application/route_inspector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 8da7de2584..26652a8e5e 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -46,7 +46,7 @@ module Rails end def collect_engine_routes(name, rack_app) - return unless rack_app && ENV["ENGINES"] && rack_app.respond_to?(:routes) + return unless rack_app && rack_app.respond_to?(:routes) return if @engines[name] routes = rack_app.routes -- cgit v1.2.3 From 8ff8fa5e5fd9a615f2c63f809a2747a55cd4da15 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Nov 2011 12:54:39 +0100 Subject: I suck, forgot to also change rake's task description --- railties/lib/rails/tasks/routes.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index df72baef67..7dc54144da 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,4 +1,4 @@ -desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x. Include engine\'s routes with ENGINES=true' +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 = Rails.application.routes.routes -- cgit v1.2.3 From 95e9b5fbfd87b81bf2d2b16a6df6d9ddbfdb686d Mon Sep 17 00:00:00 2001 From: John Donahue Date: Fri, 25 Nov 2011 09:06:14 -0800 Subject: Updating newline fix to maintain existing linebreaks and indentation and test for b/eol on inserts --- railties/lib/rails/generators/actions.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 184cb2866b..ca93f9ef9d 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -68,8 +68,9 @@ module Rails end in_root do - str = "\ngem #{parts.join(", ")}\n" + str = "gem #{parts.join(", ")}" str = " " + str if @in_group + str = "\n" + str append_file "Gemfile", str, :verbose => false end end @@ -87,13 +88,13 @@ module Rails log :gemfile, "group #{name}" in_root do - append_file "Gemfile", "\ngroup #{name} do\n", :force => true + append_file "Gemfile", "\ngroup #{name} do", :force => true @in_group = true instance_eval(&block) @in_group = false - append_file "Gemfile", "end\n", :force => true + append_file "Gemfile", "\nend\n", :force => true end end -- cgit v1.2.3 From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 19:29:39 +0000 Subject: Revert the serializers API as other alternatives are now also under discussion --- railties/lib/rails/generators.rb | 4 +-- .../rails/scaffold/scaffold_generator.rb | 1 - .../lib/rails/generators/rails/serializer/USAGE | 9 ----- .../rails/serializer/serializer_generator.rb | 39 ---------------------- .../rails/serializer/templates/serializer.rb | 9 ----- .../test_unit/serializer/serializer_generator.rb | 13 -------- .../test_unit/serializer/templates/unit_test.rb | 9 ----- 7 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/serializer/USAGE delete mode 100644 railties/lib/rails/generators/rails/serializer/serializer_generator.rb delete mode 100644 railties/lib/rails/generators/rails/serializer/templates/serializer.rb delete mode 100644 railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb delete mode 100644 railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index f1ca9080ff..27f8d13ce8 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -33,8 +33,7 @@ module Rails :stylesheets => '-y', :stylesheet_engine => '-se', :template_engine => '-e', - :test_framework => '-t', - :serializer => '-z' + :test_framework => '-t' }, :test_unit => { @@ -59,7 +58,6 @@ module Rails :performance_tool => nil, :resource_controller => :controller, :scaffold_controller => :scaffold_controller, - :serializer => false, :stylesheets => true, :stylesheet_engine => :css, :test_framework => false, diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 7353a67c83..03a61a035e 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -10,7 +10,6 @@ module Rails class_option :stylesheet_engine, :desc => "Engine for Stylesheets" hook_for :scaffold_controller, :required => true - hook_for :serializer hook_for :assets do |assets| invoke assets, [controller_name] diff --git a/railties/lib/rails/generators/rails/serializer/USAGE b/railties/lib/rails/generators/rails/serializer/USAGE deleted file mode 100644 index a49f7ea1fb..0000000000 --- a/railties/lib/rails/generators/rails/serializer/USAGE +++ /dev/null @@ -1,9 +0,0 @@ -Description: - Generates a serializer for the given resource with tests. - -Example: - `rails generate serializer Account name created_at` - - For TestUnit it creates: - Serializer: app/serializers/account_serializer.rb - TestUnit: test/unit/account_serializer_test.rb diff --git a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb b/railties/lib/rails/generators/rails/serializer/serializer_generator.rb deleted file mode 100644 index 2118906227..0000000000 --- a/railties/lib/rails/generators/rails/serializer/serializer_generator.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Rails - module Generators - class SerializerGenerator < NamedBase - check_class_collision :suffix => "Serializer" - - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" - - class_option :parent, :type => :string, :desc => "The parent class for the generated serializer" - - def create_serializer_file - template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb") - end - - hook_for :test_framework - - private - - def attributes_names - attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym } - end - - def association_names - attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym } - end - - def parent_class_name - if options[:parent] - options[:parent] - elsif (n = Rails::Generators.namespace) && n.const_defined?(:ApplicationSerializer) - "ApplicationSerializer" - elsif Object.const_defined?(:ApplicationSerializer) - "ApplicationSerializer" - else - "ActiveModel::Serializer" - end - end - end - end -end diff --git a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb b/railties/lib/rails/generators/rails/serializer/templates/serializer.rb deleted file mode 100644 index 30c058c7e9..0000000000 --- a/railties/lib/rails/generators/rails/serializer/templates/serializer.rb +++ /dev/null @@ -1,9 +0,0 @@ -<% module_namespacing do -%> -class <%= class_name %>Serializer < <%= parent_class_name %> -<% if attributes.any? -%> attributes <%= attributes_names.map(&:inspect).join(", ") %> -<% end -%> -<% association_names.each do |attribute| -%> - has_one :<%= attribute %> -<% end -%> -end -<% end -%> \ No newline at end of file diff --git a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb b/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb deleted file mode 100644 index 533c032c3b..0000000000 --- a/railties/lib/rails/generators/test_unit/serializer/serializer_generator.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rails/generators/test_unit' - -module TestUnit - module Generators - class SerializerGenerator < Base - check_class_collision :suffix => "SerializerTest" - - def create_test_files - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_serializer_test.rb") - end - end - end -end diff --git a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb deleted file mode 100644 index 0b1bbdcaa5..0000000000 --- a/railties/lib/rails/generators/test_unit/serializer/templates/unit_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' - -<% module_namespacing do -%> -class <%= class_name %>SerializerTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end -<% end -%> -- cgit v1.2.3 From 89d6db05d74ba8cb1d99aaa2166f02dd67a34a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ku=C5=BAma?= Date: Sat, 26 Nov 2011 17:11:17 +0100 Subject: allow using orm_instance without invoking orm_class first in generators --- railties/lib/rails/generators/resource_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index b34bc4a524..f2195cb81a 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -73,7 +73,7 @@ module Rails # Initialize ORM::Generators::ActiveModel to access instance methods. def orm_instance(name=singular_table_name) - @orm_instance ||= @orm_class.new(name) + @orm_instance ||= orm_class.new(name) end end end -- cgit v1.2.3 From 4e5eaae1faebe5e889a50a3c3cfade397f39863c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ku=C5=BAma?= Date: Sat, 26 Nov 2011 19:57:51 +0100 Subject: added tests, replaced classify with constantize - using classify here cuts the last 's' in ORM name --- railties/lib/rails/generators/resource_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index f2195cb81a..3c5b39fa16 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -64,7 +64,7 @@ module Rails end begin - "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize + "#{options[:orm].to_s.camelize}::Generators::ActiveModel".constantize rescue NameError Rails::Generators::ActiveModel end -- cgit v1.2.3 From 78ad94aaa7b70fee6c8f49de04f26d4ec14fa162 Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 27 Nov 2011 20:25:05 +0900 Subject: avoid absolute path for the rails.png in index.html --- railties/lib/rails/generators/rails/app/templates/public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/public/index.html b/railties/lib/rails/generators/rails/app/templates/public/index.html index 9d9811a5bf..a1d50995c5 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/index.html +++ b/railties/lib/rails/generators/rails/app/templates/public/index.html @@ -59,7 +59,7 @@ #header { - background-image: url("/assets/rails.png"); + background-image: url("assets/rails.png"); background-repeat: no-repeat; background-position: top left; height: 64px; -- cgit v1.2.3 From 7f8f554d75a4c1fe56fda1cbf39f67a0b32b5c16 Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 27 Nov 2011 22:49:37 +0900 Subject: Call a block passed rake_tasks method in the self context --- railties/lib/rails/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index f0991b99af..07a122e7d0 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -181,7 +181,7 @@ module Rails def load_tasks(app=self) extend Rake::DSL if defined? Rake::DSL - self.class.rake_tasks.each { |block| block.call(app) } + self.class.rake_tasks.each { |block| self.instance_exec(app, &block) } # load also tasks from all superclasses klass = self.class.superclass -- cgit v1.2.3 From 8ef1ec427f75a3ca2a2c19737a057ad3f354a9bd Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Mon, 10 Oct 2011 19:02:06 +0530 Subject: global variable `$rails_rake_task' not initialized Warning removed --- railties/lib/rails/application/finisher.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 028c8814c4..fc7d205a6f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -2,6 +2,7 @@ module Rails class Application module Finisher include Initializable + $rails_rake_task = nil initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) -- cgit v1.2.3 From fe7d4f09ef2296e45ab4a82c1556c63382856607 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 28 Nov 2011 19:25:37 +0300 Subject: put backtrace_cleaner to env --- railties/lib/rails/application.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 25ff74506a..2a62446a04 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -124,7 +124,8 @@ module Rails "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.secret_token" => config.secret_token, "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions, - "action_dispatch.logger" => Rails.logger + "action_dispatch.logger" => Rails.logger, + "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner }) end -- cgit v1.2.3 From 750bb5c865ac9234da91ec451eec7d9de55b8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 20:46:18 +0100 Subject: Split ShowExceptions responsibilities in two middlewares. --- railties/lib/rails/application.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 2a62446a04..f5f47acfbc 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -195,10 +195,13 @@ module Rails middleware.use ::ActionDispatch::RequestId middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions + middleware.use ::ActionDispatch::DebugExceptions middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies + if config.action_dispatch.x_sendfile_header.present? middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header end + middleware.use ::ActionDispatch::Reloader unless config.cache_classes middleware.use ::ActionDispatch::Callbacks middleware.use ::ActionDispatch::Cookies -- cgit v1.2.3 From 0306f82e0c3cda3aad1b45eb0c3a359c254b62cc Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 2 Dec 2011 04:32:18 -0800 Subject: implements automatic EXPLAIN logging for slow queries --- .../rails/app/templates/config/environments/development.rb.tt | 4 ++++ .../rails/app/templates/config/environments/production.rb.tt | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 47078e3af9..beaf941282 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -25,6 +25,10 @@ <%- unless options.skip_active_record? -%> # Raise exception on mass assignment protection for ActiveRecord models config.active_record.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL) + config.active_record.auto_explain_threshold_in_seconds = 0.5 <%- end -%> # Do not compress assets diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 50f2df3d35..40ec3fc644 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -60,4 +60,10 @@ # Send deprecation notices to registered listeners config.active_support.deprecation = :notify + + <%- unless options.skip_active_record? -%> + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL) + # config.active_record.auto_explain_threshold_in_seconds = 0.5 + <%- end -%> end -- cgit v1.2.3 From d2f46d053f640c568a9cea25db66c227b6dc4ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Mon, 5 Dec 2011 21:24:09 +0200 Subject: Remove .rxml, .rjs and .rhtml from source annotation regexp. --- railties/lib/rails/source_annotation_extractor.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 1eed763aa3..a9f2180196 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -30,7 +30,7 @@ class SourceAnnotationExtractor # Prints all annotations with tag +tag+ under the root directories +app+, +config+, +lib+, # +script+, and +test+ (recursively). Only filenames with extension - # +.builder+, +.rb+, +.rxml+, +.rhtml+, or +.erb+ are taken into account. The +options+ + # +.builder+, +.rb+, and +.erb+ are taken into account. The +options+ # hash is passed to each annotation's +to_s+. # # This class method is the single entry point for the rake tasks. @@ -47,7 +47,7 @@ class SourceAnnotationExtractor # Returns a hash that maps filenames under +dirs+ (recursively) to arrays # with their annotations. Only files with annotations are included, and only - # those with extension +.builder+, +.rb+, +.rxml+, +.rhtml+, and +.erb+ + # those with extension +.builder+, +.rb+, and +.erb+ # are taken into account. def find(dirs=%w(app config lib script test)) dirs.inject({}) { |h, dir| h.update(find_in(dir)) } @@ -55,7 +55,7 @@ class SourceAnnotationExtractor # Returns a hash that maps filenames under +dir+ (recursively) to arrays # with their annotations. Only files with annotations are included, and only - # those with extension +.builder+, +.rb+, +.rxml+, +.rhtml+, and +.erb+ + # those with extension +.builder+, +.rb+, and +.erb+ # are taken into account. def find_in(dir) results = {} @@ -65,9 +65,9 @@ class SourceAnnotationExtractor if File.directory?(item) results.update(find_in(item)) - elsif item =~ /\.(builder|(r(?:b|xml|js)))$/ + elsif item =~ /\.(builder|rb)$/ results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/)) - elsif item =~ /\.(rhtml|erb)$/ + elsif item =~ /\.erb$/ results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)) end end -- cgit v1.2.3 From 8f61df0bcd0e84f26c6c41b98eeb2f7bb8d5ca4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kazimierz=20Kie=C5=82kowicz?= Date: Wed, 7 Dec 2011 13:17:50 +0100 Subject: Add annotation to haml and slim template. --- railties/lib/rails/source_annotation_extractor.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index a9f2180196..3705db0a3a 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -69,6 +69,10 @@ class SourceAnnotationExtractor results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/)) elsif item =~ /\.erb$/ results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)) + elsif item =~ /\.haml$/ + results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/)) + elsif item =~ /\.slim$/ + results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/)) end end -- cgit v1.2.3 From 8188d265a1ea8c33cc6b82c2142325d1a0c62d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kazimierz=20Kie=C5=82kowicz?= Date: Wed, 7 Dec 2011 17:30:03 +0100 Subject: Update source_annotation_extractor comment. --- railties/lib/rails/source_annotation_extractor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 3705db0a3a..a296473632 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -55,7 +55,7 @@ class SourceAnnotationExtractor # Returns a hash that maps filenames under +dir+ (recursively) to arrays # with their annotations. Only files with annotations are included, and only - # those with extension +.builder+, +.rb+, and +.erb+ + # those with extension +.builder+, +.rb+, +.erb+, +.haml+ and +.slim+ # are taken into account. def find_in(dir) results = {} -- cgit v1.2.3 From 94dcbe8115810b4545ca8011e6c1e5386cb1c842 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 9 Dec 2011 01:15:54 +0530 Subject: fix nodocs --- railties/lib/rails/engine/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index f424492bb4..d6015e9c01 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -30,7 +30,7 @@ module Rails # # config.generators.colorize_logging = false # - def generators #:nodoc + def generators #:nodoc: @generators ||= Rails::Configuration::Generators.new yield(@generators) if block_given? @generators -- cgit v1.2.3 From 5c60b44837cd52855b0082c73f8e7af051ba0550 Mon Sep 17 00:00:00 2001 From: Steve Richert Date: Fri, 9 Dec 2011 16:49:29 -0500 Subject: Add the .rdoc extension to the README that Rails generates for a new application --- railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 3e32f758a4..2a6bd57df4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -38,7 +38,7 @@ module Rails end def readme - copy_file "README" + copy_file "README", "README.rdoc" end def gemfile -- cgit v1.2.3 From 04ef93dae6d9cec616973c1110a33894ad4ba6ed Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 9 Dec 2011 16:03:18 -0800 Subject: * ActiveSupport::BufferedLogger#silence is deprecated. If you want to squelch logs for a certain block, change the log level for that block. * ActiveSupport::BufferedLogger#open_log is deprecated. This method should not have been public in the first place. * ActiveSupport::BufferedLogger's behavior of automatically creating the directory for your log file is deprecated. Please make sure to create the directory for your log file before instantiating. * ActiveSupport::BufferedLogger#auto_flushing is deprecated. Either set the sync level on the underlying file handle like this: f = File.open('foo.log', 'w') f.sync = true ActiveSupport::BufferedLogger.new f Or tune your filesystem. The FS cache is now what controls flushing. * ActiveSupport::BufferedLogger#flush is deprecated. Set sync on your filehandle, or tune your filesystem. --- railties/lib/rails/application/bootstrap.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index c2cb121e42..1ae90056d9 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -24,9 +24,18 @@ module Rails initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin path = config.paths["log"].first - logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(path)) + unless File.exist? File.dirname path + FileUtils.mkdir_p File.dirname path + end + + f = File.open path, 'w' + f.binmode + f.sync = !Rails.env.production? # make sure every write flushes + + logger = ActiveSupport::TaggedLogging.new( + ActiveSupport::BufferedLogger.new(f) + ) logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) - logger.auto_flushing = false if Rails.env.production? logger rescue StandardError logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) @@ -37,7 +46,6 @@ module Rails ) logger end - at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) } end # Initialize cache early in the stack so railties can make use of it. -- cgit v1.2.3 From b12a17665abe37ab7ef116fc56519fdadf045dd6 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 9 Dec 2011 21:52:10 -0500 Subject: Skip assets groups if --skip-sprockets option is given --- railties/lib/rails/generators/app_base.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 3fbde0d989..e3d22e81fb 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -193,6 +193,7 @@ module Rails end def assets_gemfile_entry + return if options[:skip_sprockets] <<-GEMFILE.strip_heredoc # Gems used only for assets and not required # in production environments by default. -- cgit v1.2.3 From ea5a70a462b463d46b4ec558cbf3e8db685acaf0 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 11 Dec 2011 08:48:58 -0500 Subject: Skip assets options in environments files when --skip-sprockets is used --- .../rails/app/templates/config/environments/development.rb.tt | 2 ++ .../rails/app/templates/config/environments/production.rb.tt | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index beaf941282..9e53b6a70d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -31,9 +31,11 @@ config.active_record.auto_explain_threshold_in_seconds = 0.5 <%- end -%> + <%- unless options.skip_sprockets? -%> # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true + <%- end -%> end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 40ec3fc644..0f571f7c1a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -11,6 +11,7 @@ # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false + <%- unless options.skip_sprockets? -%> # Compress JavaScripts and CSS config.assets.compress = true @@ -22,6 +23,7 @@ # Defaults to Rails.root.join("public/assets") # config.assets.manifest = YOUR_PATH + <%- end -%> # Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache @@ -45,8 +47,10 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" + <%- unless options.skip_sprockets? -%> # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) + <%- end -%> # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false -- cgit v1.2.3 From aa6aa9b25dce80d2d9d63d6784a00be3cfda8d2e Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 11 Dec 2011 22:24:50 +0530 Subject: revising doc --- railties/lib/rails/source_annotation_extractor.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index a296473632..2286e0477a 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -46,9 +46,7 @@ class SourceAnnotationExtractor end # Returns a hash that maps filenames under +dirs+ (recursively) to arrays - # with their annotations. Only files with annotations are included, and only - # those with extension +.builder+, +.rb+, and +.erb+ - # are taken into account. + # with their annotations. def find(dirs=%w(app config lib script test)) dirs.inject({}) { |h, dir| h.update(find_in(dir)) } end -- cgit v1.2.3 From 5c234ab8ed4659a74a6c47ce8337055a62f75eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 14:39:22 +0100 Subject: Composition > inheritance. --- railties/lib/rails/application/routes_reloader.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 1d1f5e1b06..c1f435a3ee 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,13 +1,21 @@ module Rails class Application - class RoutesReloader < ::ActiveSupport::FileUpdateChecker + class RoutesReloader attr_reader :route_sets - def initialize - super([]) { reload! } + def initialize(updater=ActiveSupport::FileUpdateChecker) + @updater = updater.new([]) { reload! } @route_sets = [] end + def paths + @updater.paths + end + + def execute_if_updated + @updater.execute_if_updated + end + def reload! clear! load_paths -- cgit v1.2.3 From 27f0add3f93510c1aee2491467dffbb1e4015bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 15:18:19 +0100 Subject: Improve docs for Rails::Application and add routes_reloader_hook and app_reloader_hooks. --- railties/lib/rails/application.rb | 63 +++++++++++++++++++++++++---- railties/lib/rails/application/bootstrap.rb | 7 ---- railties/lib/rails/application/finisher.rb | 36 ++++++++++------- 3 files changed, 77 insertions(+), 29 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index f5f47acfbc..f1d546fc59 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -33,6 +33,24 @@ module Rails # # The Application is also responsible for building the middleware stack. # + # == Booting process + # + # The application is also responsible for setting up and executing the booting + # process. From the moment you require "config/application.rb" in your app, + # the booting process goes like this: + # + # 1) require "config/boot.rb" to setup load paths + # 2) require railties and engines + # 3) Define Rails.application as "class MyApp::Application < Rails::Application" + # 4) Run config.before_configuration callbacks + # 5) Load config/environments/ENV.rb + # 6) Run config.before_initialize callbacks + # 7) Run Railtie#initializer defined by railties, engines and application. + # One by one, each engine sets up its load paths, routes and runs its initializer files. + # 8) Build the middleware stack and run to_prepare callbacks + # 9) Run config.before_eager_load and eager_load if cache classes is true + # 10) Run config.after_initialize callbacks + # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Configuration, 'rails/application/configuration' @@ -83,27 +101,55 @@ module Rails require environment if environment end + # Reload application routes regardless if they changed or not. def reload_routes! routes_reloader.reload! end - def routes_reloader + def routes_reloader #:nodoc: @routes_reloader ||= RoutesReloader.new end - def initialize!(group=:default) + # A routes reloader hook that is used to setup to_prepare callbacks. + # A plugin may override this if they desire to provide a more + # exquisite route reloading. + # :api: plugin + def routes_reloader_hook + app = self + lambda { app.routes_reloader.execute_if_updated } + end + + # An app reloader hook that is used to setup to_cleanup callbacks. + # A plugin may override this if they desire to provide a more exquisite app reloading. + # :api: plugin + def app_reloader_hook + lambda { + ActiveSupport::DescendantsTracker.clear + ActiveSupport::Dependencies.clear + } + end + + # Initialize the application passing the given group. By default, the + # group is :default but sprockets precompilation passes group equals + # to assets if initialize_on_precompile is false to avoid booting the + # whole app. + def initialize!(group=:default) #:nodoc: raise "Application has been already initialized." if @initialized run_initializers(group, self) @initialized = true self end + # Load the application and its railties tasks and invoke the registered hooks. + # Check Rails::Railtie.rake_tasks for more info. def load_tasks(app=self) initialize_tasks super self end + # Load the application console and invoke the registered hooks. + # Check Rails::Railtie.console for more info. def load_console(app=self) initialize_console super @@ -129,7 +175,8 @@ module Rails }) end - def ordered_railties + # Returns the ordered railties for this application considering railties_order. + def ordered_railties #:nodoc: @ordered_railties ||= begin order = config.railties_order.map do |railtie| if railtie == :main_app @@ -151,13 +198,13 @@ module Rails end end - def initializers + def initializers #:nodoc: Bootstrap.initializers_for(self) + super + Finisher.initializers_for(self) end - def config + def config #:nodoc: @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd)) end @@ -165,7 +212,7 @@ module Rails self end - def helpers_paths + def helpers_paths #:nodoc: config.helpers_paths end @@ -222,7 +269,7 @@ module Rails end end - def initialize_tasks + def initialize_tasks #:nodoc: self.class.rake_tasks do require "rails/tasks" task :environment do @@ -232,7 +279,7 @@ module Rails end end - def initialize_console + def initialize_console #:nodoc: require "pp" require "rails/console/app" require "rails/console/helpers" diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 1ae90056d9..e189009cc5 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -59,13 +59,6 @@ module Rails end end - initializer :set_clear_dependencies_hook, :group => :all do - ActionDispatch::Reloader.to_cleanup do - ActiveSupport::DescendantsTracker.clear - ActiveSupport::Dependencies.clear - end - end - # Sets the dependency loading mechanism. # TODO: Remove files from the $" and always use require. initializer :initialize_dependency_mechanism, :group => :all do diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index fc7d205a6f..df2853498a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -20,12 +20,6 @@ module Rails end end - initializer :add_to_prepare_blocks do - config.to_prepare_blocks.each do |block| - ActionDispatch::Reloader.to_prepare(&block) - end - end - initializer :add_builtin_route do |app| if Rails.env.development? app.routes.append do @@ -38,14 +32,22 @@ module Rails build_middleware_stack end - initializer :run_prepare_callbacks do - ActionDispatch::Reloader.prepare! - end - initializer :define_main_app_helper do |app| app.routes.define_mounted_helper(:main_app) end + initializer :add_to_prepare_blocks do + config.to_prepare_blocks.each do |block| + ActionDispatch::Reloader.to_prepare(&block) + end + end + + # This needs to happen before eager load so it happens + # in exactly the same point regardless of config.cache_classes + initializer :run_prepare_callbacks do + ActionDispatch::Reloader.prepare! + end + initializer :eager_load! do if config.cache_classes && !$rails_rake_task ActiveSupport.run_load_hooks(:before_eager_load, self) @@ -53,15 +55,21 @@ module Rails end end + # All initialization is done, including eager loading in production initializer :finisher_hook do ActiveSupport.run_load_hooks(:after_initialize, self) end - # Force routes to be loaded just at the end and add it to to_prepare callbacks - # This needs to be after the finisher hook to ensure routes added in the hook - # are still loaded. + # Set app reload just after the finisher hook to ensure + # paths added in the hook are still loaded. + initializer :set_clear_dependencies_hook, :group => :all do |app| + ActionDispatch::Reloader.to_cleanup(&app.app_reloader_hook) + end + + # Set app reload just after the finisher hook to ensure + # routes added in the hook are still loaded. initializer :set_routes_reloader do |app| - reloader = lambda { app.routes_reloader.execute_if_updated } + reloader = app.routes_reloader_hook reloader.call ActionDispatch::Reloader.to_prepare(&reloader) end -- cgit v1.2.3 From c2e3ce8d1e1174e66536d59d8d97eb2cc8ce6f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 15:34:31 +0100 Subject: Provide a unique point for running initializers. --- railties/lib/rails/application.rb | 9 +++++---- railties/lib/rails/application/configuration.rb | 3 ++- railties/lib/rails/application/finisher.rb | 4 ++++ railties/lib/rails/engine.rb | 6 ++---- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index f1d546fc59..2648476d6d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -46,10 +46,11 @@ module Rails # 5) Load config/environments/ENV.rb # 6) Run config.before_initialize callbacks # 7) Run Railtie#initializer defined by railties, engines and application. - # One by one, each engine sets up its load paths, routes and runs its initializer files. - # 8) Build the middleware stack and run to_prepare callbacks - # 9) Run config.before_eager_load and eager_load if cache classes is true - # 10) Run config.after_initialize callbacks + # One by one, each engine sets up its load paths, routes, locales and so on. + # 8) Runs all registered config/initializers/*, executing the engines one first + # 9) Build the middleware stack and run to_prepare callbacks + # 10) Run config.before_eager_load and eager_load if cache classes is true + # 11) Run config.after_initialize callbacks # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index e95b0f5495..9e1a5be358 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -11,7 +11,7 @@ module Rails :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils, :railties_order + :time_zone, :whiny_nils, :railties_order, :all_initializers attr_writer :log_level attr_reader :encoding @@ -36,6 +36,7 @@ module Rails @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] + @all_initializers = [] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index df2853498a..9c25e05ee5 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -4,6 +4,10 @@ module Rails include Initializable $rails_rake_task = nil + initializer :load_config_initializers do + config.all_initializers.each { |init| load(init) } + end + initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 5c1af99fe2..8ebe1f48a5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -583,10 +583,8 @@ module Rails end end - initializer :load_config_initializers do - config.paths["config/initializers"].existent.sort.each do |initializer| - load(initializer) - end + initializer :append_config_initializers do |app| + app.config.all_initializers.concat config.paths["config/initializers"].existent.sort end initializer :engines_blank_point do -- cgit v1.2.3 From c0466603288252a5db8a4d8cf0ca193004a542ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 16:23:50 +0100 Subject: Give hooks the flexibility to choose the type of callback. --- railties/lib/rails/application.rb | 16 +++++++++------- railties/lib/rails/application/finisher.rb | 10 ++++------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 2648476d6d..acbfd7078b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -115,19 +115,21 @@ module Rails # A plugin may override this if they desire to provide a more # exquisite route reloading. # :api: plugin - def routes_reloader_hook - app = self - lambda { app.routes_reloader.execute_if_updated } + def set_routes_reloader_hook + reloader = routes_reloader + hook = lambda { reloader.execute_if_updated } + hook.call + ActionDispatch::Reloader.to_prepare(&hook) end - # An app reloader hook that is used to setup to_cleanup callbacks. + # An app dependencies hook that is used to setup to_cleanup callbacks. # A plugin may override this if they desire to provide a more exquisite app reloading. # :api: plugin - def app_reloader_hook - lambda { + def set_dependencies_hook + ActionDispatch::Reloader.to_cleanup do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear - } + end end # Initialize the application passing the given group. By default, the diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 9c25e05ee5..17e7aa0f28 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -66,16 +66,14 @@ module Rails # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_clear_dependencies_hook, :group => :all do |app| - ActionDispatch::Reloader.to_cleanup(&app.app_reloader_hook) + initializer :set_dependencies_hook, :group => :all do |app| + app.set_dependencies_hook end # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. - initializer :set_routes_reloader do |app| - reloader = app.routes_reloader_hook - reloader.call - ActionDispatch::Reloader.to_prepare(&reloader) + initializer :set_routes_reloader_hook do |app| + app.set_routes_reloader_hook end # Disable dependency loading during request cycle -- cgit v1.2.3 From 5266eb9f611a114663c48eec0680b7050181d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Oko=C5=84ski?= Date: Mon, 12 Dec 2011 16:52:56 +0100 Subject: Default relative_url_root to ENV["RAILS_RELATIVE_URL_ROOT"]. Fixes #3365 --- railties/lib/rails/application/configuration.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9e1a5be358..4b2afe3a28 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -9,7 +9,7 @@ module Rails :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, - :reload_plugins, :secret_token, :serve_static_assets, + :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :whiny_nils, :railties_order, :all_initializers @@ -37,6 +37,7 @@ module Rails @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] @all_initializers = [] + @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From f8fa3835319dc4517e5b77215d514bba62f04868 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 12 Dec 2011 12:37:37 -0500 Subject: Use rubygems https endpoint for the Gemfile on new apps --- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index d3b8f4d595..c260cc999b 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,4 +1,4 @@ -source 'http://rubygems.org' +source 'https://rubygems.org' <%= rails_gemfile_entry -%> -- cgit v1.2.3 From b04e2d86df388098c12d2067ac6997e11b9479ad Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Dec 2011 13:46:05 -0800 Subject: strip whitespace errors from the generated Gemfile --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index e3d22e81fb..0bd39cb2cd 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -194,7 +194,7 @@ module Rails def assets_gemfile_entry return if options[:skip_sprockets] - <<-GEMFILE.strip_heredoc + <<-GEMFILE.strip_heredoc.gsub(/^[ \t]*$/, '') # Gems used only for assets and not required # in production environments by default. group :assets do -- cgit v1.2.3 From fa1d9a884c0d5b70c97442e3360ac98ca5fa4340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 22:51:33 +0100 Subject: Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting `config.reload_classes_only_on_change` to false. Extensions like Active Record should add their respective files like db/schema.rb and db/structure.sql to `config.watchable_files` if they want their changes to affect classes reloading. Thanks to https://github.com/paneq/active_reload and Pastorino for the inspiration. <3 --- railties/lib/rails/application.rb | 40 +++++++++++++++++- railties/lib/rails/application/configuration.rb | 49 ++++++++++++----------- railties/lib/rails/application/finisher.rb | 14 +++---- railties/lib/rails/application/routes_reloader.rb | 12 ++---- railties/lib/rails/engine.rb | 2 +- railties/lib/rails/railtie/configuration.rb | 12 ++++++ 6 files changed, 87 insertions(+), 42 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index acbfd7078b..0b8eac8a8b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -71,12 +71,14 @@ module Rails attr_accessor :assets, :sandbox alias_method :sandbox?, :sandbox + attr_reader :reloaders delegate :default_url_options, :default_url_options=, :to => :routes def initialize super @initialized = false + @reloaders = [] end # This method is called just after an application inherits from Rails::Application, @@ -119,6 +121,7 @@ module Rails reloader = routes_reloader hook = lambda { reloader.execute_if_updated } hook.call + self.reloaders << reloader ActionDispatch::Reloader.to_prepare(&hook) end @@ -126,10 +129,35 @@ module Rails # A plugin may override this if they desire to provide a more exquisite app reloading. # :api: plugin def set_dependencies_hook - ActionDispatch::Reloader.to_cleanup do + callback = lambda do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear end + + if config.reload_classes_only_on_change + reloader = ActiveSupport::FileUpdateChecker.new(watchable_args, true, &callback) + self.reloaders << reloader + # We need to set a to_prepare callback regardless of the reloader result, i.e. + # models should be reloaded if any of the reloaders (i18n, routes) were updated. + ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) + else + ActionDispatch::Reloader.to_cleanup(&callback) + end + end + + # Returns an array of file paths appended with a hash of directories-extensions + # suitable for ActiveSupport::FileUpdateChecker API. + def watchable_args + files = [] + files.concat config.watchable_files + + dirs = {} + dirs.merge! config.watchable_dirs + ActiveSupport::Dependencies.autoload_paths.each do |path| + dirs[path.to_s] = [:rb] + end + + files << dirs end # Initialize the application passing the given group. By default, the @@ -223,6 +251,10 @@ module Rails alias :build_middleware_stack :app + def reload_dependencies? + config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any? + end + def default_middleware_stack ActionDispatch::MiddlewareStack.new.tap do |middleware| if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache @@ -252,7 +284,11 @@ module Rails middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header end - middleware.use ::ActionDispatch::Reloader unless config.cache_classes + unless config.cache_classes + app = self + middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? } + end + middleware.use ::ActionDispatch::Callbacks middleware.use ::ActionDispatch::Cookies diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 4b2afe3a28..39d66ecc31 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -7,11 +7,11 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :filter_parameters, - :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, - :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, - :ssl_options, :static_cache_control, :session_options, - :time_zone, :whiny_nils, :railties_order, :all_initializers + :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, + :initializers_paths, :logger, :log_tags, :preload_frameworks, + :railties_order, :relative_url_root, :reload_plugins, :secret_token, + :serve_static_assets, :ssl_options, :static_cache_control, :session_options, + :time_zone, :reload_classes_only_on_change, :whiny_nils attr_writer :log_level attr_reader :encoding @@ -19,25 +19,26 @@ module Rails def initialize(*) super self.encoding = "utf-8" - @allow_concurrency = false - @consider_all_requests_local = false - @filter_parameters = [] - @helpers_paths = [] - @dependency_loading = true - @serve_static_assets = true - @static_cache_control = nil - @force_ssl = false - @ssl_options = {} - @session_store = :cookie_store - @session_options = {} - @time_zone = "UTC" - @log_level = nil - @middleware = app_middleware - @generators = app_generators - @cache_store = [ :file_store, "#{root}/tmp/cache/" ] - @railties_order = [:all] - @all_initializers = [] - @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] + @allow_concurrency = false + @consider_all_requests_local = false + @filter_parameters = [] + @helpers_paths = [] + @dependency_loading = true + @serve_static_assets = true + @static_cache_control = nil + @force_ssl = false + @ssl_options = {} + @session_store = :cookie_store + @session_options = {} + @time_zone = "UTC" + @log_level = nil + @middleware = app_middleware + @generators = app_generators + @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] + @initializers_paths = [] + @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] + @reload_classes_only_on_change = true @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 17e7aa0f28..e000f6ef3a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -5,7 +5,7 @@ module Rails $rails_rake_task = nil initializer :load_config_initializers do - config.all_initializers.each { |init| load(init) } + config.initializers_paths.each { |init| load(init) } end initializer :add_generator_templates do @@ -64,18 +64,18 @@ module Rails ActiveSupport.run_load_hooks(:after_initialize, self) end - # Set app reload just after the finisher hook to ensure - # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do |app| - app.set_dependencies_hook - end - # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. initializer :set_routes_reloader_hook do |app| app.set_routes_reloader_hook end + # Set app reload just after the finisher hook to ensure + # paths added in the hook are still loaded. + initializer :set_dependencies_hook, :group => :all do |app| + app.set_dependencies_hook + end + # Disable dependency loading during request cycle initializer :disable_dependency_loading do if config.cache_classes && !config.dependency_loading diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index c1f435a3ee..460b84dfd9 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,21 +1,17 @@ +require "active_support/core_ext/module/delegation" + module Rails class Application class RoutesReloader attr_reader :route_sets + delegate :paths, :execute_if_updated, :updated?, :to => :@updater + def initialize(updater=ActiveSupport::FileUpdateChecker) @updater = updater.new([]) { reload! } @route_sets = [] end - def paths - @updater.paths - end - - def execute_if_updated - @updater.execute_if_updated - end - def reload! clear! load_paths diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 8ebe1f48a5..86efc7332c 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -584,7 +584,7 @@ module Rails end initializer :append_config_initializers do |app| - app.config.all_initializers.concat config.paths["config/initializers"].existent.sort + app.config.initializers_paths.concat config.paths["config/initializers"].existent.sort end initializer :engines_blank_point do diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index f888684117..cf9e4ad500 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -7,6 +7,18 @@ module Rails @@options ||= {} end + # Add files that should be watched for change. + def watchable_files + @@watchable_files ||= [] + end + + # Add directories that should be watched for change. + # The key of the hashes should be directories and the values should + # be an array of extensions to match in each directory. + def watchable_dirs + @@watchable_dirs ||= {} + end + # This allows you to modify the application's middlewares from Engines. # # All operations you run on the app_middleware will be replayed on the -- cgit v1.2.3 From f2fa4837a8a888ee86997be892d0aa5bbd2b5fd0 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 13 Dec 2011 10:14:38 +0300 Subject: commented whitelist mode enforcement for mass assignment --- .../lib/rails/generators/rails/app/templates/config/application.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 40fd843b1b..c6dfa1f2dd 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -54,6 +54,12 @@ module <%= app_const_base %> # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql + # Enforce whitelist mode for mass assignment. + # This will create an empty whitelist of attributes available for mass-assignment for all models + # in your app. As such, your models will need to explicitly whitelist or blacklist accessible + # parameters by using an attr_accessible or attr_protected declaration. + # config.active_record.whitelist_attributes = true + <% unless options.skip_sprockets? -%> # Enable the asset pipeline config.assets.enabled = true -- cgit v1.2.3 From 11aa167e239a85513d00a7910446bedf7b1f7800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 08:49:04 +0100 Subject: Revert "Provide a unique point for running initializers." This reverts commit c2e3ce8d1e1174e66536d59d8d97eb2cc8ce6f25. Conflicts: railties/lib/rails/application/configuration.rb railties/lib/rails/application/finisher.rb railties/lib/rails/engine.rb --- railties/lib/rails/application.rb | 10 +++++----- railties/lib/rails/application/configuration.rb | 3 +-- railties/lib/rails/application/finisher.rb | 4 ---- railties/lib/rails/engine.rb | 6 ++++-- 4 files changed, 10 insertions(+), 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0b8eac8a8b..aa6608d49e 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -46,11 +46,11 @@ module Rails # 5) Load config/environments/ENV.rb # 6) Run config.before_initialize callbacks # 7) Run Railtie#initializer defined by railties, engines and application. - # One by one, each engine sets up its load paths, routes, locales and so on. - # 8) Runs all registered config/initializers/*, executing the engines one first - # 9) Build the middleware stack and run to_prepare callbacks - # 10) Run config.before_eager_load and eager_load if cache classes is true - # 11) Run config.after_initialize callbacks + # One by one, each engine sets up its load paths, routes and runs its config/initializers/* files. + # 9) Custom Railtie#initializers added by railties, engines and applications are executed + # 10) Build the middleware stack and run to_prepare callbacks + # 11) Run config.before_eager_load and eager_load if cache classes is true + # 12) Run config.after_initialize callbacks # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 39d66ecc31..40deecea1c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, - :initializers_paths, :logger, :log_tags, :preload_frameworks, + :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :whiny_nils @@ -36,7 +36,6 @@ module Rails @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] - @initializers_paths = [] @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index e000f6ef3a..3a94311b57 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -4,10 +4,6 @@ module Rails include Initializable $rails_rake_task = nil - initializer :load_config_initializers do - config.initializers_paths.each { |init| load(init) } - end - initializer :add_generator_templates do config.generators.templates.unshift(*paths["lib/templates"].existent) end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 86efc7332c..5c1af99fe2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -583,8 +583,10 @@ module Rails end end - initializer :append_config_initializers do |app| - app.config.initializers_paths.concat config.paths["config/initializers"].existent.sort + initializer :load_config_initializers do + config.paths["config/initializers"].existent.sort.each do |initializer| + load(initializer) + end end initializer :engines_blank_point do -- cgit v1.2.3 From cd3033eb627f408b71a7adf98c350e2c01115c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 09:19:58 +0100 Subject: Add config.file_watcher so developers can provide their own watchers (for instance, hooking on fsevents). --- railties/lib/rails/application.rb | 3 +-- railties/lib/rails/application/configuration.rb | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index aa6608d49e..35fae24297 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/hash/reverse_merge' -require 'active_support/file_update_checker' require 'fileutils' require 'rails/plugin' require 'rails/engine' @@ -135,7 +134,7 @@ module Rails end if config.reload_classes_only_on_change - reloader = ActiveSupport::FileUpdateChecker.new(watchable_args, true, &callback) + reloader = config.file_watcher.new(watchable_args, true, &callback) self.reloaders << reloader # We need to set a to_prepare callback regardless of the reloader result, i.e. # models should be reloaded if any of the reloaders (i18n, routes) were updated. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 40deecea1c..dddf7e498f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/string/encoding' require 'active_support/core_ext/kernel/reporting' +require 'active_support/file_update_checker' require 'rails/engine/configuration' module Rails @@ -7,8 +8,8 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, - :logger, :log_tags, :preload_frameworks, + :dependency_loading, :file_watcher, :filter_parameters, + :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :whiny_nils @@ -38,6 +39,7 @@ module Rails @railties_order = [:all] @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true + @file_watcher = ActiveSupport::FileUpdateChecker @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From 693d2be82706d7dc40af6860a26330c49c27f151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 09:25:12 +0100 Subject: Move hooks back to initializers (we need an API that allows hooks to be replaced). --- railties/lib/rails/application.rb | 32 ------------------------------ railties/lib/rails/application/finisher.rb | 25 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 36 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 35fae24297..75f2b9a3bd 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -112,38 +112,6 @@ module Rails @routes_reloader ||= RoutesReloader.new end - # A routes reloader hook that is used to setup to_prepare callbacks. - # A plugin may override this if they desire to provide a more - # exquisite route reloading. - # :api: plugin - def set_routes_reloader_hook - reloader = routes_reloader - hook = lambda { reloader.execute_if_updated } - hook.call - self.reloaders << reloader - ActionDispatch::Reloader.to_prepare(&hook) - end - - # An app dependencies hook that is used to setup to_cleanup callbacks. - # A plugin may override this if they desire to provide a more exquisite app reloading. - # :api: plugin - def set_dependencies_hook - callback = lambda do - ActiveSupport::DescendantsTracker.clear - ActiveSupport::Dependencies.clear - end - - if config.reload_classes_only_on_change - reloader = config.file_watcher.new(watchable_args, true, &callback) - self.reloaders << reloader - # We need to set a to_prepare callback regardless of the reloader result, i.e. - # models should be reloaded if any of the reloaders (i18n, routes) were updated. - ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) - else - ActionDispatch::Reloader.to_cleanup(&callback) - end - end - # Returns an array of file paths appended with a hash of directories-extensions # suitable for ActiveSupport::FileUpdateChecker API. def watchable_args diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 3a94311b57..738fb93994 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -62,14 +62,31 @@ module Rails # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. - initializer :set_routes_reloader_hook do |app| - app.set_routes_reloader_hook + initializer :set_routes_reloader_hook do + reloader = routes_reloader + hook = lambda { reloader.execute_if_updated } + hook.call + self.reloaders << reloader + ActionDispatch::Reloader.to_prepare(&hook) end # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do |app| - app.set_dependencies_hook + initializer :set_dependencies_hook, :group => :all do + callback = lambda do + ActiveSupport::DescendantsTracker.clear + ActiveSupport::Dependencies.clear + end + + if config.reload_classes_only_on_change + reloader = config.file_watcher.new(watchable_args, true, &callback) + self.reloaders << reloader + # We need to set a to_prepare callback regardless of the reloader result, i.e. + # models should be reloaded if any of the reloaders (i18n, routes) were updated. + ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) + else + ActionDispatch::Reloader.to_cleanup(&callback) + end end # Disable dependency loading during request cycle -- cgit v1.2.3 From 1f5b9bbdb377c1b0e29650a103bf53526ceefdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 10:07:02 +0100 Subject: Clean up FileUpdateChecker API. --- railties/lib/rails/application/finisher.rb | 2 +- railties/lib/rails/application/routes_reloader.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 738fb93994..064723c1e0 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -83,7 +83,7 @@ module Rails self.reloaders << reloader # We need to set a to_prepare callback regardless of the reloader result, i.e. # models should be reloaded if any of the reloaders (i18n, routes) were updated. - ActionDispatch::Reloader.to_prepare(:prepend => true, &callback) + ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute } else ActionDispatch::Reloader.to_cleanup(&callback) end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 460b84dfd9..e080481976 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -3,12 +3,12 @@ require "active_support/core_ext/module/delegation" module Rails class Application class RoutesReloader - attr_reader :route_sets - - delegate :paths, :execute_if_updated, :updated?, :to => :@updater + attr_reader :route_sets, :paths + delegate :execute_if_updated, :updated?, :to => :@updater def initialize(updater=ActiveSupport::FileUpdateChecker) - @updater = updater.new([]) { reload! } + @paths = [] + @updater = updater.new(paths) { reload! } @route_sets = [] end -- cgit v1.2.3 From 80256abb39332dd49996b909d6f0413a15291a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 11:23:21 +0100 Subject: FileUpdateChecker should be able to handle deleted files. --- railties/lib/rails/application.rb | 2 +- railties/lib/rails/application/finisher.rb | 7 +++---- railties/lib/rails/application/routes_reloader.rb | 15 +++++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 75f2b9a3bd..22689cc278 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -124,7 +124,7 @@ module Rails dirs[path.to_s] = [:rb] end - files << dirs + [files, dirs] end # Initialize the application passing the given group. By default, the diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 064723c1e0..2ce2980b97 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -64,10 +64,9 @@ module Rails # routes added in the hook are still loaded. initializer :set_routes_reloader_hook do reloader = routes_reloader - hook = lambda { reloader.execute_if_updated } - hook.call + reloader.execute_if_updated self.reloaders << reloader - ActionDispatch::Reloader.to_prepare(&hook) + ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated } end # Set app reload just after the finisher hook to ensure @@ -79,7 +78,7 @@ module Rails end if config.reload_classes_only_on_change - reloader = config.file_watcher.new(watchable_args, true, &callback) + reloader = config.file_watcher.new(*watchable_args, &callback) self.reloaders << reloader # We need to set a to_prepare callback regardless of the reloader result, i.e. # models should be reloaded if any of the reloaders (i18n, routes) were updated. diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index e080481976..ef7e733ce4 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -4,11 +4,10 @@ module Rails class Application class RoutesReloader attr_reader :route_sets, :paths - delegate :execute_if_updated, :updated?, :to => :@updater + delegate :execute_if_updated, :execute, :updated?, :to => :updater - def initialize(updater=ActiveSupport::FileUpdateChecker) + def initialize @paths = [] - @updater = updater.new(paths) { reload! } @route_sets = [] end @@ -20,7 +19,15 @@ module Rails revert end - protected + private + + def updater + @updater ||= begin + updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! } + updater.execute + updater + end + end def clear! route_sets.each do |routes| -- cgit v1.2.3 From 6cbe2709d60d10b6e4f7fd7fa22517d68cc47c9f Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Wed, 14 Dec 2011 14:08:41 +0100 Subject: dbconsole: Use the app's database_configuration instead of duplicating code. --- railties/lib/rails/commands/dbconsole.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 4b0acc9d88..d425c9db6c 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -41,7 +41,7 @@ module Rails abort opt.to_s unless (0..1).include?(ARGV.size) end - unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[Rails.env] + unless config = @app.config.database_configuration[Rails.env] abort "No database is configured for the environment '#{Rails.env}'" end -- cgit v1.2.3 From e9382474fd175c0f662906e445af987ed0901ee6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 14 Dec 2011 19:09:31 -0800 Subject: =?UTF-8?q?seed=20file=20was=20already=20tested=20for=20existence.?= =?UTF-8?q?=20=E0=B2=A0=5F=E0=B2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 5c1af99fe2..fa27564c63 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -517,7 +517,7 @@ module Rails # Blog::Engine.load_seed def load_seed seed_file = paths["db/seeds"].existent.first - load(seed_file) if seed_file && File.exist?(seed_file) + load(seed_file) if seed_file end # Add configured load paths to ruby load paths and remove duplicates. -- cgit v1.2.3 From 54f60c1063551d134dc84f353a805ddbf7ac7db0 Mon Sep 17 00:00:00 2001 From: Steven Anderson Date: Thu, 15 Dec 2011 12:38:52 +0000 Subject: Added .sass-cache/ directory to the genrated gitignore in engines. --- railties/lib/rails/generators/rails/plugin_new/templates/gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore index 92bd3c614b..7833c586f3 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore +++ b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore @@ -3,4 +3,5 @@ log/*.log pkg/ <%= dummy_path %>/db/*.sqlite3 <%= dummy_path %>/log/*.log -<%= dummy_path %>/tmp/ \ No newline at end of file +<%= dummy_path %>/tmp/ +<%= dummy_path %>/.sass-cache -- cgit v1.2.3 From 283a08763495a6b3ce0b196259ee1666f2b08cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 18:48:10 +0100 Subject: Clean up the cache before the request in case we are running in the reload_classes_only_on_change schema. --- railties/lib/rails/application/finisher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 2ce2980b97..b9944bed26 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -71,7 +71,7 @@ module Rails # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_dependencies_hook, :group => :all do + initializer :set_clear_dependencies_hook, :group => :all do callback = lambda do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear -- cgit v1.2.3 From 26e7400cc5415dbce5e2c5d13da96ad8c25749e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 19:43:49 +0100 Subject: Fix diagnostics page for routing errors. --- railties/lib/rails/application.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 22689cc278..56d11d0b01 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -168,6 +168,7 @@ module Rails "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.secret_token" => config.secret_token, "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions, + "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local, "action_dispatch.logger" => Rails.logger, "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner }) -- cgit v1.2.3 From 4baf145375ee4ef712799b0c96c2aeadc5060015 Mon Sep 17 00:00:00 2001 From: Rafael Valverde Date: Thu, 15 Dec 2011 17:03:19 -0200 Subject: Fixed small typo in the Rails::Engine documentation. --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index fa27564c63..20321a502d 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -228,7 +228,7 @@ module Rails # resources :articles # end # - # The routes above will automatically point to MyEngine::ApplicationContoller. Furthermore, you don't + # The routes above will automatically point to MyEngine::ApplicationController. Furthermore, you don't # need to use longer url helpers like my_engine_articles_path. Instead, you should simply use # articles_path as you would do with your application. # -- cgit v1.2.3 From deef8dd68241cdb9826a2293bced5e2257ccea90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:29:37 +0100 Subject: Extract the rendering of public exceptions pages into a Rack app. --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 56d11d0b01..54612755b4 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -244,7 +244,7 @@ module Rails middleware.use ::Rack::MethodOverride middleware.use ::ActionDispatch::RequestId middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods - middleware.use ::ActionDispatch::ShowExceptions + middleware.use ::ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new(Rails.public_path) middleware.use ::ActionDispatch::DebugExceptions middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies -- cgit v1.2.3 From 02127e64061fc61868f085102277ac5b679e0f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:41:05 +0100 Subject: Allow a custom exceptions app to set. --- railties/lib/rails/application.rb | 2 +- railties/lib/rails/application/configuration.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 54612755b4..b20634c5a9 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -244,7 +244,7 @@ module Rails middleware.use ::Rack::MethodOverride middleware.use ::ActionDispatch::RequestId middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods - middleware.use ::ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new(Rails.public_path) + middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path) middleware.use ::ActionDispatch::DebugExceptions middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index dddf7e498f..a782441a21 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,7 +8,7 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :cache_classes, :cache_store, :consider_all_requests_local, - :dependency_loading, :file_watcher, :filter_parameters, + :dependency_loading, :exceptions_app, :file_watcher, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, @@ -40,6 +40,7 @@ module Rails @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] @reload_classes_only_on_change = true @file_watcher = ActiveSupport::FileUpdateChecker + @exceptions_app = nil @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false -- cgit v1.2.3 From 8de96949e9d3d8f0902486df343ad88401c028fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 17 Dec 2011 12:51:38 +0100 Subject: Use gem versions of sass-rails and coffee-rails. --- railties/lib/rails/generators/app_base.rb | 36 ++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 0bd39cb2cd..197b692469 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -194,16 +194,32 @@ module Rails def assets_gemfile_entry return if options[:skip_sprockets] - <<-GEMFILE.strip_heredoc.gsub(/^[ \t]*$/, '') - # Gems used only for assets and not required - # in production environments by default. - group :assets do - gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' - gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' - #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} - gem 'uglifier', '>= 1.0.3' - end - GEMFILE + + gemfile = if options.dev? || options.edge? + <<-GEMFILE + # Gems used only for assets and not required + # in production environments by default. + group :assets do + gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' + gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' + #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} + gem 'uglifier', '>= 1.0.3' + end + GEMFILE + else + <<-GEMFILE + # Gems used only for assets and not required + # in production environments by default. + group :assets do + gem 'sass-rails', '~> 3.2.0' + gem 'coffee-rails', '~> 3.2.0' + #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} + gem 'uglifier', '>= 1.0.3' + end + GEMFILE + end + + gemfile.strip_heredoc.gsub(/^[ \t]*$/, '') end def javascript_gemfile_entry -- cgit v1.2.3 From 5e68fed450f6e6c16f308bad0fc270777d1015f3 Mon Sep 17 00:00:00 2001 From: Kir Date: Tue, 13 Dec 2011 15:06:36 +0400 Subject: Rake tasks generator with test --- railties/lib/rails/generators/rails/task/USAGE | 9 +++++++++ railties/lib/rails/generators/rails/task/task_generator.rb | 12 ++++++++++++ railties/lib/rails/generators/rails/task/templates/task.rb | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 railties/lib/rails/generators/rails/task/USAGE create mode 100644 railties/lib/rails/generators/rails/task/task_generator.rb create mode 100644 railties/lib/rails/generators/rails/task/templates/task.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/task/USAGE b/railties/lib/rails/generators/rails/task/USAGE new file mode 100644 index 0000000000..dbe9bbaf08 --- /dev/null +++ b/railties/lib/rails/generators/rails/task/USAGE @@ -0,0 +1,9 @@ +Description: + Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments. + + This generates a task file in lib/tasks. + +Example: + `rails generate task feeds fetch erase add` + + Task: lib/tasks/feeds.rake \ No newline at end of file diff --git a/railties/lib/rails/generators/rails/task/task_generator.rb b/railties/lib/rails/generators/rails/task/task_generator.rb new file mode 100644 index 0000000000..8a62d9e8eb --- /dev/null +++ b/railties/lib/rails/generators/rails/task/task_generator.rb @@ -0,0 +1,12 @@ +module Rails + module Generators + class TaskGenerator < NamedBase + argument :actions, :type => :array, :default => [], :banner => "action action" + + def create_task_files + template 'task.rb', File.join('lib/tasks', "#{file_name}.rake") + end + + end + end +end diff --git a/railties/lib/rails/generators/rails/task/templates/task.rb b/railties/lib/rails/generators/rails/task/templates/task.rb new file mode 100644 index 0000000000..b7407bd6dc --- /dev/null +++ b/railties/lib/rails/generators/rails/task/templates/task.rb @@ -0,0 +1,8 @@ +namespace :<%= file_name %> do +<% actions.each do |action| -%> + desc "TODO" + task :<%= action %> => :environment do + end + +<% end -%> +end -- cgit v1.2.3 From 1e941dde7c766fe298c1005139541c91a9f1434b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 19 Dec 2011 18:27:19 -0600 Subject: Add an invitation to use jbuilder, since we are not going to bundle it in 3.2 --- railties/lib/rails/generators/rails/app/templates/Gemfile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index c260cc999b..082642d5cd 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -13,6 +13,9 @@ source 'https://rubygems.org' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' +# To use Jbuilder templates for JSON +# gem 'jbuilder' + # Use unicorn as the web server # gem 'unicorn' -- cgit v1.2.3 From 9d6e52b55ec67d0573a0bb1900b13f38e18f7eba Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 19 Dec 2011 18:34:57 -0600 Subject: Party like its R-C-UNO! --- railties/lib/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index 254227ecf7..9844cbe34b 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -3,7 +3,7 @@ module Rails MAJOR = 3 MINOR = 2 TINY = 0 - PRE = "beta" + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end -- cgit v1.2.3 From 572c3d517899524c2a7c4c84ad9646660168d4cd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Dec 2011 18:41:37 -0800 Subject: * BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger from Ruby stdlib. --- railties/lib/rails.rb | 1 - railties/lib/rails/application/bootstrap.rb | 8 ++++---- railties/lib/rails/performance_test_help.rb | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 73bdd0b552..04c7415f3f 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -5,7 +5,6 @@ require 'pathname' require 'active_support' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/logger' require 'rails/application' require 'rails/version' diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index e189009cc5..78d2e6c913 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -33,13 +33,13 @@ module Rails f.sync = !Rails.env.production? # make sure every write flushes logger = ActiveSupport::TaggedLogging.new( - ActiveSupport::BufferedLogger.new(f) + ActiveSupport::Logger.new(f) ) - logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) + logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase) logger rescue StandardError - logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR)) - logger.level = ActiveSupport::BufferedLogger::WARN + logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR)) + logger.level = ActiveSupport::Logger::WARN logger.warn( "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " + "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed." diff --git a/railties/lib/rails/performance_test_help.rb b/railties/lib/rails/performance_test_help.rb index 4ac38981d0..b1285efde2 100644 --- a/railties/lib/rails/performance_test_help.rb +++ b/railties/lib/rails/performance_test_help.rb @@ -1,3 +1,3 @@ ActionController::Base.perform_caching = true ActiveSupport::Dependencies.mechanism = :require -Rails.logger.level = ActiveSupport::BufferedLogger::INFO +Rails.logger.level = ActiveSupport::Logger::INFO -- cgit v1.2.3 From 22cb97ba5c1d02398d94d91bbdcce386fca11770 Mon Sep 17 00:00:00 2001 From: Jo Liss Date: Tue, 20 Dec 2011 16:08:01 +0100 Subject: Add db/*.sqlite3-journal to .gitignore These can pop up while the SQLite DB is being written to. --- railties/lib/rails/generators/rails/app/templates/gitignore | 1 + railties/lib/rails/generators/rails/plugin_new/templates/gitignore | 1 + 2 files changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index eb3489a986..8910bf5a06 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -9,6 +9,7 @@ # Ignore the default SQLite database. /db/*.sqlite3 +/db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/*.log diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore index 7833c586f3..458b2c662e 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore +++ b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore @@ -2,6 +2,7 @@ log/*.log pkg/ <%= dummy_path %>/db/*.sqlite3 +<%= dummy_path %>/db/*.sqlite3-journal <%= dummy_path %>/log/*.log <%= dummy_path %>/tmp/ <%= dummy_path %>/.sass-cache -- cgit v1.2.3 From 632fa15fa4ceec6dbb00bf26da249d3039749f50 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 20 Dec 2011 09:30:37 -0600 Subject: rails/master is now 4.0.0.beta and will only support Ruby 1.9.3+ --- railties/lib/rails/version.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index 9844cbe34b..ec878f9dcf 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -1,9 +1,9 @@ module Rails module VERSION #:nodoc: - MAJOR = 3 - MINOR = 2 + MAJOR = 4 + MINOR = 0 TINY = 0 - PRE = "rc1" + PRE = "beta" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end -- cgit v1.2.3 From 4fa615a8661eb13d4bd8a7de4d839e9883ef26ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 16:53:44 +0100 Subject: Update ruby_version_check. --- railties/lib/rails/ruby_version_check.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb index 4d57c5973c..4536fedaa3 100644 --- a/railties/lib/rails/ruby_version_check.rb +++ b/railties/lib/rails/ruby_version_check.rb @@ -1,23 +1,13 @@ -if RUBY_VERSION < '1.8.7' +if RUBY_VERSION < '1.9.3' desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})" abort <<-end_message - Rails 3 requires Ruby 1.8.7 or 1.9.2. + Rails 4 requires Ruby 1.9.3+. You're running #{desc} Please upgrade to continue. - end_message -elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2' - $stderr.puts <<-end_message - - Rails 3 doesn't officially support Ruby 1.9.1 since recent stable - releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2. - - You're running - #{RUBY_DESCRIPTION} - end_message end -- cgit v1.2.3 From 9cf38be008aff555b3aecc53a6f18800cea30a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 17:51:26 +0100 Subject: Get rid of --old-style-hash --- railties/lib/rails/generators/app_base.rb | 12 ++---------- railties/lib/rails/generators/named_base.rb | 3 --- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 197b692469..ab699e4c9e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -60,9 +60,6 @@ module Rails class_option :help, :type => :boolean, :aliases => "-h", :group => :rails, :desc => "Show this help message and quit" - - class_option :old_style_hash, :type => :boolean, :default => false, - :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9" end def initialize(*args) @@ -255,14 +252,9 @@ module Rails create_file("#{destination}/.gitkeep") unless options[:skip_git] end - # Returns Ruby 1.9 style key-value pair if current code is running on - # Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise. + # Returns Ruby 1.9 style key-value pair. def key_value(key, value) - if options[:old_style_hash] || RUBY_VERSION < '1.9' - ":#{key} => #{value}" - else - "#{key}: #{value}" - end + "#{key}: #{value}" end end end diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index c6c0392f43..547b31cf7b 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -9,9 +9,6 @@ module Rails class_option :skip_namespace, :type => :boolean, :default => false, :desc => "Skip namespace (affects only isolated applications)" - class_option :old_style_hash, :type => :boolean, :default => false, - :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9" - def initialize(args, *options) #:nodoc: @inside_template = nil # Unfreeze name in case it's given as a frozen string -- cgit v1.2.3 From 51095be1b08b1dd2a8a049f009bac6220fa7a68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 17:58:45 +0100 Subject: Get rid of more 1.8.x dead code --- railties/lib/rails.rb | 15 +++------------ railties/lib/rails/commands/plugin.rb | 2 +- railties/lib/rails/generators/app_base.rb | 6 +----- railties/lib/rails/generators/named_base.rb | 9 ++------- railties/lib/rails/generators/rails/app/templates/Gemfile | 1 - 5 files changed, 7 insertions(+), 26 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 04c7415f3f..658756ad51 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -12,19 +12,10 @@ require 'rails/version' require 'active_support/railtie' require 'action_dispatch/railtie' -# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the -# multibyte safe operations. Plugin authors supporting other encodings -# should override this behavior and set the relevant +default_charset+ -# on ActionController::Base. -# # For Ruby 1.9, UTF-8 is the default internal and external encoding. -if RUBY_VERSION < '1.9' - $KCODE='u' -else - silence_warnings do - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 - end +silence_warnings do + Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 end module Rails diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index c99a2e6685..4ddd12ae0b 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -478,7 +478,7 @@ class RecursiveHTTPFetcher def initialize(urls_to_fetch, level = 1, cwd = ".") @level = level @cwd = cwd - @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a + @urls_to_fetch = urls_to_fetch.lines @quiet = false end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ab699e4c9e..0ed1eb4af8 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -182,11 +182,7 @@ module Rails end def ruby_debugger_gemfile_entry - if RUBY_VERSION < "1.9" - "gem 'ruby-debug'" - else - "gem 'ruby-debug19', :require => 'ruby-debug'" - end + "gem 'ruby-debug19', :require => 'ruby-debug'" end def assets_gemfile_entry diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 547b31cf7b..e96fc63ee9 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -182,14 +182,9 @@ module Rails end end - # Returns Ruby 1.9 style key-value pair if current code is running on - # Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise. + # Returns Ruby 1.9 style key-value pair. def key_value(key, value) - if options[:old_style_hash] || RUBY_VERSION < '1.9' - ":#{key} => #{value}" - else - "#{key}: #{value}" - end + "#{key}: #{value}" end end end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 082642d5cd..60ea394d2f 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -5,7 +5,6 @@ source 'https://rubygems.org' <%= database_gemfile_entry -%> <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%> -<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> <%= assets_gemfile_entry %> <%= javascript_gemfile_entry %> -- cgit v1.2.3 From 568777bcd0c615b867d06436a7127e0d97ab5826 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Tue, 20 Dec 2011 23:55:57 +0530 Subject: It should be README.rdoc fixes #4067 --- railties/lib/rails/tasks/documentation.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 1e7da5ccae..1c28b2c8e6 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -63,7 +63,7 @@ namespace :doc do rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.title = "Rails Framework Documentation" rdoc.options << '--line-numbers' - rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('README.rdoc') gem_path('actionmailer') do |actionmailer| %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_mailer/base.rb).each do |file| -- cgit v1.2.3 From c7a485a289984aac1a723c6a3bce0f6ff03b93b2 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Tue, 20 Dec 2011 18:32:01 +0000 Subject: Added Capistrano to the development group in Gemfile There's no need for Capistrano to be install on a server, the extra argument in the comment implies this now. --- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 082642d5cd..2c7021e6e9 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -20,7 +20,7 @@ source 'https://rubygems.org' # gem 'unicorn' # Deploy with Capistrano -# gem 'capistrano' +# gem 'capistrano', :group => :development # To use debugger # <%= ruby_debugger_gemfile_entry %> -- cgit v1.2.3 From 482ec2ac3f518c91544a3b3e92765eef41b91419 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 20 Dec 2011 20:17:17 +0100 Subject: Add ORIGINAL_FULLPATH to env This behaves similarly to REQUEST_URI, but we need to implement it on our own because REQUEST_URI is not reliable. Note that since PATH_INFO does not contain information about trailing question mark, this is not 100% accurate, for example `/foo?` will result in `/foo` in ORIGINAL_FULLPATH --- railties/lib/rails/application.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b20634c5a9..19e8426e60 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -215,6 +215,11 @@ module Rails config.helpers_paths end + def call(env) + env["ORIGINAL_FULLPATH"] = build_original_fullpath(env) + super(env) + end + protected alias :build_middleware_stack :app @@ -291,5 +296,17 @@ module Rails require "rails/console/app" require "rails/console/helpers" end + + def build_original_fullpath(env) + path_info = env["PATH_INFO"] + query_string = env["QUERY_STRING"] + script_name = env["SCRIPT_NAME"] + + if query_string.present? + "#{script_name}#{path_info}?#{query_string}" + else + "#{script_name}#{path_info}" + end + end end end -- cgit v1.2.3 From fc7e5db90a97613506356d0d99b072acdb0b195a Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Wed, 21 Dec 2011 00:56:49 -0800 Subject: Doc fixes on Rails::Generators::Base.hook_for. --- railties/lib/rails/generators/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index f38a487a4e..af743a9c51 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -128,13 +128,13 @@ module Rails # # ==== Boolean hooks # - # In some cases, you want to provide a boolean hook. For example, webrat + # In some cases, you may want to provide a boolean hook. For example, webrat # developers might want to have webrat available on controller generator. # This can be achieved as: # # Rails::Generators::ControllerGenerator.hook_for :webrat, :type => :boolean # - # Then, if you want, webrat to be invoked, just supply: + # Then, if you want webrat to be invoked, just supply: # # rails generate controller Account --webrat # @@ -146,7 +146,7 @@ module Rails # # You can also supply a block to hook_for to customize how the hook is # going to be invoked. The block receives two arguments, an instance - # of the current class and the klass to be invoked. + # of the current class and the class to be invoked. # # For example, in the resource generator, the controller should be invoked # with a pluralized class name. But by default it is invoked with the same -- cgit v1.2.3 From 14c89e7285d4e7cd40a542fbc31d9345f60c3aa4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Dec 2011 08:15:36 -0700 Subject: Rails::SubTestTask warns on test failure and moves on. Renamed from TestTaskWithoutDescription. This makes it easier to add your own tests to the default suite: task test: 'test:acceptance' namespace :test do Rails::SubTestTask.new acceptance: 'test:prepare' do |t| t.libs << 'test' t.pattern = 'test/acceptance/**/*_test.rb' end end Now `rake` runs unit, functional, integration, and acceptance tests. --- railties/lib/rails/test_unit/testing.rake | 83 ++++++++++++++----------------- 1 file changed, 38 insertions(+), 45 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 52d92cdd96..cf86cf67f2 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,32 +1,40 @@ require 'rbconfig' require 'rake/testtask' -# Monkey-patch to silence the description from Rake::TestTask to cut down on rake -T noise -class TestTaskWithoutDescription < Rake::TestTask - # Create the tasks defined by this task lib. - def define - lib_path = @libs.join(File::PATH_SEPARATOR) - task @name do - run_code = '' - RakeFileUtils.verbose(@verbose) do - run_code = - case @loader - when :direct - "-e 'ARGV.each{|f| load f}'" - when :testrb - "-S testrb #{fix}" - when :rake - rake_loader +module Rails + # Don't abort when tests fail; move on the next test task. + # Silence the default description to cut down on `rake -T` noise. + class SubTestTask < Rake::TestTask + # Create the tasks defined by this task lib. + def define + lib_path = @libs.join(File::PATH_SEPARATOR) + task @name do + run_code = '' + RakeFileUtils.verbose(@verbose) do + run_code = + case @loader + when :direct + "-e 'ARGV.each{|f| load f}'" + when :testrb + "-S testrb #{fix}" + when :rake + rake_loader + end + @ruby_opts.unshift( "-I\"#{lib_path}\"" ) + @ruby_opts.unshift( "-w" ) if @warning + + begin + ruby @ruby_opts.join(" ") + + " \"#{run_code}\" " + + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + + " #{option_list}" + rescue => error + warn "Error running #{@name}: #{error.inspect}" end - @ruby_opts.unshift( "-I\"#{lib_path}\"" ) - @ruby_opts.unshift( "-w" ) if @warning - ruby @ruby_opts.join(" ") + - " \"#{run_code}\" " + - file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + - " #{option_list}" + end end + self end - self end end @@ -75,22 +83,7 @@ end task :default => :test desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)' -task :test do - tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units test:functionals test:integration) - errors = tests_to_run.collect do |task| - begin - Rake::Task[task].invoke - nil - rescue => e - { :task => task, :exception => e } - end - end.compact - - if errors.any? - puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n") - abort - end -end +task :test => %w(test:units test:functionals test:integration) namespace :test do task :prepare do @@ -134,33 +127,33 @@ namespace :test do t.libs << "test" end - TestTaskWithoutDescription.new(:units => "test:prepare") do |t| + Rails::SubTestTask.new(:units => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/unit/**/*_test.rb' end - TestTaskWithoutDescription.new(:functionals => "test:prepare") do |t| + Rails::SubTestTask.new(:functionals => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/functional/**/*_test.rb' end - TestTaskWithoutDescription.new(:integration => "test:prepare") do |t| + Rails::SubTestTask.new(:integration => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/integration/**/*_test.rb' end - TestTaskWithoutDescription.new(:benchmark => 'test:prepare') do |t| + Rails::SubTestTask.new(:benchmark => 'test:prepare') do |t| t.libs << 'test' t.pattern = 'test/performance/**/*_test.rb' t.options = '-- --benchmark' end - TestTaskWithoutDescription.new(:profile => 'test:prepare') do |t| + Rails::SubTestTask.new(:profile => 'test:prepare') do |t| t.libs << 'test' t.pattern = 'test/performance/**/*_test.rb' end - TestTaskWithoutDescription.new(:plugins => :environment) do |t| + Rails::SubTestTask.new(:plugins => :environment) do |t| t.libs << "test" if ENV['PLUGIN'] -- cgit v1.2.3 From 4f629ed4bbb8902e8905dee3069edb1cd7e693b6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Dec 2011 10:10:35 -0700 Subject: Restore `rake TEST=test/unit/foo_test.rb` support. Add your own test tasks as dependencies on the `test:run` task instead of `test` itself. namespace :test do task run: 'test:acceptance' Rails::SubTestTask.new acceptance: 'test:prepare' do |t| t.libs << 'test' t.pattern = 'test/acceptance/**/*_test.rb' end end --- railties/lib/rails/test_unit/testing.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index cf86cf67f2..62c8de8d22 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -83,13 +83,17 @@ end task :default => :test desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)' -task :test => %w(test:units test:functionals test:integration) +task :test do + Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke +end namespace :test do task :prepare do # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example. end + task :run => %w(test:units test:functionals test:integration) + Rake::TestTask.new(:recent => "test:prepare") do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + -- cgit v1.2.3 From 5a4b41443c09c1d1f5c996afe0838391b2e2c5f2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Dec 2011 12:43:41 -0700 Subject: Move SubTestTask. Soften up tests. --- railties/lib/rails/test_unit/sub_test_task.rb | 36 +++++++++++++++++++++++++ railties/lib/rails/test_unit/testing.rake | 39 +-------------------------- 2 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 railties/lib/rails/test_unit/sub_test_task.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/sub_test_task.rb b/railties/lib/rails/test_unit/sub_test_task.rb new file mode 100644 index 0000000000..284c70050f --- /dev/null +++ b/railties/lib/rails/test_unit/sub_test_task.rb @@ -0,0 +1,36 @@ +module Rails + # Don't abort when tests fail; move on the next test task. + # Silence the default description to cut down on `rake -T` noise. + class SubTestTask < Rake::TestTask + # Create the tasks defined by this task lib. + def define + lib_path = @libs.join(File::PATH_SEPARATOR) + task @name do + run_code = '' + RakeFileUtils.verbose(@verbose) do + run_code = + case @loader + when :direct + "-e 'ARGV.each{|f| load f}'" + when :testrb + "-S testrb #{fix}" + when :rake + rake_loader + end + @ruby_opts.unshift( "-I\"#{lib_path}\"" ) + @ruby_opts.unshift( "-w" ) if @warning + + begin + ruby @ruby_opts.join(" ") + + " \"#{run_code}\" " + + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + + " #{option_list}" + rescue => error + warn "Error running #{name}: #{error.inspect}" + end + end + end + self + end + end +end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 62c8de8d22..a23d22d607 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,43 +1,6 @@ require 'rbconfig' require 'rake/testtask' - -module Rails - # Don't abort when tests fail; move on the next test task. - # Silence the default description to cut down on `rake -T` noise. - class SubTestTask < Rake::TestTask - # Create the tasks defined by this task lib. - def define - lib_path = @libs.join(File::PATH_SEPARATOR) - task @name do - run_code = '' - RakeFileUtils.verbose(@verbose) do - run_code = - case @loader - when :direct - "-e 'ARGV.each{|f| load f}'" - when :testrb - "-S testrb #{fix}" - when :rake - rake_loader - end - @ruby_opts.unshift( "-I\"#{lib_path}\"" ) - @ruby_opts.unshift( "-w" ) if @warning - - begin - ruby @ruby_opts.join(" ") + - " \"#{run_code}\" " + - file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + - " #{option_list}" - rescue => error - warn "Error running #{@name}: #{error.inspect}" - end - end - end - self - end - end -end - +require 'rails/test_unit/sub_test_task' TEST_CHANGES_SINCE = Time.now - 600 -- cgit v1.2.3 From 4f6af26a886630c97865a2e5023a9560692e6aa4 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Tue, 20 Dec 2011 22:18:23 +0300 Subject: remove AS whiny nil extension and deprecate config.whiny_nils --- railties/lib/rails/application/configuration.rb | 7 ++++++- .../rails/app/templates/config/environments/development.rb.tt | 3 --- .../generators/rails/app/templates/config/environments/test.rb.tt | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a782441a21..d14cf737d9 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -12,7 +12,7 @@ module Rails :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :reload_classes_only_on_change, :whiny_nils + :time_zone, :reload_classes_only_on_change attr_writer :log_level attr_reader :encoding @@ -145,6 +145,11 @@ module Rails @session_options = args.shift || {} end end + + def whiny_nils=(*) + ActiveSupport::Deprecation.warn "config.whiny_nils option " \ + "is deprecated and no longer works", caller + end end end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 9e53b6a70d..a1d41fd7dd 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -6,9 +6,6 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 37a8b81dad..86016da189 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -11,9 +11,6 @@ config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false -- cgit v1.2.3 From 2adc145264c5c30499d8837bf32536171aefca9a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 22 Dec 2011 10:55:38 -0700 Subject: Depend on 4.0.0.beta gems. Use https for github urls. --- railties/lib/rails/generators/app_base.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 0ed1eb4af8..046b8f3925 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -135,21 +135,21 @@ module Rails if options.dev? <<-GEMFILE.strip_heredoc gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}' - gem 'journey', :git => 'git://github.com/rails/journey.git' - gem 'arel', :git => 'git://github.com/rails/arel.git' + gem 'journey', :git => 'https://github.com/rails/journey.git' + gem 'arel', :git => 'https://github.com/rails/arel.git' GEMFILE elsif options.edge? <<-GEMFILE.strip_heredoc - gem 'rails', :git => 'git://github.com/rails/rails.git' - gem 'journey', :git => 'git://github.com/rails/journey.git' - gem 'arel', :git => 'git://github.com/rails/arel.git' + gem 'rails', :git => 'https://github.com/rails/rails.git' + gem 'journey', :git => 'https://github.com/rails/journey.git' + gem 'arel', :git => 'https://github.com/rails/arel.git' GEMFILE else <<-GEMFILE.strip_heredoc gem 'rails', '#{Rails::VERSION::STRING}' # Bundle edge Rails instead: - # gem 'rails', :git => 'git://github.com/rails/rails.git' + # gem 'rails', :git => 'https://github.com/rails/rails.git' GEMFILE end end @@ -193,8 +193,8 @@ module Rails # Gems used only for assets and not required # in production environments by default. group :assets do - gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' - gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' + gem 'sass-rails', :git => 'https://github.com/rails/sass-rails.git' + gem 'coffee-rails', :git => 'https://github.com/rails/coffee-rails.git' #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} gem 'uglifier', '>= 1.0.3' end @@ -204,8 +204,8 @@ module Rails # Gems used only for assets and not required # in production environments by default. group :assets do - gem 'sass-rails', '~> 3.2.0' - gem 'coffee-rails', '~> 3.2.0' + gem 'sass-rails', '~> 4.0.0.beta' + gem 'coffee-rails', '~> 4.0.0.beta' #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)} gem 'uglifier', '>= 1.0.3' end -- cgit v1.2.3 From 7a47f362c8246c20437f49111e5dcc0781d6d024 Mon Sep 17 00:00:00 2001 From: Dmitrii Samoilov Date: Wed, 17 Aug 2011 12:16:04 +0300 Subject: added ability to specify from cli when generating a model/migration whether particular property should be an index like this 'rails g model person name:string:index profile:string' --- .../lib/rails/generators/generated_attribute.rb | 52 ++++++++++++++++++++-- railties/lib/rails/generators/named_base.rb | 5 +-- .../rails/migration/migration_generator.rb | 2 +- .../generators/rails/model/model_generator.rb | 2 +- railties/lib/rails/generators/test_case.rb | 2 +- 5 files changed, 53 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 816d82cac3..5ba37737a2 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -4,11 +4,10 @@ require 'active_support/core_ext/object/inclusion' module Rails module Generators class GeneratedAttribute - attr_accessor :name, :type + attr_accessor :name, :type, :has_index, :attr_options - def initialize(name, type) - type = :string if type.blank? - @name, @type = name, type.to_sym + def initialize(column_definition) + parse column_definition end def field_type @@ -48,6 +47,51 @@ module Rails def reference? self.type.in?([:references, :belongs_to]) end + + def has_index? + @has_index + end + + def has_uniq_index? + @has_uniq_index + end + + def parse(column_definition) + name, type, has_index = column_definition.split(':') + # if user provided "name:index" instead of "name:string:index" type should be set blank + # so GeneratedAttribute's constructor could set it to :string + if type =~ /index|uniq|unique/i + has_index = type + type = nil + end + type = :string if type.blank? + + @name = name + @type, @attr_options = *parse_type_and_options(type) + @has_index = ['index','uniq','unique'].include?(has_index) + @has_uniq_index = ['uniq','unique'].include?(has_index) + end + + # parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals + # when declaring options curly brackets should be used + def parse_type_and_options(type) + attribute_options = case type + when /(string|text|binary|integer){(\d+)}/ + {:limit => $2.to_i} + when /decimal{(\d+),(\d+)}/ + {:precision => $1.to_i, :scale => $2.to_i} + else; {} + end + [type.to_s.gsub(/{.*}/,'').to_sym, attribute_options] + end + + def inject_options + @attr_options.blank? ? '' : ", #{@attr_options.to_s.gsub(/[{}]/, '')}" + end + + def inject_index_options + has_uniq_index? ? ", :unique => true" : '' + end end end end diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index e96fc63ee9..baf7cb7dca 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -150,9 +150,8 @@ module Rails # Convert attributes array into GeneratedAttribute objects. def parse_attributes! #:nodoc: - self.attributes = (attributes || []).map do |key_value| - name, type = key_value.split(':') - Rails::Generators::GeneratedAttribute.new(name, type) + self.attributes = (attributes || []).map do |attr| + Rails::Generators::GeneratedAttribute.new(attr) end end diff --git a/railties/lib/rails/generators/rails/migration/migration_generator.rb b/railties/lib/rails/generators/rails/migration/migration_generator.rb index 39fa5b63b1..ecf0a77b76 100644 --- a/railties/lib/rails/generators/rails/migration/migration_generator.rb +++ b/railties/lib/rails/generators/rails/migration/migration_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class MigrationGenerator < NamedBase #metagenerator - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type field:type:index" hook_for :orm, :required => true end end diff --git a/railties/lib/rails/generators/rails/model/model_generator.rb b/railties/lib/rails/generators/rails/model/model_generator.rb index 629d5eed3f..2a882981c3 100644 --- a/railties/lib/rails/generators/rails/model/model_generator.rb +++ b/railties/lib/rails/generators/rails/model/model_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class ModelGenerator < NamedBase #metagenerator - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type field:type:index" hook_for :orm, :required => true end end diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 7319fb79f6..ab55031d07 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -219,7 +219,7 @@ module Rails # create_generated_attribute(:string, 'name') # def create_generated_attribute(attribute_type, name = 'test') - Rails::Generators::GeneratedAttribute.new(name, attribute_type.to_s) + Rails::Generators::GeneratedAttribute.new([name, attribute_type.to_s].join(':')) end protected -- cgit v1.2.3 From b4e97ea2d961c7ed99dcfa48044f4922378ff9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 10:38:19 +0100 Subject: Tidy up migration types. --- .../lib/rails/generators/generated_attribute.rb | 76 ++++++++++++---------- railties/lib/rails/generators/named_base.rb | 2 +- .../rails/migration/migration_generator.rb | 2 +- .../generators/rails/model/model_generator.rb | 2 +- railties/lib/rails/generators/rails/scaffold/USAGE | 24 ++++--- railties/lib/rails/generators/test_case.rb | 4 +- 6 files changed, 63 insertions(+), 47 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 5ba37737a2..132145474b 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -1,13 +1,48 @@ require 'active_support/time' require 'active_support/core_ext/object/inclusion' +require 'active_support/core_ext/object/blank' module Rails module Generators class GeneratedAttribute - attr_accessor :name, :type, :has_index, :attr_options + attr_accessor :name, :type + attr_reader :attr_options - def initialize(column_definition) - parse column_definition + class << self + def parse(column_definition) + name, type, has_index = column_definition.split(':') + + # if user provided "name:index" instead of "name:string:index" + # type should be set blank so GeneratedAttribute's constructor + # could set it to :string + has_index, type = type, nil if %w(index uniq).include?(type) + + type, attr_options = *parse_type_and_options(type) + new(name, type, has_index, attr_options) + end + + private + + # parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals + # when declaring options curly brackets should be used + def parse_type_and_options(type) + case type + when /(string|text|binary|integer){(\d+)}/ + return $1, :limit => $2.to_i + when /decimal{(\d+),(\d+)}/ + return :decimal, :precision => $1.to_i, :scale => $2.to_i + else + return type, {} + end + end + end + + def initialize(name, type=nil, index_type=false, attr_options={}) + @name = name + @type = (type.presence || :string).to_sym + @has_index = %w(index uniq).include?(index_type) + @has_uniq_index = %w(uniq).include?(index_type) + @attr_options = attr_options end def field_type @@ -44,10 +79,14 @@ module Rails name.to_s.humanize end + def index_name + reference? ? "#{name}_id" : name + end + def reference? self.type.in?([:references, :belongs_to]) end - + def has_index? @has_index end @@ -56,35 +95,6 @@ module Rails @has_uniq_index end - def parse(column_definition) - name, type, has_index = column_definition.split(':') - # if user provided "name:index" instead of "name:string:index" type should be set blank - # so GeneratedAttribute's constructor could set it to :string - if type =~ /index|uniq|unique/i - has_index = type - type = nil - end - type = :string if type.blank? - - @name = name - @type, @attr_options = *parse_type_and_options(type) - @has_index = ['index','uniq','unique'].include?(has_index) - @has_uniq_index = ['uniq','unique'].include?(has_index) - end - - # parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals - # when declaring options curly brackets should be used - def parse_type_and_options(type) - attribute_options = case type - when /(string|text|binary|integer){(\d+)}/ - {:limit => $2.to_i} - when /decimal{(\d+),(\d+)}/ - {:precision => $1.to_i, :scale => $2.to_i} - else; {} - end - [type.to_s.gsub(/{.*}/,'').to_sym, attribute_options] - end - def inject_options @attr_options.blank? ? '' : ", #{@attr_options.to_s.gsub(/[{}]/, '')}" end diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index baf7cb7dca..9cef55e0a6 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -151,7 +151,7 @@ module Rails # Convert attributes array into GeneratedAttribute objects. def parse_attributes! #:nodoc: self.attributes = (attributes || []).map do |attr| - Rails::Generators::GeneratedAttribute.new(attr) + Rails::Generators::GeneratedAttribute.parse(attr) end end diff --git a/railties/lib/rails/generators/rails/migration/migration_generator.rb b/railties/lib/rails/generators/rails/migration/migration_generator.rb index ecf0a77b76..f87dce1502 100644 --- a/railties/lib/rails/generators/rails/migration/migration_generator.rb +++ b/railties/lib/rails/generators/rails/migration/migration_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class MigrationGenerator < NamedBase #metagenerator - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type field:type:index" + argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" hook_for :orm, :required => true end end diff --git a/railties/lib/rails/generators/rails/model/model_generator.rb b/railties/lib/rails/generators/rails/model/model_generator.rb index 2a882981c3..9bb29b784e 100644 --- a/railties/lib/rails/generators/rails/model/model_generator.rb +++ b/railties/lib/rails/generators/rails/model/model_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class ModelGenerator < NamedBase #metagenerator - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type field:type:index" + argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" hook_for :orm, :required => true end end diff --git a/railties/lib/rails/generators/rails/scaffold/USAGE b/railties/lib/rails/generators/rails/scaffold/USAGE index be1d113ed8..4a3eb2c7c7 100644 --- a/railties/lib/rails/generators/rails/scaffold/USAGE +++ b/railties/lib/rails/generators/rails/scaffold/USAGE @@ -7,23 +7,29 @@ Description: under_scored, as the first argument, and an optional list of attribute pairs. - Attribute pairs are field:type arguments specifying the - model's attributes. Timestamps are added by default, so you don't have to - specify them by hand as 'created_at:datetime updated_at:datetime'. + Attributes are field arguments specifying the model's attributes. You can + optionally pass the type and an index to each field. For instance: + "title body:text tracking_id:integer:uniq" will generate a title field of + string type, a body with text type and a tracking_id as an integer with an + unique index. "index" could also be given instead of "uniq" if one desires + a non unique index. + + Timestamps are added by default, so you don't have to specify them by hand + as 'created_at:datetime updated_at:datetime'. You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately. - For example, 'scaffold post title:string body:text published:boolean' - gives you a model with those three attributes, a controller that handles + For example, 'scaffold post title body:text published:boolean' gives + you a model with those three attributes, a controller that handles the create/show/update/destroy, forms to create and edit your posts, and - an index that lists them all, as well as a resources :posts - declaration in config/routes.rb. + an index that lists them all, as well as a resources :posts declaration + in config/routes.rb. If you want to remove all the generated files, run 'rails destroy scaffold ModelName'. Examples: `rails generate scaffold post` - `rails generate scaffold post title:string body:text published:boolean` - `rails generate scaffold purchase order_id:integer amount:decimal` + `rails generate scaffold post title body:text published:boolean` + `rails generate scaffold purchase amount:decimal tracking_id:integer:uniq` diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index ab55031d07..d81c4c3e1d 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -218,8 +218,8 @@ module Rails # # create_generated_attribute(:string, 'name') # - def create_generated_attribute(attribute_type, name = 'test') - Rails::Generators::GeneratedAttribute.new([name, attribute_type.to_s].join(':')) + def create_generated_attribute(attribute_type, name = 'test', index = nil) + Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':')) end protected -- cgit v1.2.3 From 8a04bd0c832a5fe3f248225a732db54392e38fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 12:53:27 +0100 Subject: Fix regexp intervals. --- railties/lib/rails/generators/generated_attribute.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 132145474b..964bd6280c 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -27,9 +27,9 @@ module Rails # when declaring options curly brackets should be used def parse_type_and_options(type) case type - when /(string|text|binary|integer){(\d+)}/ + when /(string|text|binary|integer)\{(\d+)\}/ return $1, :limit => $2.to_i - when /decimal{(\d+),(\d+)}/ + when /decimal\{(\d+),(\d+)\}/ return :decimal, :precision => $1.to_i, :scale => $2.to_i else return type, {} -- cgit v1.2.3 From cd2c31a1c448cef135b14017a32ebf7e00d81059 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 24 Dec 2011 15:25:22 +0530 Subject: A few doc changes --- railties/lib/rails/application.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 19e8426e60..493102a58f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -154,15 +154,8 @@ module Rails self end - # Rails.application.env_config stores some of the Rails initial environment parameters. - # Currently stores: - # - # * action_dispatch.parameter_filter" => config.filter_parameters, - # * action_dispatch.secret_token" => config.secret_token, - # * action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions - # - # These parameters will be used by middlewares and engines to configure themselves. - # + # Stores some of the Rails initial environment parameters which + # will be used by middlewares and engines to configure themselves. def env_config @env_config ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, -- cgit v1.2.3 From 5ca86ac8f924b333a5a01a47cc07cbcf39c16e80 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sat, 24 Dec 2011 15:57:54 +0300 Subject: deprecate String#encoding_aware? and remove its usage --- railties/lib/rails/application/configuration.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index d14cf737d9..79b12ad4eb 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -65,17 +65,9 @@ module Rails def encoding=(value) @encoding = value - if "ruby".encoding_aware? - silence_warnings do - Encoding.default_external = value - Encoding.default_internal = value - end - else - $KCODE = value - if $KCODE == "NONE" - raise "The value you specified for config.encoding is " \ - "invalid. The possible values are UTF8, SJIS, or EUC" - end + silence_warnings do + Encoding.default_external = value + Encoding.default_internal = value end end -- cgit v1.2.3 From 7c9bcbb5e486a5d5e35d38c5fbcbea6af88fc23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 22:06:25 +0100 Subject: Use 1.9 hash syntax instead. --- railties/lib/rails/generators/generated_attribute.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 964bd6280c..61479b9068 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -96,11 +96,11 @@ module Rails end def inject_options - @attr_options.blank? ? '' : ", #{@attr_options.to_s.gsub(/[{}]/, '')}" + "".tap { |s| @attr_options.each { |k,v| s << ", #{k}: #{v.inspect}" } } end def inject_index_options - has_uniq_index? ? ", :unique => true" : '' + has_uniq_index? ? ", unique: true" : "" end end end -- cgit v1.2.3 From 357837288f7d53440758377fe85aded557e3fb33 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sun, 25 Dec 2011 15:19:52 +0530 Subject: gem ruby-debug19 for console error if ruby-debug19 not found --- railties/lib/rails/commands/console.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 7733a8f116..3acac2a6f0 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -31,7 +31,7 @@ module Rails require 'ruby-debug' puts "=> Debugger enabled" rescue Exception - puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'" + puts "You need to install ruby-debug19 to run the console in debugging mode. With gems, use 'gem install ruby-debug19'" exit end end -- cgit v1.2.3 From 28cd098d99c52486aecb72aab39105d8abcd52ad Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 11:31:22 +0100 Subject: Correctly display rack apps with dynamic constraints in RoutesInspector If you used dynamic constraint like that: scope :constraint => MyConstraint.new do mount RackApp => "/foo" end routes were not displayed correctly when using `rake routes`. This commit fixes it. If you want nice display of dynamic constraints in `rake routes` output, please just override to_s method in your constraint's class. --- railties/lib/rails/application/route_inspector.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 26652a8e5e..3e08b78221 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -23,7 +23,7 @@ module Rails routes = routes.collect do |route| route_reqs = route.requirements - rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ + rack_app = discover_rack_app(route.app) controller = route_reqs[:controller] || ':controller' action = route_reqs[:action] || ':action' @@ -70,6 +70,15 @@ module Rails "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end + + def discover_rack_app(app) + class_name = app.class.name.to_s + if class_name == "ActionDispatch::Routing::Mapper::Constraints" + discover_rack_app(app.app) + elsif class_name !~ /^ActionDispatch::Routing/ + app + end + end end end end -- cgit v1.2.3 From 9fffef5f463d3c1f518373423c9e2044836b0de6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 16:16:17 +0100 Subject: Refactor RouteInspector --- railties/lib/rails/application/route_inspector.rb | 101 +++++++++++++++------- 1 file changed, 69 insertions(+), 32 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 3e08b78221..5ca366c5f2 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -1,5 +1,64 @@ +require 'delegate' + module Rails class Application + class RouteWrapper < SimpleDelegator + def endpoint + rack_app ? rack_app.inspect : "#{controller}##{action}" + end + + def constraints + requirements.except(:controller, :action) + end + + def rack_app(app = self.app) + @rack_app ||= begin + class_name = app.class.name.to_s + if class_name == "ActionDispatch::Routing::Mapper::Constraints" + rack_app(app.app) + elsif class_name !~ /^ActionDispatch::Routing/ + app + end + end + end + + def verb + super.source.gsub(/[$^]/, '') + end + + def path + super.spec.to_s + end + + def name + super.to_s + end + + def reqs + @reqs ||= begin + reqs = endpoint + reqs += " #{constraints.inspect}" unless constraints.empty? + reqs + end + end + + def controller + requirements[:controller] || ':controller' + end + + def action + requirements[:action] || ':action' + end + + def internal? + path =~ %r{/rails/info/properties|^/assets} + end + + def engine? + rack_app && rack_app.respond_to?(:routes) + end + end + ## # This class is just used for displaying route information when someone # executes `rake routes`. People should not use this class. @@ -21,35 +80,22 @@ module Rails def collect_routes(routes) routes = routes.collect do |route| - route_reqs = route.requirements - - rack_app = discover_rack_app(route.app) - - controller = route_reqs[:controller] || ':controller' - action = route_reqs[:action] || ':action' + RouteWrapper.new(route) + end.reject do |route| + route.internal? + end.collect do |route| + collect_engine_routes(route) - endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}" - constraints = route_reqs.except(:controller, :action) - - reqs = endpoint - reqs += " #{constraints.inspect}" unless constraints.empty? - - verb = route.verb.source.gsub(/[$^]/, '') - - collect_engine_routes(reqs, rack_app) - - {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs } + {:name => route.name, :verb => route.verb, :path => route.path, :reqs => route.reqs } end - - # Skip the route if it's internal info route - routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } end - def collect_engine_routes(name, rack_app) - return unless rack_app && rack_app.respond_to?(:routes) + def collect_engine_routes(route) + name = route.endpoint + return unless route.engine? return if @engines[name] - routes = rack_app.routes + routes = route.rack_app.routes if routes.is_a?(ActionDispatch::Routing::RouteSet) @engines[name] = collect_routes(routes.routes) end @@ -70,15 +116,6 @@ module Rails "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end - - def discover_rack_app(app) - class_name = app.class.name.to_s - if class_name == "ActionDispatch::Routing::Mapper::Constraints" - discover_rack_app(app.app) - elsif class_name !~ /^ActionDispatch::Routing/ - app - end - end end end end -- cgit v1.2.3 From 7626c0be3a379ccdac4eddcf41e2b8d9883fcf1c Mon Sep 17 00:00:00 2001 From: Tony Coconate Date: Wed, 28 Dec 2011 12:33:28 -0600 Subject: Update railties/lib/rails/generators/actions.rb --- railties/lib/rails/generators/actions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index b26839644e..8f7924a916 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -1,5 +1,6 @@ require 'open-uri' require 'rbconfig' +require 'active_support/core_ext/array/wrap' module Rails module Generators -- cgit v1.2.3 From 73f0588fd3d457b2191e9393f87262defb2c0af4 Mon Sep 17 00:00:00 2001 From: Pavel Gabriel Date: Thu, 29 Dec 2011 13:33:01 +0200 Subject: Fix rails/generators/base.rb documentation for hook_for --- railties/lib/rails/generators/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index af743a9c51..a98244c525 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -91,7 +91,7 @@ module Rails # # The lookup in this case for test_unit as input is: # - # "test_framework:awesome", "test_framework" + # "test_unit:awesome", "test_unit" # # Which is not the desired the lookup. You can change it by providing the # :as option: @@ -102,7 +102,7 @@ module Rails # # And now it will lookup at: # - # "test_framework:controller", "test_framework" + # "test_unit:controller", "test_unit" # # Similarly, if you want it to also lookup in the rails namespace, you just # need to provide the :base value: @@ -113,7 +113,7 @@ module Rails # # And the lookup is exactly the same as previously: # - # "rails:test_framework", "test_framework:controller", "test_framework" + # "rails:test_unit", "test_unit:controller", "test_unit" # # ==== Switches # -- cgit v1.2.3