diff options
Diffstat (limited to 'railties')
17 files changed, 95 insertions, 95 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 8c2b64d543..a422c5fe39 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* `Rails.public_path` now returns a Pathname object. *Prem Sichanugrist* + * Remove highly uncommon `config.assets.manifest` option for moving the manifest path. This option is now unsupported in sprockets-rails. diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index a15965a9da..d7e22cc839 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -127,7 +127,7 @@ module Rails end def public_path - application && application.paths["public"].first + application && Pathname.new(application.paths["public"].first) end end end diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0b9ed025db..b30e6ff615 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -101,6 +101,14 @@ module Rails routes_reloader.reload! end + + # Return the application's KeyGenerator + def key_generator + # number of iterations selected based on consultation with the google security + # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220 + @key_generator ||= ActiveSupport::KeyGenerator.new(config.secret_token, :iterations=>1000) + end + # Stores some of the Rails initial environment parameters which # will be used by middlewares and engines to configure themselves. # Currently stores: @@ -121,7 +129,8 @@ module Rails "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 + "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner, + "action_dispatch.key_generator" => key_generator }) end @@ -288,6 +297,15 @@ module Rails error.message << ' Be sure to add rack-cache to your Gemfile' raise end + + if rack_cache == true + rack_cache = { + :metastore => "rails:/", + :entitystore => "rails:/", + :verbose => false + } + end + require "action_dispatch/http/rack_cache" middleware.use ::Rack::Cache, rack_cache end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 184c59cb90..44c6507b08 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -154,10 +154,8 @@ module Rails GEMFILE else <<-GEMFILE.strip_heredoc + # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '#{Rails::VERSION::STRING}' - - # Bundle edge Rails instead: - # gem 'rails', github: 'rails/rails' GEMFILE end end @@ -226,7 +224,14 @@ module Rails end def javascript_gemfile_entry - "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript] + unless options[:skip_javascript] + <<-GEMFILE.strip_heredoc + gem '#{options[:javascript]}-rails' + + # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks + gem 'turbolinks' + GEMFILE + end end def javascript_runtime_gemfile_entry diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 69027f2903..e5aa153e29 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -9,14 +9,13 @@ source 'https://rubygems.org' <%= assets_gemfile_entry %> <%= javascript_gemfile_entry %> -# Puts a simple HTTP cache in front of your app. -# For large-scale production use, consider using a caching reverse proxy like nginx, varnish, or squid. -gem 'rack-cache', '~> 1.2' +# Puts a simple HTTP cache in front of your app (and gets you ready for later upgrading to nginx/varnish/squid) +# gem 'rack-cache', '~> 1.2' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' -# To use Jbuilder templates for JSON +# Build JSON APIs with ease. Read more: http://github.com/rails/jbuilder # gem 'jbuilder' # Use unicorn as the app server diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index f33a7f4ac2..7342bffd9d 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -5,7 +5,7 @@ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. +// compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. @@ -13,5 +13,6 @@ <% unless options[:skip_javascript] -%> //= require <%= options[:javascript] %> //= require <%= options[:javascript] %>_ujs +//= require turbolinks <% end -%> //= require_tree . 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 39275e4285..fb43c90e21 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -11,12 +11,8 @@ require "action_mailer/railtie" <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie" <% end -%> -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line. - Bundler.require(*Rails.groups(assets: %w(development test))) - # If you want your assets lazily compiled in production, use this line. - # Bundler.require(:default, :assets, Rails.env) -end +# Assets should be precompiled for production (so we don't need the gems loaded then) +Bundler.require(*Rails.groups(assets: %w(development test))) module <%= app_const_base %> class Application < Rails::Application @@ -27,17 +23,6 @@ module <%= app_const_base %> # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" - # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] 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 cb3e8b123e..3629920c30 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 @@ -14,6 +14,11 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/locale.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/locale.rb new file mode 100644 index 0000000000..9b41300e7e --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/locale.rb @@ -0,0 +1,7 @@ +# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. +# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. +# Rails.config.time_zone = 'Central Time (US & Canada)' + +# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. +# Rails.config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] +# Rails.config.i18n.default_locale = :de diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb index f6b1ef1feb..631543c705 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb @@ -1,23 +1,20 @@ <%= app_const %>.routes.draw do - # The priority is based upon order of creation: - # first created -> highest priority. + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. + # You can have the root of your site routed with "root" just remember to delete public/index.html. # root to: 'welcome#index' - # Sample of regular route: + # Example of regular route: # get 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action. - # Sample of named route: + # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - # This route can be invoked with purchase_url(id: product.id). - # Sample resource route (maps HTTP verbs to controller actions automatically): + # Example resource route (maps HTTP verbs to controller actions automatically): # resources :products - # Sample resource route with options: + # Example resource route with options: # resources :products do # member do # get 'short' @@ -29,13 +26,13 @@ # end # end - # Sample resource route with sub-resources: + # Example resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end - # Sample resource route with more complex sub-resources: + # Example resource route with more complex sub-resources: # resources :products do # resources :comments # resources :sales do @@ -43,13 +40,10 @@ # end # end - # Sample resource route within a namespace: + # Example resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end - - - # See how all your routes lay out with "rake routes". end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 3c2210aaf9..9826aecb54 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -115,7 +115,6 @@ module Rails class Path include Enumerable - attr_reader :path attr_accessor :glob def initialize(root, current, paths, options = {}) diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index d0d053e7ed..3f59bb8733 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -12,9 +12,6 @@ module Rails def call(env) request = ActionDispatch::Request.new(env) - # Put some space between requests in development logs. - Rails.logger.info "\n\n" if Rails.env.development? - if Rails.logger.respond_to?(:tagged) Rails.logger.tagged(compute_tags(request)) { call_app(request, env) } else @@ -25,6 +22,12 @@ module Rails protected def call_app(request, env) + # Put some space between requests in development logs. + if Rails.env.development? + Rails.logger.info '' + Rails.logger.info '' + end + Rails.logger.info started_request_message(request) @app.call(env) ensure diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 581ceaf9ce..aed7fd4b14 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,6 +7,10 @@ require 'active_support/test_case' require 'action_controller/test_case' require 'action_dispatch/testing/integration' +# Config Rails backtrace in tests. +require 'rails/backtrace_cleaner' +MiniTest.backtrace_filter = Rails.backtrace_cleaner + # Enable turn if it is available begin require 'turn' @@ -25,8 +29,8 @@ if defined?(ActiveRecord::Base) ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - def create_fixtures(*table_names, &block) - Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) + def create_fixtures(*fixture_set_names, &block) + FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, {}, &block) end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index d014e5e362..07d47dc67b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -139,6 +139,14 @@ module ApplicationTests assert_instance_of Pathname, Rails.root end + test "Rails.public_path should be a Pathname" do + add_to_config <<-RUBY + config.paths["public"] = "somewhere" + RUBY + require "#{app_path}/config/environment" + assert_instance_of Pathname, Rails.public_path + end + test "initialize an eager loaded, cache classes app" do add_to_config <<-RUBY config.eager_load = true @@ -227,7 +235,7 @@ module ApplicationTests RUBY require "#{app_path}/config/application" - assert_equal File.join(app_path, "somewhere"), Rails.public_path + assert_equal Pathname.new(app_path).join("somewhere"), Rails.public_path end test "config.secret_token is sent in env" do @@ -324,27 +332,6 @@ module ApplicationTests assert last_response.body =~ /_xsrf_token_here/ end - test "config.action_controller.perform_caching = true" do - make_basic_app do |app| - app.config.action_controller.perform_caching = true - end - - class ::OmgController < ActionController::Base - @@count = 0 - - caches_action :index - def index - @@count += 1 - render :text => @@count - end - end - - get "/" - res = last_response.body - get "/" - assert_equal res, last_response.body # value should be unchanged - end - test "sets ActionDispatch.test_app" do make_basic_app assert_equal Rails.application, ActionDispatch.test_app @@ -454,27 +441,6 @@ module ApplicationTests end end - test "config.action_controller.perform_caching = false" do - make_basic_app do |app| - app.config.action_controller.perform_caching = false - end - - class ::OmgController < ActionController::Base - @@count = 0 - - caches_action :index - def index - @@count += 1 - render :text => @@count - end - end - - get "/" - res = last_response.body - get "/" - assert_not_equal res, last_response.body - end - test "config.asset_path is not passed through env" do make_basic_app do |app| app.config.asset_path = "/omg%s" @@ -634,6 +600,7 @@ module ApplicationTests assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions assert_equal app.env_config['action_dispatch.logger'], Rails.logger assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner + assert_equal app.env_config['action_dispatch.key_generator'], Rails.application.key_generator end test "config.colorize_logging default is true" do diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 5268257d62..81f6096be8 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -175,7 +175,7 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_raises(NoMethodError) { [1,2,3].forty_two } + assert_raises(NoMethodError) { "hello".exclude? "lo" } end end diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index 19d3f3a397..fffe79f9cc 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -49,6 +49,8 @@ module ApplicationTests get ':controller(/:action)' end RUBY + + add_to_config "config.action_dispatch.rack_cache = true" end def test_cache_keeps_if_modified_since diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 3e096e99f2..b2443e6503 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -56,11 +56,20 @@ module ApplicationTests assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header" end - test "Rack::Cache is present when action_controller.perform_caching is set" do + test "Rack::Cache is not included by default" do add_to_config "config.action_controller.perform_caching = true" boot! + assert !middleware.include?("Rack::Cache"), "Rack::Cache is not included in the default stack unless you set config.action_dispatch.rack_cache" + end + + test "Rack::Cache is present when action_controller.perform_caching is set and action_dispatch.rack_cache is set" do + add_to_config "config.action_controller.perform_caching = true" + add_to_config "config.action_dispatch.rack_cache = true" + + boot! + assert_equal "Rack::Cache", middleware.first end |