diff options
Diffstat (limited to 'railties/lib')
29 files changed, 177 insertions, 81 deletions
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 050190cba6..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 @@ -282,6 +291,21 @@ module Rails ActionDispatch::MiddlewareStack.new.tap do |middleware| app = self if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache + begin + require 'rack/cache' + rescue LoadError => error + 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/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 613c5b25f0..a7a35c2685 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -57,7 +57,7 @@ module Rails @assets.debug = false @assets.compile = true @assets.digest = false - @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] + @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/#{Rails.env}/" ] @assets.js_compressor = nil @assets.css_compressor = nil @assets.initialize_on_precompile = true diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 4829f3fd45..e761e26b04 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/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 417bddaa9d..67e7c4d54f 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -113,9 +113,11 @@ module Rails def test empty_directory_with_keep_file 'test/fixtures' - empty_directory_with_keep_file 'test/functional' + empty_directory_with_keep_file 'test/controllers' + empty_directory_with_keep_file 'test/mailers' + empty_directory_with_keep_file 'test/models' + empty_directory_with_keep_file 'test/helpers' empty_directory_with_keep_file 'test/integration' - empty_directory_with_keep_file 'test/unit' template 'test/performance/browsing_test.rb' template 'test/test_helper.rb' diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 55a6b3f4f2..30f8a5f75e 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -12,7 +12,7 @@ source 'https://rubygems.org' # 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: https://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 ddfdd9720d..74457b0efd 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..a8285f88ca --- /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.application.config.time_zone = 'Central Time (US & Canada)' + +# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. +# Rails.application.config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] +# Rails.application.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/generators/rails/controller/USAGE b/railties/lib/rails/generators/rails/controller/USAGE index b658777b12..9def4af65c 100644 --- a/railties/lib/rails/generators/rails/controller/USAGE +++ b/railties/lib/rails/generators/rails/controller/USAGE @@ -12,7 +12,7 @@ Example: `rails generate controller CreditCards open debit credit close` CreditCards controller with URLs like /credit_cards/debit. - Controller: app/controllers/credit_cards_controller.rb - Functional Test: test/functional/credit_cards_controller_test.rb - Views: app/views/credit_cards/debit.html.erb [...] - Helper: app/helpers/credit_cards_helper.rb + Controller: app/controllers/credit_cards_controller.rb + Test: test/controllers/credit_cards_controller_test.rb + Views: app/views/credit_cards/debit.html.erb [...] + Helper: app/helpers/credit_cards_helper.rb diff --git a/railties/lib/rails/generators/rails/helper/USAGE b/railties/lib/rails/generators/rails/helper/USAGE index c0ddb0f606..30e323a858 100644 --- a/railties/lib/rails/generators/rails/helper/USAGE +++ b/railties/lib/rails/generators/rails/helper/USAGE @@ -13,5 +13,5 @@ Example: Credit card helper. Helper: app/helpers/credit_card_helper.rb - Test: test/unit/helpers/credit_card_helper_test.rb + Test: test/helpers/credit_card_helper_test.rb diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index c46c86076e..e29e19490e 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -74,7 +74,7 @@ Examples: For ActiveRecord and TestUnit it creates: Model: app/models/account.rb - Test: test/unit/account_test.rb + Test: test/models/account_test.rb Fixtures: test/fixtures/accounts.yml Migration: db/migrate/XXX_add_accounts.rb @@ -88,7 +88,7 @@ Examples: Module: app/models/admin.rb Model: app/models/admin/account.rb - Test: test/unit/admin/account_test.rb + Test: test/models/admin/account_test.rb Fixtures: test/fixtures/admin/accounts.yml Migration: db/migrate/XXX_add_admin_accounts.rb diff --git a/railties/lib/rails/generators/rails/observer/USAGE b/railties/lib/rails/generators/rails/observer/USAGE index d8f32a6a48..177ff49e4a 100644 --- a/railties/lib/rails/generators/rails/observer/USAGE +++ b/railties/lib/rails/generators/rails/observer/USAGE @@ -9,4 +9,4 @@ Example: For ActiveRecord and TestUnit it creates: Observer: app/models/account_observer.rb - TestUnit: test/unit/account_observer_test.rb + TestUnit: test/models/account_observer_test.rb diff --git a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb index d5c2cf4c93..121205b254 100644 --- a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb +++ b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb @@ -1,13 +1,50 @@ module Rails module Generators class ResourceRouteGenerator < NamedBase # :nodoc: + + # Properly nests namespaces passed into a generator + # + # $ rails generate resource admin/users/products + # + # should give you + # + # namespace :admin do + # namespace :users + # resources :products + # end + # end def add_resource_route return if options[:actions].present? - route_config = regular_class_path.collect{ |namespace| "namespace :#{namespace} do " }.join(" ") - route_config << "resources :#{file_name.pluralize}" - route_config << " end" * regular_class_path.size - route route_config + + # iterates over all namespaces and opens up blocks + regular_class_path.each_with_index do |namespace, index| + write("namespace :#{namespace} do", index + 1) + end + + # inserts the primary resource + write("resources :#{file_name.pluralize}", route_length + 1) + + # ends blocks + regular_class_path.each_index do |index| + write("end", route_length - index) + end + + # route prepends two spaces onto the front of the string that is passed, this corrects that + route route_string[2..-1] end + + private + def route_string + @route_string ||= "" + end + + def write(str, indent) + route_string << "#{" " * indent}#{str}\n" + end + + def route_length + regular_class_path.length + end end end end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/USAGE b/railties/lib/rails/generators/rails/scaffold_controller/USAGE index 5cd51b62d4..8ba4c5ccbc 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/USAGE +++ b/railties/lib/rails/generators/rails/scaffold_controller/USAGE @@ -13,7 +13,7 @@ Example: `rails generate scaffold_controller CreditCard` Credit card controller with URLs like /credit_card/debit. - Controller: app/controllers/credit_cards_controller.rb - Functional Test: test/functional/credit_cards_controller_test.rb - Views: app/views/credit_cards/index.html.erb [...] - Helper: app/helpers/credit_cards_helper.rb + Controller: app/controllers/credit_cards_controller.rb + Test: test/controllers/credit_cards_controller_test.rb + Views: app/views/credit_cards/index.html.erb [...] + Helper: app/helpers/credit_cards_helper.rb diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb index 2611d61b7a..c53930f994 100644 --- a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -8,7 +8,7 @@ module TestUnit # :nodoc: def create_test_files template 'functional_test.rb', - File.join('test/functional', class_path, "#{file_name}_controller_test.rb") + File.join('test/controllers', class_path, "#{file_name}_controller_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb index 44de759a5b..bcd370098e 100644 --- a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb +++ b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb @@ -6,7 +6,7 @@ module TestUnit # :nodoc: check_class_collision :suffix => "HelperTest" def create_helper_files - template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb") + template 'helper_test.rb', File.join('test/helpers', class_path, "#{file_name}_helper_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb index ddc639ae7e..570a733227 100644 --- a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -7,7 +7,7 @@ module TestUnit # :nodoc: check_class_collision :suffix => "Test" def create_test_files - template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb") + template "functional_test.rb", File.join('test/mailers', class_path, "#{file_name}_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index f373f43f11..9b73f3561f 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -9,7 +9,7 @@ module TestUnit # :nodoc: check_class_collision :suffix => "Test" def create_test_file - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") + template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_test.rb") end hook_for :fixture_replacement diff --git a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb index f9b0234b11..8bfb749743 100644 --- a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb +++ b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb @@ -6,7 +6,7 @@ module TestUnit # :nodoc: check_class_collision :suffix => "ObserverTest" def create_test_files - template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb") + template 'unit_test.rb', File.join('test/models', class_path, "#{file_name}_observer_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index a9946b9791..0462c15224 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -12,7 +12,7 @@ module TestUnit # :nodoc: def create_test_files template "functional_test.rb", - File.join("test/functional", controller_class_path, "#{controller_file_name}_controller_test.rb") + File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb") end private 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/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index 67a6d2d2ac..c1674c72ad 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -6,9 +6,13 @@ STATS_DIRECTORIES = [ %w(Javascripts app/assets/javascripts), %w(Libraries lib/), %w(APIs app/apis), + %w(Controller\ tests test/controllers), + %w(Helper\ tests test/helpers), + %w(Model\ tests test/models), + %w(Mailer\ tests test/mailers), %w(Integration\ tests test/integration), - %w(Functional\ tests test/functional), - %w(Unit\ tests test/unit) + %w(Functional\ tests\ (old) test/functional), + %w(Unit\ tests \ (old) test/unit) ].collect { |name, dir| [ name, "#{Rails.root}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } desc "Report code statistics (KLOCs, etc) from the application" diff --git a/railties/lib/rails/tasks/tmp.rake b/railties/lib/rails/tasks/tmp.rake index 0968765b4f..0bb64ced95 100644 --- a/railties/lib/rails/tasks/tmp.rake +++ b/railties/lib/rails/tasks/tmp.rake @@ -6,7 +6,9 @@ namespace :tmp do 'tmp/cache', 'tmp/sockets', 'tmp/pids', - 'tmp/cache/assets' ] + 'tmp/cache/assets/development', + 'tmp/cache/assets/test', + 'tmp/cache/assets/production' ] tmp_dirs.each { |d| directory d } 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/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 0de4afe905..63cb955d44 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -15,11 +15,11 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) # Support subdirs in app/models and app/controllers modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path - # For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb + # For modified files in app/ run the tests for it. ex. /test/controllers/account_controller.rb test = "#{modified_test_path}/#{source_file}_test.rb" tests.push test if File.exist?(test) - # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb + # For modified files in app, run tests in subdirs too. ex. /test/controllers/account/*_test.rb test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}" FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test) @@ -74,7 +74,9 @@ namespace :test do Rake::TestTask.new(:recent => "test:prepare") do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + + recent_tests('app/models/**/*.rb', 'test/models', since) + recent_tests('app/models/**/*.rb', 'test/unit', since) + + recent_tests('app/controllers/**/*.rb', 'test/controllers', since) + recent_tests('app/controllers/**/*.rb', 'test/functional', since) t.libs << 'test' @@ -95,8 +97,10 @@ 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 { |model| "test/models/#{File.basename(model, '.rb')}_test.rb" } + + models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } + + functional_tests = controllers.map { |controller| "test/controllers/#{File.basename(controller, '.rb')}_test.rb" } + + controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" } (unit_tests + functional_tests).uniq.select { |file| File.exist?(file) } end @@ -108,14 +112,34 @@ namespace :test do t.libs << "test" end + Rails::SubTestTask.new(:models => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/models/**/*_test.rb' + end + + Rails::SubTestTask.new(:helpers => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/helpers/**/*_test.rb' + end + Rails::SubTestTask.new(:units => "test:prepare") do |t| t.libs << "test" - t.pattern = 'test/unit/**/*_test.rb' + t.pattern = 'test/{models,helpers,unit}/**/*_test.rb' + end + + Rails::SubTestTask.new(:controllers => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/controllers/**/*_test.rb' + end + + Rails::SubTestTask.new(:mailers => "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/mailers/**/*_test.rb' end Rails::SubTestTask.new(:functionals => "test:prepare") do |t| t.libs << "test" - t.pattern = 'test/functional/**/*_test.rb' + t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb' end Rails::SubTestTask.new(:integration => "test:prepare") do |t| |