From 9433dde5d1ff33731e5a928166c1b9192bca92ae Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 24 Jan 2016 10:10:15 -0500 Subject: Remove empty lines in Rails development logger This is causing bugs like #23215 to occur, due to the extra spaces being inserted. Also, this is fixed upstream in the upcoming release of Sprockets 4. --- railties/lib/rails/rack/logger.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 12676b18bc..aa7d3ca6c6 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -30,12 +30,6 @@ module Rails protected def call_app(request, env) - # Put some space between requests in development logs. - if development? - logger.debug '' - logger.debug '' - end - instrumenter = ActiveSupport::Notifications.instrumenter instrumenter.start 'request.action_dispatch', request: request logger.info { started_request_message(request) } -- cgit v1.2.3 From 38492590cf30bae0f4817c610bc0237ccdea7c1a Mon Sep 17 00:00:00 2001 From: Genadi Samokovarov Date: Mon, 25 Jan 2016 18:26:20 +0200 Subject: Introduce new welcome page for new projects As requested by David in 23233. --- .../rails/templates/rails/welcome/index.html.erb | 326 ++++----------------- railties/test/application/routing_test.rb | 3 +- railties/test/isolation/abstract_unit.rb | 4 +- 3 files changed, 65 insertions(+), 268 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/templates/rails/welcome/index.html.erb b/railties/lib/rails/templates/rails/welcome/index.html.erb index acf04af416..5cdb7e6a20 100644 --- a/railties/lib/rails/templates/rails/welcome/index.html.erb +++ b/railties/lib/rails/templates/rails/welcome/index.html.erb @@ -1,268 +1,64 @@ - - Ruby on Rails: Welcome aboard - - - - -
- - -
- - - - -
-

Getting started

-

Here’s how to get rolling:

- -
    -
  1. -

    Use bin/rails generate to create your models and controllers

    -

    To see all available options, run it without parameters.

    -
  2. - -
  3. -

    Set up a root route to replace this page

    -

    You're seeing this page because you're running in development mode and you haven't set a root route yet.

    -

    Routes are set up in config/routes.rb.

    -
  4. - -
  5. -

    Configure your database

    -

    If you're not using SQLite (the default), edit config/database.yml with your username and password.

    -
  6. -
-
-
- - -
- + + Ruby on Rails + + + + + + +
+
+

+ + Ruby on Rails + +

+ +

Yay! You’re on Rails!

+ + Welcome + +

+ Rails version: <%= Rails.version %>
+ Ruby version: <%= RUBY_VERSION %> (<%= RUBY_PLATFORM %>) +

+
+
+ diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 0777714d35..e51f32aaed 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -42,8 +42,7 @@ module ApplicationTests test "root takes precedence over internal welcome controller" do app("development") - get '/' - assert_match %r{

Getting started

} , last_response.body + assert_welcome get('/') controller :foo, <<-RUBY class FooController < ApplicationController diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index df3c2ca66d..dddf8bd257 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -74,10 +74,12 @@ module TestHelpers end def assert_welcome(resp) + resp = Array(resp) + assert_equal 200, resp[0] assert_match 'text/html', resp[1]["Content-Type"] assert_match 'charset=utf-8', resp[1]["Content-Type"] - assert extract_body(resp).match(/Welcome aboard/) + assert extract_body(resp).match(/Yay! You.*re on Rails!/) end def assert_success(resp) -- cgit v1.2.3 From 9ea7aa84d16d99fd32ed1877e3fd6631a41e7042 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 27 Jan 2016 14:33:15 +0100 Subject: Revert "Eliminate the EventMachine dependency" --- railties/lib/rails/generators/rails/app/templates/config.ru.tt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru.tt b/railties/lib/rails/generators/rails/app/templates/config.ru.tt index 343c0833d7..70556fcc99 100644 --- a/railties/lib/rails/generators/rails/app/templates/config.ru.tt +++ b/railties/lib/rails/generators/rails/app/templates/config.ru.tt @@ -3,8 +3,9 @@ require ::File.expand_path('../config/environment', __FILE__) <%- unless options[:skip_action_cable] -%> -# Action Cable requires that all classes are loaded in advance +# Action Cable uses EventMachine which requires that all classes are loaded in advance Rails.application.eager_load! +require 'action_cable/process/logging' <%- end -%> run Rails.application -- cgit v1.2.3 From 31701fbdf28688ba53b8f2d2d26904954ae1b976 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 28 Jan 2016 12:43:24 -0600 Subject: Add an after_bundle callback in Rails plugin templates --- railties/CHANGELOG.md | 7 ++++++ .../generators/rails/plugin/plugin_generator.rb | 6 +++++ railties/test/generators/app_generator_test.rb | 5 ++-- railties/test/generators/plugin_generator_test.rb | 28 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 2c363c55da..91e879dd73 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -448,4 +448,11 @@ *Alex Robbin* +* Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing + templates to perform actions that are dependent upon `bundle install`. + + Fixes #<> + + *Ryan Manuel* + Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md) for previous changes. diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 0c7a73a54e..b5e836b584 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -259,6 +259,12 @@ task default: :test public_task :apply_rails_template, :run_bundle + def run_after_bundle_callbacks + @after_bundle_callbacks.each do |callback| + callback.call + end + end + def name @name ||= begin # same as ActiveSupport::Inflector#underscore except not replacing '-' diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 136bdd1694..53f8ed6af0 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -703,9 +703,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end sequence = ['install', 'exec spring binstub --all', 'echo ran after_bundle'] - ensure_bundler_first = -> command do @sequence_step ||= 0 - + ensure_bundler_first = -> command do assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" @sequence_step += 1 end @@ -717,6 +716,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end end end + + assert_equal 3, @sequence_step end protected diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 874bda17b7..ef33cd4ff7 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -634,6 +634,34 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "app/models/bukkits/article.rb", /class Article < ApplicationRecord/ end + def test_after_bundle_callback + path = 'http://example.org/rails_template' + template = %{ after_bundle { run 'echo ran after_bundle' } } + template.instance_eval "def read; self; end" # Make the string respond to read + + check_open = -> *args do + assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args + template + end + + sequence = ['install', 'echo ran after_bundle'] + @sequence_step ||= 0 + ensure_bundler_first = -> command do + assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" + @sequence_step += 1 + end + + generator([destination_root], template: path).stub(:open, check_open, template) do + generator.stub(:bundle_command, ensure_bundler_first) do + generator.stub(:run, ensure_bundler_first) do + quietly { generator.invoke_all } + end + end + end + + assert_equal 2, @sequence_step + end + protected def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } -- cgit v1.2.3 From 3a06a06ca9cd508f32e6c7f73662140949c9c748 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Thu, 28 Jan 2016 13:06:11 -0600 Subject: Update doc with appropriate issue and pull request versions --- railties/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 91e879dd73..6076940323 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -451,7 +451,7 @@ * Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing templates to perform actions that are dependent upon `bundle install`. - Fixes #<> + Fixes #<23315> *Ryan Manuel* -- cgit v1.2.3 From 92e565825d102a0f4d6ed2368d9510008da1da21 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Fri, 29 Jan 2016 09:27:00 -0600 Subject: Implemented pull request changes. --- railties/CHANGELOG.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 6076940323..f94bb49135 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing + templates to perform actions that are dependent upon `bundle install`. + + *Ryan Manuel* + * Bring back `TEST=` env for `rake test` task. *Yves Senn* @@ -448,11 +453,4 @@ *Alex Robbin* -* Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing - templates to perform actions that are dependent upon `bundle install`. - - Fixes #<23315> - - *Ryan Manuel* - Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md) for previous changes. -- cgit v1.2.3 From 74497eabd52f2f9f8c383808b11286283046c2b2 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Thu, 28 Jan 2016 15:25:31 +1030 Subject: Revert "Revert "Eliminate the EventMachine dependency"" --- railties/lib/rails/generators/rails/app/templates/config.ru.tt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru.tt b/railties/lib/rails/generators/rails/app/templates/config.ru.tt index 70556fcc99..343c0833d7 100644 --- a/railties/lib/rails/generators/rails/app/templates/config.ru.tt +++ b/railties/lib/rails/generators/rails/app/templates/config.ru.tt @@ -3,9 +3,8 @@ require ::File.expand_path('../config/environment', __FILE__) <%- unless options[:skip_action_cable] -%> -# Action Cable uses EventMachine which requires that all classes are loaded in advance +# Action Cable requires that all classes are loaded in advance Rails.application.eager_load! -require 'action_cable/process/logging' <%- end -%> run Rails.application -- cgit v1.2.3 From 5563c329eee5febc22a3330e16fe8a6899d42fe2 Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 14 Jan 2016 13:05:41 -0600 Subject: Add Default Puma Config When the `puma` command is run without any configuration options it will detect presence of a `config/puma.rb` file and use that. Currently there is discrepancy between `puma` command and `rails server` but Evan said it would be reasonable to add in reading in config from the default location. I am working on that right now as a feature in puma/puma. Why do we need this? By default Puma uses 16 threads, and by default ActiveRecord only has 5 threads. Due to the architecture of AR it is guaranteed that if you're running with fewer DB connections than your server has threads you will hit `ActiveRecord::ConnectionTimeoutError ` eventually if your app gets modest amounts of traffic. Since we are providing a default webserver, we should provide reasonable configuration for that webserver. This PR does a few things, first it sets the default Puma thread count to 5 to mach ActiveRecord's default. It sets the default environment to `"development"` and the default port to 300 so that booting the server with `$ puma` will give you the same default port as `rails server`. It is worth mentioning that by reading in from `PORT` environment variable this config can work with containerized deployments, such as on Heroku. We are not using worker processes by default, that way JRuby and windows devs can use this configuration without modification. I went ahead and included a default `on_worker_boot`. It won't be used unless a worker count is specified, that means this config will not use it. Even though it's not being used now It will make someone who wants to try modifying their config to run extra workers easier. cc/ @pixeltrix --- railties/lib/rails/generators/app_base.rb | 10 +++++ .../rails/generators/rails/app/app_generator.rb | 1 + .../rails/generators/rails/app/templates/Gemfile | 3 -- .../generators/rails/app/templates/config/puma.rb | 44 ++++++++++++++++++++++ railties/test/generators/app_generator_test.rb | 9 +++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/config/puma.rb (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index c629459d95..420e9673a1 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -51,6 +51,9 @@ module Rails class_option :skip_active_record, type: :boolean, aliases: '-O', default: false, desc: 'Skip Active Record files' + class_option :skip_puma, type: :boolean, aliases: '-P', default: false, + desc: 'Skip Puma related files' + class_option :skip_action_cable, type: :boolean, aliases: '-C', default: false, desc: 'Skip Action Cable files' @@ -113,6 +116,7 @@ module Rails def gemfile_entries [rails_gemfile_entry, database_gemfile_entry, + webserver_gemfile_entry, assets_gemfile_entry, javascript_gemfile_entry, jbuilder_gemfile_entry, @@ -171,6 +175,12 @@ module Rails "Use #{options[:database]} as the database for Active Record" end + def webserver_gemfile_entry + return [] if options[:skip_puma] + comment = 'Use Puma as the app server' + GemfileEntry.new('puma', nil, comment) + end + def include_all_railties? options.values_at(:skip_active_record, :skip_action_mailer, :skip_test, :skip_sprockets, :skip_action_cable).none? end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 3d689ff37e..63bb02cf9a 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -79,6 +79,7 @@ module Rails template "environment.rb" template "secrets.yml" template "cable.yml" unless options[:skip_action_cable] + template "puma.rb" unless options[:skip_puma] directory "environments" directory "initializers" diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index da5af4eefc..3825dc4e38 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -12,9 +12,6 @@ source 'https://rubygems.org' <% end -%> <% end -%> -# Use Puma as the app server -gem 'puma' - # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/railties/lib/rails/generators/rails/app/templates/config/puma.rb b/railties/lib/rails/generators/rails/app/templates/config/puma.rb new file mode 100644 index 0000000000..1bf274bc66 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/puma.rb @@ -0,0 +1,44 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 5b62b500e5..39224b70ca 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -27,6 +27,7 @@ DEFAULT_APP_FILES = %w( config/initializers config/locales config/cable.yml + config/puma.rb db lib lib/tasks @@ -337,6 +338,14 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generator_if_skip_puma_is_given + run_generator [destination_root, "--skip-puma"] + assert_no_file "config/puma.rb" + assert_file "Gemfile" do |content| + assert_no_match(/puma/, content) + end + end + def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] assert_no_file "config/database.yml" -- cgit v1.2.3 From 284f8d4970e50c1239236c22c9eb45ca7dbfb60f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 30 Jan 2016 23:07:23 +0900 Subject: remove unnecessary gsub for `action_cable_meta_tag` If the specified `skip_action_cable` option, so as not to output the `action_cable_meta_tag` in template, gsub is unnecessary. ref: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt#L6..L8 --- railties/lib/rails/generators/rails/app/app_generator.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a4758857f2..775750d86b 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -318,7 +318,6 @@ module Rails remove_file 'config/cable.yml' remove_file 'app/assets/javascripts/cable.coffee' remove_dir 'app/channels' - gsub_file 'app/views/layouts/application.html.erb', /action_cable_meta_tag/, '' unless options[:api] end end -- cgit v1.2.3 From 3ffa5a15cc966c80029043c77adb3184422e33b3 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 21 Jan 2016 08:11:58 +0900 Subject: make rake proxy work in rails engines --- railties/lib/rails/engine/commands.rb | 35 +------ railties/lib/rails/engine/commands_tasks.rb | 116 +++++++++++++++++++++ railties/lib/rails/tasks/engine.rake | 4 +- railties/test/generators/plugin_generator_test.rb | 2 +- .../test/generators/scaffold_generator_test.rb | 8 +- 5 files changed, 126 insertions(+), 39 deletions(-) create mode 100644 railties/lib/rails/engine/commands_tasks.rb (limited to 'railties') diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index a6d87b78e4..7bbd9ef744 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -1,3 +1,5 @@ +require 'rails/engine/commands_tasks' + ARGV << '--help' if ARGV.empty? aliases = { @@ -9,35 +11,4 @@ aliases = { command = ARGV.shift command = aliases[command] || command -require ENGINE_PATH -engine = ::Rails::Engine.find(ENGINE_ROOT) - -case command -when 'generate', 'destroy', 'test' - require 'rails/generators' - Rails::Generators.namespace = engine.railtie_namespace - engine.load_generators - require "rails/commands/#{command}" - -when '--version', '-v' - ARGV.unshift '--version' - require 'rails/commands/application' - -else - puts "Error: Command not recognized" unless %w(-h --help).include?(command) - puts <<-EOT -Usage: rails COMMAND [ARGS] - -The common Rails commands available for engines are: - generate Generate new code (short-cut alias: "g") - destroy Undo code generated with "generate" (short-cut alias: "d") - test Run tests (short-cut alias: "t") - -All commands can be run with -h for more information. - -If you want to run any commands that need to be run in context -of the application, like `rails server` or `rails console`, -you should do it from application's directory (typically test/dummy). - EOT - exit(1) -end +Rails::Engine::CommandsTasks.new(ARGV).run_command!(command) diff --git a/railties/lib/rails/engine/commands_tasks.rb b/railties/lib/rails/engine/commands_tasks.rb new file mode 100644 index 0000000000..fa3ee59b7d --- /dev/null +++ b/railties/lib/rails/engine/commands_tasks.rb @@ -0,0 +1,116 @@ +require 'rails/commands/rake_proxy' + +module Rails + class Engine + class CommandsTasks # :nodoc: + include Rails::RakeProxy + + attr_reader :argv + + HELP_MESSAGE = <<-EOT +Usage: rails COMMAND [ARGS] + +The common Rails commands available for engines are: + generate Generate new code (short-cut alias: "g") + destroy Undo code generated with "generate" (short-cut alias: "d") + test Run tests (short-cut alias: "t") + +All commands can be run with -h for more information. + +If you want to run any commands that need to be run in context +of the application, like `rails server` or `rails console`, +you should do it from application's directory (typically test/dummy). + +In addition to those commands, there are: + EOT + + COMMAND_WHITELIST = %w(generate destroy version help test) + + def initialize(argv) + @argv = argv + end + + def run_command!(command) + command = parse_command(command) + + if COMMAND_WHITELIST.include?(command) + send(command) + else + run_rake_task(command) + end + end + + def generate + generate_or_destroy(:generate) + end + + def destroy + generate_or_destroy(:destroy) + end + + def test + require_command!("test") + end + + def version + argv.unshift '--version' + require_command!("application") + end + + def help + write_help_message + write_commands(formatted_rake_tasks) + end + + private + + def require_command!(command) + require "rails/commands/#{command}" + end + + def generate_or_destroy(command) + load_generators + require_command!(command) + end + + def load_generators + require 'rails/generators' + require ENGINE_PATH + + engine = ::Rails::Engine.find(ENGINE_ROOT) + Rails::Generators.namespace = engine.railtie_namespace + engine.load_generators + end + + def write_help_message + puts HELP_MESSAGE + end + + def write_commands(commands) + width = commands.map { |name, _| name.size }.max || 10 + commands.each { |command| printf(" %-#{width}s %s\n", *command) } + end + + def parse_command(command) + case command + when '--version', '-v' + 'version' + when '--help', '-h' + 'help' + else + command + end + end + + def rake_tasks + return @rake_tasks if defined?(@rake_tasks) + + load_generators + Rake::TaskManager.record_task_metadata = true + Rake.application.init('rails') + Rake.application.load_rakefile + @rake_tasks = Rake.application.tasks.select(&:comment) + end + end + end +end diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index c51524f8f6..e678103f63 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -4,8 +4,8 @@ task "load_app" do end task :environment => "app:environment" - if !defined?(ENGINE_PATH) || !ENGINE_PATH - ENGINE_PATH = find_engine_path(APP_RAKEFILE) + if !defined?(ENGINE_ROOT) || !ENGINE_ROOT + ENGINE_ROOT = find_engine_path(APP_RAKEFILE) end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index ef33cd4ff7..0fd1d34131 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -240,7 +240,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--mountable"] FileUtils.cd destination_root quietly { system 'bundle install' } - output = `bundle exec rake db:migrate 2>&1` + output = `bin/rails db:migrate 2>&1` assert $?.success?, "Command failed: #{output}" end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 6f7a83cae0..5e45120704 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -486,7 +486,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase Dir.chdir(engine_path) do quietly do `bin/rails g scaffold User name:string age:integer; - bundle exec rake db:migrate` + bin/rails db:migrate` end assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) end @@ -500,7 +500,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase Dir.chdir(engine_path) do quietly do `bin/rails g scaffold User name:string age:integer; - bundle exec rake db:migrate` + bin/rails db:migrate` end assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) end @@ -514,7 +514,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase Dir.chdir(engine_path) do quietly do `bin/rails g scaffold User name:string age:integer; - bundle exec rake db:migrate` + bin/rails db:migrate` end assert_match(/6 runs, 8 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) end @@ -528,7 +528,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase Dir.chdir(engine_path) do quietly do `bin/rails g scaffold User name:string age:integer; - bundle exec rake db:migrate` + bin/rails db:migrate` end assert_match(/6 runs, 8 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) end -- cgit v1.2.3 From e77368637e17e6a33db2713f651e85a09456c645 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 1 Feb 2016 01:30:00 +1030 Subject: Switch the default redis adapter to a single-stream model This new adapter does get a little more intimate with the redis-rb gem's implementation than I would like, but it's the least bad of the approaches I've come up with. --- railties/lib/rails/generators/app_base.rb | 1 - railties/test/generators/app_generator_test.rb | 3 --- 2 files changed, 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index c629459d95..51394de824 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -344,7 +344,6 @@ module Rails return [] if options[:skip_action_cable] comment = 'Action Cable dependencies for the Redis adapter' gems = [] - gems << GemfileEntry.new("em-hiredis", '~> 0.3.0', comment) gems << GemfileEntry.new("redis", '~> 3.0', comment) gems end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 53f8ed6af0..49536c068f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -400,7 +400,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/action_cable_meta_tag/, content) end assert_file "Gemfile" do |content| - assert_no_match(/em-hiredis/, content) assert_no_match(/redis/, content) end end @@ -412,14 +411,12 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_file "app/assets/javascripts/cable.coffee" assert_no_file "app/channels" assert_file "Gemfile" do |content| - assert_no_match(/em-hiredis/, content) assert_no_match(/redis/, content) end end def test_action_cable_redis_gems run_generator - assert_gem 'em-hiredis' assert_gem 'redis' end -- cgit v1.2.3 From d6f2000a67cc63aa67414c75ce77de671824ec52 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 1 Feb 2016 04:31:03 +1030 Subject: Wrangle the asset build into something that sounds more general --- railties/Rakefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/Rakefile b/railties/Rakefile index cf130a5f14..3421d9b464 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -2,6 +2,9 @@ require 'rake/testtask' task :default => :test +task :package +task "package:clean" + desc "Run all unit tests" task :test => 'test:isolated' -- cgit v1.2.3 From 082a0b5b828fd537d328f76bb69dd82148b85222 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 1 Feb 2016 05:19:44 +1030 Subject: Use the in-process subscription adapter for development & test --- railties/lib/rails/generators/rails/app/templates/config/cable.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/cable.yml b/railties/lib/rails/generators/rails/app/templates/config/cable.yml index 004adb7b3c..aa4e832748 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/cable.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/cable.yml @@ -4,9 +4,7 @@ production: url: redis://localhost:6379/1 development: - adapter: redis - url: redis://localhost:6379/2 + adapter: async test: - adapter: redis - url: redis://localhost:6379/3 + adapter: async -- cgit v1.2.3 From a374af8b5788506acc28b755c0cde62ee89fa9d3 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 12 Jan 2016 01:51:54 +0000 Subject: Shorten ActiveRecord::InternalMetadata.table_name to ar_internal_metadata to support Oracle database which only supports 30 byte identifier length --- railties/test/application/bin_setup_test.rb | 2 +- railties/test/application/rake/dbs_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/application/bin_setup_test.rb b/railties/test/application/bin_setup_test.rb index 8c3ab65c51..a07c51a60f 100644 --- a/railties/test/application/bin_setup_test.rb +++ b/railties/test/application/bin_setup_test.rb @@ -28,7 +28,7 @@ module ApplicationTests assert_not File.exist?("tmp/restart.txt") `bin/setup 2>&1` assert_equal 0, File.size("log/test.log") - assert_equal '["articles", "schema_migrations", "active_record_internal_metadatas"]', list_tables.call + assert_equal '["articles", "schema_migrations", "ar_internal_metadata"]', list_tables.call assert File.exist?("tmp/restart.txt") end end diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index c000a70382..a229609e84 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -222,14 +222,14 @@ module ApplicationTests assert_equal '["posts"]', list_tables[] `bin/rails db:schema:load` - assert_equal '["posts", "comments", "schema_migrations", "active_record_internal_metadatas"]', list_tables[] + assert_equal '["posts", "comments", "schema_migrations", "ar_internal_metadata"]', list_tables[] app_file 'db/structure.sql', <<-SQL CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)); SQL `bin/rails db:structure:load` - assert_equal '["posts", "comments", "schema_migrations", "active_record_internal_metadatas", "users"]', list_tables[] + assert_equal '["posts", "comments", "schema_migrations", "ar_internal_metadata", "users"]', list_tables[] end end -- cgit v1.2.3 From 92203edbe6546f84921b6ccb6e79c3a01857a8b3 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 1 Feb 2016 19:42:14 +1030 Subject: Always obtain the lock and do the unload We mostly care about `reload_classes_only_on_change=true`, because that's the default... and there, we definitely need to wait for the lock when necessary. --- railties/lib/rails/application/finisher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 404e3c3e23..411cdbad19 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -86,7 +86,7 @@ module Rails # added in the hook are taken into account. initializer :set_clear_dependencies_hook, group: :all do callback = lambda do - ActiveSupport::Dependencies.interlock.attempt_unloading do + ActiveSupport::Dependencies.interlock.unloading do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear end -- cgit v1.2.3 From 8a436fdd98c63cc0a7a6d2c642c18d33421dc6ad Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 25 Jan 2016 01:32:44 +0530 Subject: Add options for rake routes task Add two options: `-c` and `-g`. `-g` option returns the urls name, verb and path fields that match the pattern. `-c` option returns the urls for specific controller. Fixes #18902, and Fixes #20420 [Anton Davydov & Vipul A M] --- railties/lib/rails/tasks/routes.rake | 32 +++++++++++++++-- railties/test/application/rake_test.rb | 63 ++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 1815c2fdc7..499c434ffa 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,7 +1,35 @@ -desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' +require 'active_support/deprecation' +require 'active_support/core_ext/string/strip' # for strip_heredoc +require 'optparse' + +desc 'Print out all defined routes in match order, with names. Target specific controller with --controller option - or its -c shorthand.' task routes: :environment do all_routes = Rails.application.routes.routes require 'action_dispatch/routing/inspector' inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) - puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER']) + if ARGV.any?{ |argv| argv.start_with? 'CONTROLLER' } + puts <<-eow.strip_heredoc + Passing `CONTROLLER` to `bin/rake routes` is deprecated and will be removed in Rails 5.1. + Please use `bin/rake routes -c controller_name` instead. + eow + end + + routes_filter = nil + routes_filter = {controller: ENV['CONTROLLER']} if ENV['CONTROLLER'] + + OptionParser.new do |opts| + opts.banner = "Usage: rake routes [options]" + opts.on("-c", "--controller [CONTROLLER]") do |controller| + routes_filter = { controller: controller } + end + + opts.on("-g", "--grep [PATTERN]") do |pattern| + routes_filter = pattern + end + + end.parse!(ARGV.reject { |x| x == "routes" }) + + puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter) + + exit 0 # ensure extra arguments aren't interpreted as Rake tasks end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index b979ad64d1..7171aa6e1a 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -141,8 +141,67 @@ module ApplicationTests end RUBY - ENV['CONTROLLER'] = 'cart' - output = Dir.chdir(app_path){ `bin/rails routes` } + output = Dir.chdir(app_path){ `bin/rake routes CONTROLLER=cart` } + assert_equal ["Passing `CONTROLLER` to `bin/rake routes` is deprecated and will be removed in Rails 5.1.", + "Please use `bin/rake routes -c controller_name` instead.", + "Prefix Verb URI Pattern Controller#Action", + " cart GET /cart(.:format) cart#show\n"].join("\n"), output + + output = Dir.chdir(app_path){ `bin/rails routes -c cart` } + assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output + end + + def test_rake_routes_with_namespaced_controller_environment + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + namespace :admin do + resource :post + end + end + RUBY + expected_output = [" Prefix Verb URI Pattern Controller#Action", + " admin_post POST /admin/post(.:format) admin/posts#create", + " new_admin_post GET /admin/post/new(.:format) admin/posts#new", + "edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit", + " GET /admin/post(.:format) admin/posts#show", + " PATCH /admin/post(.:format) admin/posts#update", + " PUT /admin/post(.:format) admin/posts#update", + " DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n") + + output = Dir.chdir(app_path){ `bin/rails routes -c Admin::PostController` } + assert_equal expected_output, output + + output = Dir.chdir(app_path){ `bin/rails routes -c PostController` } + assert_equal expected_output, output + end + + def test_rake_routes_with_global_search_key + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + get '/cart', to: 'cart#show' + get '/basketball', to: 'basketball#index' + end + RUBY + + output = Dir.chdir(app_path){ `bin/rake routes -g show` } + assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output + end + + def test_rake_routes_with_controller_search_key + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + get '/cart', to: 'cart#show' + get '/basketball', to: 'basketball#index' + end + RUBY + + output = Dir.chdir(app_path){ `bin/rake routes -c cart` } + assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output + + output = Dir.chdir(app_path){ `bin/rake routes -c Cart` } + assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output + + output = Dir.chdir(app_path){ `bin/rake routes -c CartController` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end -- cgit v1.2.3 From b801566972d3e23d5f299e914034bda2d44ce5f5 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 1 Feb 2016 22:18:19 +0100 Subject: Add spaces in the braces. Solves personal insanity, since I was down in these files. (Please don't submit PRs like this.) --- railties/lib/rails/tasks/routes.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 499c434ffa..353b8b4e72 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -15,7 +15,7 @@ task routes: :environment do end routes_filter = nil - routes_filter = {controller: ENV['CONTROLLER']} if ENV['CONTROLLER'] + routes_filter = { controller: ENV['CONTROLLER'] } if ENV['CONTROLLER'] OptionParser.new do |opts| opts.banner = "Usage: rake routes [options]" -- cgit v1.2.3 From 49f6ce63f33b7817bcbd0cdf5f8881b63f40d9c9 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 1 Feb 2016 14:27:38 -0700 Subject: Preparing for Rails 5.0.0.beta2 --- railties/CHANGELOG.md | 5 +++++ railties/lib/rails/gem_version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index f94bb49135..e98180d126 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +## Rails 5.0.0.beta2 (February 01, 2016) ## + +* No changes. + + * Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing templates to perform actions that are dependent upon `bundle install`. diff --git a/railties/lib/rails/gem_version.rb b/railties/lib/rails/gem_version.rb index f4d5b660dc..93e0151602 100644 --- a/railties/lib/rails/gem_version.rb +++ b/railties/lib/rails/gem_version.rb @@ -8,7 +8,7 @@ module Rails MAJOR = 5 MINOR = 0 TINY = 0 - PRE = "beta1.1" + PRE = "beta2" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From 60b040e362086fa11f86d35938d515145241174e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 1 Feb 2016 19:57:31 -0200 Subject: Add some Action Cable CHANGELOG entries And improve changelongs. [ci skip] --- railties/CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index e98180d126..96149acc08 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,8 +1,5 @@ ## Rails 5.0.0.beta2 (February 01, 2016) ## -* No changes. - - * Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing templates to perform actions that are dependent upon `bundle install`. @@ -26,6 +23,7 @@ *Will Fisher* + ## Rails 5.0.0.beta1 (December 18, 2015) ## * Newly generated plugins get a `README.md` in Markdown. -- cgit v1.2.3 From 96b9609e2b006d7b75d099a29729fe8d805f12bf Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 2 Feb 2016 09:04:10 +0900 Subject: :warning: assigned but unused variable - err --- railties/lib/rails/commands/runner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index babb197ba1..5844e9037c 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -59,8 +59,8 @@ elsif File.exist?(code_or_file) Kernel.load code_or_file else begin - eval(code_or_file, binding, __FILE__, __LINE__) - rescue SyntaxError,NameError => err + eval(code_or_file, binding, __FILE__, __LINE__) + rescue SyntaxError, NameError $stderr.puts "Please specify a valid ruby command or the path of a script to run." $stderr.puts "Run '#{$0} -h' for help." exit 1 -- cgit v1.2.3 From 538bce1f7c676f4a5b3d800ed0f68ec065776a7f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 1 Feb 2016 17:17:56 -0800 Subject: Generated engines should protect from forgery Generated engines should call `protect_from_forgery`. If this method isn't called, then the Engine could be susceptible to XSS attacks. Thanks @tomekr for reporting this to us! --- .../app/controllers/%namespaced_name%/application_controller.rb.tt | 1 + railties/test/generators/plugin_generator_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt b/railties/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt index 7fe4e5034d..83807f14b4 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt @@ -1,5 +1,6 @@ <%= wrap_in_modules <<-rb.strip_heredoc class ApplicationController < ActionController::#{api? ? "API" : "Base"} + #{ api? ? '# ' : '' }protect_from_forgery :with => :exception end rb %> diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 0fd1d34131..6e5132e849 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -335,7 +335,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "hyphenated-name/lib/hyphenated/name/engine.rb", /module Hyphenated\n module Name\n class Engine < ::Rails::Engine\n isolate_namespace Hyphenated::Name\n end\n end\nend/ assert_file "hyphenated-name/lib/hyphenated/name.rb", /require "hyphenated\/name\/engine"/ assert_file "hyphenated-name/test/dummy/config/routes.rb", /mount Hyphenated::Name::Engine => "\/hyphenated-name"/ - assert_file "hyphenated-name/app/controllers/hyphenated/name/application_controller.rb", /module Hyphenated\n module Name\n class ApplicationController < ActionController::Base\n end\n end\nend/ + assert_file "hyphenated-name/app/controllers/hyphenated/name/application_controller.rb", /module Hyphenated\n module Name\n class ApplicationController < ActionController::Base\n protect_from_forgery :with => :exception\n end\n end\nend\n/ assert_file "hyphenated-name/app/models/hyphenated/name/application_record.rb", /module Hyphenated\n module Name\n class ApplicationRecord < ActiveRecord::Base\n self\.abstract_class = true\n end\n end\nend/ assert_file "hyphenated-name/app/jobs/hyphenated/name/application_job.rb", /module Hyphenated\n module Name\n class ApplicationJob < ActiveJob::Base/ assert_file "hyphenated-name/app/mailers/hyphenated/name/application_mailer.rb", /module Hyphenated\n module Name\n class ApplicationMailer < ActionMailer::Base\n default from: 'from@example.com'\n layout 'mailer'\n end\n end\nend/ @@ -357,7 +357,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "my_hyphenated-name/lib/my_hyphenated/name/engine.rb", /module MyHyphenated\n module Name\n class Engine < ::Rails::Engine\n isolate_namespace MyHyphenated::Name\n end\n end\nend/ assert_file "my_hyphenated-name/lib/my_hyphenated/name.rb", /require "my_hyphenated\/name\/engine"/ assert_file "my_hyphenated-name/test/dummy/config/routes.rb", /mount MyHyphenated::Name::Engine => "\/my_hyphenated-name"/ - assert_file "my_hyphenated-name/app/controllers/my_hyphenated/name/application_controller.rb", /module MyHyphenated\n module Name\n class ApplicationController < ActionController::Base\n end\n end\nend/ + assert_file "my_hyphenated-name/app/controllers/my_hyphenated/name/application_controller.rb", /module MyHyphenated\n module Name\n class ApplicationController < ActionController::Base\n protect_from_forgery :with => :exception\n end\n end\nend\n/ assert_file "my_hyphenated-name/app/models/my_hyphenated/name/application_record.rb", /module MyHyphenated\n module Name\n class ApplicationRecord < ActiveRecord::Base\n self\.abstract_class = true\n end\n end\nend/ assert_file "my_hyphenated-name/app/jobs/my_hyphenated/name/application_job.rb", /module MyHyphenated\n module Name\n class ApplicationJob < ActiveJob::Base/ assert_file "my_hyphenated-name/app/mailers/my_hyphenated/name/application_mailer.rb", /module MyHyphenated\n module Name\n class ApplicationMailer < ActionMailer::Base\n default from: 'from@example.com'\n layout 'mailer'\n end\n end\nend/ @@ -379,7 +379,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "deep-hyphenated-name/lib/deep/hyphenated/name/engine.rb", /module Deep\n module Hyphenated\n module Name\n class Engine < ::Rails::Engine\n isolate_namespace Deep::Hyphenated::Name\n end\n end\n end\nend/ assert_file "deep-hyphenated-name/lib/deep/hyphenated/name.rb", /require "deep\/hyphenated\/name\/engine"/ assert_file "deep-hyphenated-name/test/dummy/config/routes.rb", /mount Deep::Hyphenated::Name::Engine => "\/deep-hyphenated-name"/ - assert_file "deep-hyphenated-name/app/controllers/deep/hyphenated/name/application_controller.rb", /module Deep\n module Hyphenated\n module Name\n class ApplicationController < ActionController::Base\n end\n end\n end\nend/ + assert_file "deep-hyphenated-name/app/controllers/deep/hyphenated/name/application_controller.rb", /module Deep\n module Hyphenated\n module Name\n class ApplicationController < ActionController::Base\n protect_from_forgery :with => :exception\n end\n end\n end\nend\n/ assert_file "deep-hyphenated-name/app/models/deep/hyphenated/name/application_record.rb", /module Deep\n module Hyphenated\n module Name\n class ApplicationRecord < ActiveRecord::Base\n self\.abstract_class = true\n end\n end\n end\nend/ assert_file "deep-hyphenated-name/app/jobs/deep/hyphenated/name/application_job.rb", /module Deep\n module Hyphenated\n module Name\n class ApplicationJob < ActiveJob::Base/ assert_file "deep-hyphenated-name/app/mailers/deep/hyphenated/name/application_mailer.rb", /module Deep\n module Hyphenated\n module Name\n class ApplicationMailer < ActionMailer::Base\n default from: 'from@example.com'\n layout 'mailer'\n end\n end\n end\nend/ -- cgit v1.2.3 From b700d4811dbc1ba5efcfd618f8ee0bf0b9e22d4c Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 2 Feb 2016 15:36:12 +0900 Subject: move `test_generator_if_skip_action_cable_is_given_for_an_api_app` to the appropriate file Test of Rails API should be in `api_app_generator_test.rb`. --- railties/test/generators/api_app_generator_test.rb | 10 ++++++++++ railties/test/generators/app_generator_test.rb | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index d9eb7770f3..1ea5661006 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -52,6 +52,16 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers/application_controller.rb", /ActionController::API/ end + def test_generator_if_skip_action_cable_is_given + run_generator [destination_root, "--skip-action-cable"] + assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ + assert_no_file "config/cable.yml" + assert_no_file "app/channels" + assert_file "Gemfile" do |content| + assert_no_match(/redis/, content) + end + end + private def default_files diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 937f68fff8..9595d2a0ef 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -413,17 +413,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_generator_if_skip_action_cable_is_given_for_an_api_app - run_generator [destination_root, "--skip-action-cable", "--api"] - assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ - assert_no_file "config/cable.yml" - assert_no_file "app/assets/javascripts/cable.coffee" - assert_no_file "app/channels" - assert_file "Gemfile" do |content| - assert_no_match(/redis/, content) - end - end - def test_action_cable_redis_gems run_generator assert_gem 'redis' -- cgit v1.2.3 From fae17243984965b152d8212be6405ce840887018 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 3 Feb 2016 08:16:18 +0900 Subject: use rails command in routes task For other task has become to use the rails command at doc and test, I think that routes task also it is better to use the rails command. --- railties/lib/rails/tasks/routes.rake | 6 +++--- railties/test/application/rake_test.rb | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 353b8b4e72..939fa59c75 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -9,8 +9,8 @@ task routes: :environment do inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) if ARGV.any?{ |argv| argv.start_with? 'CONTROLLER' } puts <<-eow.strip_heredoc - Passing `CONTROLLER` to `bin/rake routes` is deprecated and will be removed in Rails 5.1. - Please use `bin/rake routes -c controller_name` instead. + Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1. + Please use `bin/rails routes -c controller_name` instead. eow end @@ -18,7 +18,7 @@ task routes: :environment do routes_filter = { controller: ENV['CONTROLLER'] } if ENV['CONTROLLER'] OptionParser.new do |opts| - opts.banner = "Usage: rake routes [options]" + opts.banner = "Usage: rails routes [options]" opts.on("-c", "--controller [CONTROLLER]") do |controller| routes_filter = { controller: controller } end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 7171aa6e1a..745a3e3ec5 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -141,9 +141,9 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rake routes CONTROLLER=cart` } - assert_equal ["Passing `CONTROLLER` to `bin/rake routes` is deprecated and will be removed in Rails 5.1.", - "Please use `bin/rake routes -c controller_name` instead.", + output = Dir.chdir(app_path){ `bin/rails routes CONTROLLER=cart` } + assert_equal ["Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.", + "Please use `bin/rails routes -c controller_name` instead.", "Prefix Verb URI Pattern Controller#Action", " cart GET /cart(.:format) cart#show\n"].join("\n"), output @@ -183,7 +183,7 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rake routes -g show` } + output = Dir.chdir(app_path){ `bin/rails routes -g show` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end @@ -195,13 +195,13 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rake routes -c cart` } + output = Dir.chdir(app_path){ `bin/rails routes -c cart` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output - output = Dir.chdir(app_path){ `bin/rake routes -c Cart` } + output = Dir.chdir(app_path){ `bin/rails routes -c Cart` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output - output = Dir.chdir(app_path){ `bin/rake routes -c CartController` } + output = Dir.chdir(app_path){ `bin/rails routes -c CartController` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end -- cgit v1.2.3 From 33681d000147d8249d7e59bcc2189140c0831e7e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 3 Feb 2016 22:22:20 +0900 Subject: update supported version of PostgreSQL in docs [ci skip] Follow up to #23434 --- .../generators/rails/app/templates/config/databases/jdbcpostgresql.yml | 2 +- .../generators/rails/app/templates/config/databases/postgresql.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml index 9e99264d33..80ceb9df92 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml @@ -1,4 +1,4 @@ -# PostgreSQL. Versions 8.2 and up are supported. +# PostgreSQL. Versions 9.1 and up are supported. # # Configure Using Gemfile # gem 'activerecord-jdbcpostgresql-adapter' diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml index feb25bbc6b..d51b2ec199 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml @@ -1,4 +1,4 @@ -# PostgreSQL. Versions 8.2 and up are supported. +# PostgreSQL. Versions 9.1 and up are supported. # # Install the pg driver: # gem install pg -- cgit v1.2.3 From deae52a62ec6085b7b8d5f9db113946343266582 Mon Sep 17 00:00:00 2001 From: Alexey Zabelin Date: Wed, 3 Feb 2016 14:50:23 -0500 Subject: Add dummy apple icon files Previously Safari would try to load these files when you visit localhost:3000. That created two exceptions in the log. It also caused the exception notifier to send them out. In response to #23427 --- railties/CHANGELOG.md | 4 ++++ .../rails/app/templates/public/apple-touch-icon-precomposed.png | 0 .../rails/generators/rails/app/templates/public/apple-touch-icon.png | 0 3 files changed, 4 insertions(+) create mode 100644 railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png create mode 100644 railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 96149acc08..a1736470ae 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 5.0.0.beta2 (February 01, 2016) ## +* Add dummy files for apple-touch-icon.png and apple-touch-icon.png. GH#23427 + + *Alexey Zabelin* + * Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing templates to perform actions that are dependent upon `bundle install`. diff --git a/railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png b/railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png b/railties/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3 From e4f0608164b1a25bc3a35a1bd024efe425410758 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 3 Feb 2016 21:58:55 +0100 Subject: Fix line filters running tests from multiple runnables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `derive_regexp` was written with the assumption that we were run from a blank slate — that if the filter didn't match we might as well return it because it was nil. This isn't the case because minitest calls `run` on every runnable. Which is any subclass of Minitest::Runnable, such as ActiveSupport::TestCase, ActionDispatch::IntegrationTest as well as any inheriting from those. Thus after the first `run` we'd have put in a composite filter in `options[:filter]` making the next `run` create a linked list when it failed to match the regexp and put the composite filter as the head. Every runnable would accumulate more and more of the same filters, which effectively acted like an expanding whitelist and we ran tests from other runnables. Clog the accumulation by returning nil if there's no filter to derive a regexp from. Note: we pass a seed in the tests because Minitest shuffles the runnables to ensure the whitelist is expanded enough that the failure is triggered. --- railties/lib/rails/test_unit/line_filtering.rb | 2 +- railties/test/application/test_runner_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/test_unit/line_filtering.rb b/railties/lib/rails/test_unit/line_filtering.rb index dab4d3631d..b7635c71f4 100644 --- a/railties/lib/rails/test_unit/line_filtering.rb +++ b/railties/lib/rails/test_unit/line_filtering.rb @@ -26,7 +26,7 @@ module Rails private def derive_regexp(filter) # Regexp filtering copied from Minitest. - filter =~ %r%/(.*)/% ? Regexp.new($1) : filter + Regexp.new $1 if filter =~ %r%/(.*)/% end def derive_line_filters(patterns) diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index a7eb0feb11..33bc998722 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -382,6 +382,30 @@ module ApplicationTests end end + def test_line_filters_trigger_only_one_runnable + app_file 'test/models/post_test.rb', <<-RUBY + require 'test_helper' + + class PostTest < ActiveSupport::TestCase + test 'truth' do + assert true + end + end + + class SecondPostTest < ActiveSupport::TestCase + test 'truth' do + assert false, 'ran second runnable' + end + end + RUBY + + # Pass seed guaranteeing failure. + run_test_command('test/models/post_test.rb:4 --seed 30410').tap do |output| + assert_no_match 'ran second runnable', output + assert_match '1 runs, 1 assertions', output + end + end + def test_shows_filtered_backtrace_by_default create_backtrace_test -- cgit v1.2.3 From d10b48dd0aa00504212cb6f8598e5c1b7d0d968e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 3 Feb 2016 22:10:02 +0100 Subject: Fix model test path typo uncovered in previous commit. Because of the expanding whitelist for test filters, this test ended up running the tests on lines 4 and 9 in the post test even though the path wasn't right. Happened incidentally because the same line numbers were used in both account and post test. Add the .rb line so the file is required correctly and the filters are applied. --- railties/test/application/test_runner_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 33bc998722..821ac9b033 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -363,7 +363,7 @@ module ApplicationTests end RUBY - run_test_command('test/models/account_test.rb:4:9 test/models/post_test:4:9').tap do |output| + run_test_command('test/models/account_test.rb:4:9 test/models/post_test.rb:4:9').tap do |output| assert_match 'AccountTest:FirstFilter', output assert_match 'AccountTest:SecondFilter', output assert_match 'PostTest:FirstFilter', output -- cgit v1.2.3 From c7f8019bff16554095ff5c2c4e539962922b7a55 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 4 Feb 2016 06:44:37 +0900 Subject: Active Record supports MySQL >= 5.0 Currently some features uses `information_schema` (e.g. foreign key support). `information_schema` introduced since MySQL 5.0. --- .../rails/generators/rails/app/templates/config/databases/jdbcmysql.yml | 2 +- .../lib/rails/generators/rails/app/templates/config/databases/mysql.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml index 5ca549a8c8..f2c4922e7d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml @@ -1,4 +1,4 @@ -# MySQL. Versions 4.1 and 5.0 are recommended. +# MySQL. Versions 5.0 and up are supported. # # Install the MySQL driver: # gem install activerecord-jdbcmysql-adapter diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml index 119c2fe2c3..193423e84a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml @@ -1,4 +1,4 @@ -# MySQL. Versions 5.0+ are recommended. +# MySQL. Versions 5.0 and up are supported. # # Install the MySQL driver # gem install mysql2 -- cgit v1.2.3 From 2cd405f34077c2766eda9c3bea75989136eb5f13 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 4 Feb 2016 18:07:35 +0900 Subject: Revert "Lines of code can be 100,000+ in a Rails app" This reverts commit 293bd95c3e77275193130bc14c986348aae8b0e2. This broke the header :< --- railties/lib/rails/code_statistics.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index 0997414482..a4e22af45b 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -69,12 +69,12 @@ class CodeStatistics #:nodoc: def print_header print_splitter - puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |" + puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |" print_splitter end def print_splitter - puts "+----------------------+--------+--------+---------+---------+-----+-------+" + puts "+----------------------+-------+-------+---------+---------+-----+-------+" end def print_line(name, statistics) @@ -82,8 +82,8 @@ class CodeStatistics #:nodoc: loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0 puts "| #{name.ljust(20)} " \ - "| #{statistics.lines.to_s.rjust(6)} " \ - "| #{statistics.code_lines.to_s.rjust(6)} " \ + "| #{statistics.lines.to_s.rjust(5)} " \ + "| #{statistics.code_lines.to_s.rjust(5)} " \ "| #{statistics.classes.to_s.rjust(7)} " \ "| #{statistics.methods.to_s.rjust(7)} " \ "| #{m_over_c.to_s.rjust(3)} " \ -- cgit v1.2.3 From dfa48f200cbc5c1ca18457a8cde14642e12af594 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 4 Feb 2016 18:12:28 +0900 Subject: rake stats dynamically scales now So it can properly show stats for an app with 1,000,000+ LOC --- railties/lib/rails/code_statistics.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index a4e22af45b..fc8717c752 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -9,6 +9,8 @@ class CodeStatistics #:nodoc: 'Job tests', 'Integration tests'] + HEADERS = {lines: ' Lines', code_lines: ' LOC', classes: 'Classes', methods: 'Methods'} + def initialize(*pairs) @pairs = pairs @statistics = calculate_statistics @@ -67,27 +69,37 @@ class CodeStatistics #:nodoc: test_loc end + def width_for(label) + [@statistics.values.sum {|s| s.send(label) }.to_s.size, HEADERS[label].length].max + end + def print_header print_splitter - puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |" + print '| Name ' + HEADERS.each do |k, v| + print " | #{v.rjust(width_for(k))}" + end + puts ' | M/C | LOC/M |' print_splitter end def print_splitter - puts "+----------------------+-------+-------+---------+---------+-----+-------+" + print '+----------------------' + HEADERS.each_key do |k| + print "+#{'-' * (width_for(k) + 2)}" + end + puts '+-----+-------+' end def print_line(name, statistics) m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0 loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0 - puts "| #{name.ljust(20)} " \ - "| #{statistics.lines.to_s.rjust(5)} " \ - "| #{statistics.code_lines.to_s.rjust(5)} " \ - "| #{statistics.classes.to_s.rjust(7)} " \ - "| #{statistics.methods.to_s.rjust(7)} " \ - "| #{m_over_c.to_s.rjust(3)} " \ - "| #{loc_over_m.to_s.rjust(5)} |" + print "| #{name.ljust(20)} " + HEADERS.each_key do |k| + print "| #{statistics.send(k).to_s.rjust(width_for(k))} " + end + puts "| #{m_over_c.to_s.rjust(3)} | #{loc_over_m.to_s.rjust(5)} |" end def print_code_test_stats -- cgit v1.2.3 From 91864439c7aebb6ca710831aac6781903a433904 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 4 Feb 2016 12:16:57 +0100 Subject: Redis is now only needed if you want to use Action Cable in production So no need to have it on by default in the Gemfile. --- railties/lib/rails/generators/app_base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 8bc7dd63f9..8522f5196b 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -352,9 +352,9 @@ module Rails def cable_gemfile_entry return [] if options[:skip_action_cable] - comment = 'Action Cable dependencies for the Redis adapter' + comment = 'Use Redis adapter to run Action Cable in production' gems = [] - gems << GemfileEntry.new("redis", '~> 3.0', comment) + gems << GemfileEntry.new("redis", '~> 3.0', comment, {}, true) gems end -- cgit v1.2.3 From f2306d05d8b4e77741145be5ce63a1270655fed2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 4 Feb 2016 12:17:12 +0100 Subject: Turbolinks has moved out All grown up and shit! --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 8522f5196b..961efd05e3 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -326,7 +326,7 @@ module Rails unless options[:skip_turbolinks] gems << GemfileEntry.version("turbolinks", nil, - "Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks") + "Turbolinks makes following links in your web application faster. Read more: https://github.com/turbolinks/turbolinks") end gems -- cgit v1.2.3 From e0e872f6751ae653b07bd529267b4dcb5b7fca81 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Thu, 4 Feb 2016 19:40:23 +0530 Subject: Pass api only option to rails rails:update task to update only based on API. Fixes #23470 --- railties/lib/rails/tasks/framework.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 904b9d9ad6..7601836809 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -45,7 +45,7 @@ namespace :rails do @app_generator ||= begin require 'rails/generators' require 'rails/generators/rails/app/app_generator' - gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, + gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true, api: !!Rails.application.config.api_only }, destination_root: Rails.root File.exist?(Rails.root.join("config", "application.rb")) ? gen.send(:app_const) : gen.send(:valid_const?) -- cgit v1.2.3 From b1ae3a32b5ba3b53124ea12747d320800f2da8f5 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 4 Feb 2016 09:46:05 -0500 Subject: Update assertion on redis in generated Gemfile Redis now included in Gemfile but commented out. This change was made in 91864439c7aebb6ca710831aac6781903a433904 and is causing the test failure. See https://travis-ci.org/rails/rails/jobs/106994913#L1025 --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9595d2a0ef..b954738ff2 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -415,7 +415,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_action_cable_redis_gems run_generator - assert_gem 'redis' + assert_file "Gemfile", /^# gem 'redis'/ end def test_inclusion_of_javascript_runtime -- cgit v1.2.3 From c074343cffceaa8e5fc97db1f48e58dd8aff4723 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Thu, 4 Feb 2016 20:04:13 +0530 Subject: - app generate option --skip-sprockets leaves jquery-rails gem, which relies on sprockets environment - Remove jquery-rails if --skip-sprockets is true Fixes #23431 --- railties/lib/rails/generators/app_base.rb | 2 +- railties/test/generators/app_generator_test.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 961efd05e3..9b1e16a7a3 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -317,7 +317,7 @@ module Rails end def javascript_gemfile_entry - if options[:skip_javascript] + if options[:skip_javascript] || options[:skip_sprockets] [] else gems = [coffee_gemfile_entry, javascript_runtime_gemfile_entry] diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index b954738ff2..f483a0bcbd 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -385,9 +385,10 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) end assert_file "Gemfile" do |content| + assert_no_match(/jquery-rails/, content) assert_no_match(/sass-rails/, content) assert_no_match(/uglifier/, content) - assert_match(/coffee-rails/, content) + assert_no_match(/coffee-rails/, content) end assert_file "config/environments/development.rb" do |content| assert_no_match(/config\.assets\.debug = true/, content) -- cgit v1.2.3 From c9768b8a88039fffd160a859d91ed9d5aa618b87 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 5 Feb 2016 18:27:22 +0900 Subject: move CHANGELOG entry to the appropriate position [ci skip] Dummy apple icon files has been added after the 5.0.0.beta2 release. ref: #23455 --- railties/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index a1736470ae..8f4dc736a8 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,9 +1,9 @@ -## Rails 5.0.0.beta2 (February 01, 2016) ## - * Add dummy files for apple-touch-icon.png and apple-touch-icon.png. GH#23427 *Alexey Zabelin* +## Rails 5.0.0.beta2 (February 01, 2016) ## + * Add `after_bundle` callbacks in Rails plugin templates. Useful for allowing templates to perform actions that are dependent upon `bundle install`. -- cgit v1.2.3 From 84b72a812f9fb488241f06ec573dd751d52f7a67 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 4 Feb 2016 23:06:33 +0100 Subject: Fix mixing line filters with Minitest's -n filter. Previous commit accidentally broke mixing line filters with string -n filter. Fix by checking if it is a string and returning it. We also need to ensure the -n filter carry forward into any other composite filters. Fix by letting the named filter be extractable, so we'll keep this for the next runnable's run. --- railties/lib/rails/test_unit/line_filtering.rb | 16 ++++++++++++---- railties/test/application/test_runner_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/test_unit/line_filtering.rb b/railties/lib/rails/test_unit/line_filtering.rb index b7635c71f4..dd9732bb12 100644 --- a/railties/lib/rails/test_unit/line_filtering.rb +++ b/railties/lib/rails/test_unit/line_filtering.rb @@ -13,9 +13,12 @@ module Rails end class CompositeFilter # :nodoc: + attr_reader :named_filter + def initialize(runnable, filter, patterns) @runnable = runnable - @filters = [ derive_regexp(filter), *derive_line_filters(patterns) ].compact + @named_filter = derive_named_filter(filter) + @filters = [ @named_filter, *derive_line_filters(patterns) ].compact end # Minitest uses === to find matching filters. @@ -24,9 +27,14 @@ module Rails end private - def derive_regexp(filter) - # Regexp filtering copied from Minitest. - Regexp.new $1 if filter =~ %r%/(.*)/% + def derive_named_filter(filter) + if filter.respond_to?(:named_filter) + filter.named_filter + elsif filter =~ %r%/(.*)/% # Regexp filtering copied from Minitest. + Regexp.new $1 + elsif filter.is_a?(String) + filter + end end def derive_line_filters(patterns) diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 821ac9b033..7ecadb60ca 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -406,6 +406,30 @@ module ApplicationTests end end + def test_line_filter_with_minitest_string_filter + app_file 'test/models/post_test.rb', <<-RUBY + require 'test_helper' + + class PostTest < ActiveSupport::TestCase + test 'by line' do + puts 'by line' + assert true + end + + test 'by name' do + puts 'by name' + assert true + end + end + RUBY + + run_test_command('test/models/post_test.rb:4 -n test_by_name').tap do |output| + assert_match 'by line', output + assert_match 'by name', output + assert_match '2 runs, 2 assertions', output + end + end + def test_shows_filtered_backtrace_by_default create_backtrace_test -- cgit v1.2.3 From 91678fe9f78b498cc9919355213bc06b11841ce4 Mon Sep 17 00:00:00 2001 From: Genadi Samokovarov Date: Sat, 6 Feb 2016 09:14:42 +0200 Subject: Replace old Rails greeting references A couple of the READMEs were still referring the old welcome page. This is a small change that goes over it. [ci skip] --- railties/RDOC_MAIN.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/RDOC_MAIN.rdoc b/railties/RDOC_MAIN.rdoc index ce024563c4..26a25ee9dc 100644 --- a/railties/RDOC_MAIN.rdoc +++ b/railties/RDOC_MAIN.rdoc @@ -51,7 +51,7 @@ can read more about Action Pack in its {README}[link:files/actionpack/README_rdo 4. Go to http://localhost:3000 and you'll see: - "Welcome aboard: You're riding Ruby on Rails!" + "Yay! You’re on Rails!" 5. Follow the guidelines to start developing your application. You may find the following resources handy: -- cgit v1.2.3 From 00c64e8ae2c312139e5a242331d3919fe139b87c Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 6 Feb 2016 12:15:28 +0900 Subject: set association name to generated fixtures if attribute is reference It has been changed to require `belongs_to` by default in Rails 5. Therefore in order to pass the controller test, have association of set to fixtures. Fixes #23384 --- .../rails/generators/test_unit/model/templates/fixtures.yml | 2 +- railties/test/application/rake_test.rb | 9 ++++----- railties/test/generators/model_generator_test.rb | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index 2656767eb4..0681780c97 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -6,7 +6,7 @@ <%- if attribute.password_digest? -%> password_digest: <%%= BCrypt::Password.create('secret') %> <%- elsif attribute.reference? -%> - <%= yaml_key_value(attribute.column_name.sub(/_id$/, ''), attribute.default) %> + <%= yaml_key_value(attribute.column_name.sub(/_id$/, ''), attribute.default || name) %> <%- else -%> <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- end -%> diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 745a3e3ec5..3d3e47de8d 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -291,12 +291,11 @@ module ApplicationTests assert_no_match(/Errors running/, output) end - def test_scaffold_with_references_columns_tests_pass_when_belongs_to_is_optional - app_file "config/initializers/active_record_belongs_to_required_by_default.rb", - "Rails.application.config.active_record.belongs_to_required_by_default = false" - + def test_scaffold_with_references_columns_tests_pass_by_default output = Dir.chdir(app_path) do - `bin/rails generate scaffold LineItems product:references cart:belongs_to; + `bin/rails generate model Product; + bin/rails generate model Cart; + bin/rails generate scaffold LineItems product:references cart:belongs_to; RAILS_ENV=test bin/rails db:migrate test` end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 814f4c050e..c8c8f0aa3b 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -298,18 +298,18 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_fixtures_use_the_references_ids run_generator ["LineItem", "product:references", "cart:belongs_to"] - assert_file "test/fixtures/line_items.yml", /product: \n cart: / + assert_file "test/fixtures/line_items.yml", /product: one\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product"=>nil, "cart"=>nil}, "two"=>{"product"=>nil, "cart"=>nil}}) + {"one"=>{"product"=>"one", "cart"=>"one"}, "two"=>{"product"=>"two", "cart"=>"two"}}) end def test_fixtures_use_the_references_ids_and_type run_generator ["LineItem", "product:references{polymorphic}", "cart:belongs_to"] - assert_file "test/fixtures/line_items.yml", /product: \n product_type: Product\n cart: / + assert_file "test/fixtures/line_items.yml", /product: one\n product_type: Product\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product"=>nil, "product_type"=>"Product", "cart"=>nil}, - "two"=>{"product"=>nil, "product_type"=>"Product", "cart"=>nil}}) + {"one"=>{"product"=>"one", "product_type"=>"Product", "cart"=>"one"}, + "two"=>{"product"=>"two", "product_type"=>"Product", "cart"=>"two"}}) end def test_fixtures_respect_reserved_yml_keywords -- cgit v1.2.3 From 04021c4b78abc89045a7d3daf517a5d2dc63e5a7 Mon Sep 17 00:00:00 2001 From: Syamil MJ Date: Sun, 7 Feb 2016 04:07:48 +0800 Subject: Remove unused private method --- railties/lib/rails/rack/logger.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index aa7d3ca6c6..b63d3a58d2 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -72,10 +72,6 @@ module Rails instrumenter.finish 'request.action_dispatch', request: request end - def development? - Rails.env.development? - end - def logger Rails.logger end -- cgit v1.2.3 From ba2aea98079fb50a2c210001deb16ab84fac3b41 Mon Sep 17 00:00:00 2001 From: Scott Bronson Date: Sun, 7 Feb 2016 14:21:40 -0800 Subject: revert dev:cache to rake task, fixes #23410 --- railties/lib/rails/commands.rb | 1 - railties/lib/rails/commands/dev_cache.rb | 21 ------------------ railties/lib/rails/tasks.rb | 1 + railties/lib/rails/tasks/dev.rake | 14 ++++++++++++ railties/test/application/rake/dev_test.rb | 34 ++++++++++++++++++++++++++++++ railties/test/commands/dev_cache_test.rb | 32 ---------------------------- 6 files changed, 49 insertions(+), 54 deletions(-) delete mode 100644 railties/lib/rails/commands/dev_cache.rb create mode 100644 railties/lib/rails/tasks/dev.rake create mode 100644 railties/test/application/rake/dev_test.rb delete mode 100644 railties/test/commands/dev_cache_test.rb (limited to 'railties') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 7627fcf5a0..fa47c52b96 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -14,6 +14,5 @@ command = ARGV.shift command = aliases[command] || command require 'rails/command' -require 'rails/commands/dev_cache' Rails::Command.run(command, ARGV) diff --git a/railties/lib/rails/commands/dev_cache.rb b/railties/lib/rails/commands/dev_cache.rb deleted file mode 100644 index ec96e8f630..0000000000 --- a/railties/lib/rails/commands/dev_cache.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails/command' - -module Rails - module Commands - # This is a wrapper around the Rails dev:cache command - class DevCache < Command - set_banner :dev_cache, 'Toggle development mode caching on/off' - def dev_cache - if File.exist? 'tmp/caching-dev.txt' - File.delete 'tmp/caching-dev.txt' - puts 'Development mode is no longer being cached.' - else - FileUtils.touch 'tmp/caching-dev.txt' - puts 'Development mode is now being cached.' - end - - FileUtils.touch 'tmp/restart.txt' - end - end - end -end diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index d60eaf6f4f..d3e33584d7 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -3,6 +3,7 @@ require 'rake' # Load Rails Rakefile extensions %w( annotations + dev framework initializers log diff --git a/railties/lib/rails/tasks/dev.rake b/railties/lib/rails/tasks/dev.rake new file mode 100644 index 0000000000..4593100465 --- /dev/null +++ b/railties/lib/rails/tasks/dev.rake @@ -0,0 +1,14 @@ +namespace :dev do + desc 'Toggle development mode caching on/off' + task :cache do + if File.exist? 'tmp/caching-dev.txt' + File.delete 'tmp/caching-dev.txt' + puts 'Development mode is no longer being cached.' + else + FileUtils.touch 'tmp/caching-dev.txt' + puts 'Development mode is now being cached.' + end + + FileUtils.touch 'tmp/restart.txt' + end +end diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb new file mode 100644 index 0000000000..43d7a5e156 --- /dev/null +++ b/railties/test/application/rake/dev_test.rb @@ -0,0 +1,34 @@ +require 'isolation/abstract_unit' + +module ApplicationTests + module RakeTests + class RakeDevTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + test 'dev:cache creates file and outputs message' do + Dir.chdir(app_path) do + output = `rake dev:cache` + assert File.exist?('tmp/caching-dev.txt') + assert_match(/Development mode is now being cached/, output) + end + end + + test 'dev:cache deletes file and outputs message' do + Dir.chdir(app_path) do + `rails dev:cache` # Create caching file. + output = `rails dev:cache` # Delete caching file. + assert_not File.exist?('tmp/caching-dev.txt') + assert_match(/Development mode is no longer being cached/, output) + end + end + end + end +end diff --git a/railties/test/commands/dev_cache_test.rb b/railties/test/commands/dev_cache_test.rb deleted file mode 100644 index 1b7a72e7fc..0000000000 --- a/railties/test/commands/dev_cache_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../isolation/abstract_unit' - -module CommandsTests - class DevCacheTest < ActiveSupport::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - end - - def teardown - teardown_app - end - - test 'dev:cache creates file and outputs message' do - Dir.chdir(app_path) do - output = `rails dev:cache` - assert File.exist?('tmp/caching-dev.txt') - assert_match(%r{Development mode is now being cached}, output) - end - end - - test 'dev:cache deletes file and outputs message' do - Dir.chdir(app_path) do - `rails dev:cache` # Create caching file. - output = `rails dev:cache` # Delete caching file. - assert_not File.exist?('tmp/caching-dev.txt') - assert_match(%r{Development mode is no longer being cached}, output) - end - end - end -end -- cgit v1.2.3 From de6ad5665d2679944a9ee9407826ba88395a1003 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 10 Feb 2016 00:18:25 +0100 Subject: enables the evented monitor in new applications --- railties/CHANGELOG.md | 5 +++++ railties/lib/rails/generators/app_base.rb | 4 ++++ .../rails/generators/rails/app/templates/Gemfile | 3 +++ .../config/environments/development.rb.tt | 2 +- railties/test/generators/app_generator_test.rb | 22 ++++++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 8f4dc736a8..65fedbd659 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* New applications are generated with the evented file system monitor enabled + on Linux and Mac OS X. + + *Xavier Noria* + * Add dummy files for apple-touch-icon.png and apple-touch-icon.png. GH#23427 *Alexey Zabelin* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 9b1e16a7a3..8f8c2ec9e1 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -390,6 +390,10 @@ module Rails !options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin") end + def os_supports_listen_out_of_the_box? + RbConfig::CONFIG['host_os'] =~ /darwin|linux/ + end + def run_bundle bundle_command('install') if bundle_install? end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 3825dc4e38..c816c9e7e0 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -38,6 +38,9 @@ group :development do gem 'web-console', '~> 3.0' <%- end -%> <%- end -%> +<% if os_supports_listen_out_of_the_box? -%> + gem 'listen', '~> 3.0.5' +<% end -%> <% if spring_install? -%> # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' 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 fd41372d9c..3451ade158 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 @@ -58,5 +58,5 @@ Rails.application.configure do # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + <%= '# ' unless os_supports_listen_out_of_the_box? %>config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f483a0bcbd..f4d0b15546 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -479,6 +479,28 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_inclusion_of_listen_related_gems + run_generator + if RbConfig::CONFIG['host_os'] =~ /darwin|linux/ + assert_gem 'listen' + else + assert_file 'Gemfile' do |content| + assert_no_match(/listen/, content) + end + end + end + + def test_evented_file_update_checker_config + run_generator + assert_file 'config/environments/development.rb' do |content| + if RbConfig::CONFIG['host_os'] =~ /darwin|linux/ + assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + else + assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + end + end + end + def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) -- cgit v1.2.3 From 00a5eb6aeb1277472da5fe9e7dd02d003c766b13 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 10 Feb 2016 00:22:42 +0100 Subject: include spring-watcher-listen in the Gemfile of new applications --- railties/CHANGELOG.md | 5 +++++ railties/lib/rails/generators/rails/app/templates/Gemfile | 3 +++ railties/test/generators/app_generator_test.rb | 1 + 3 files changed, 9 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 65fedbd659..2506baac16 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* The Gemfiles of new applications include spring-watcher-listen on Linux and + Mac OS X (unless --skip-spring). + + *Xavier Noria* + * New applications are generated with the evented file system monitor enabled on Linux and Mac OS X. diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index c816c9e7e0..c3fad31f23 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -44,6 +44,9 @@ group :development do <% if spring_install? -%> # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' +<% if os_supports_listen_out_of_the_box? -%> + gem 'spring-watcher-listen', '~> 2.0.0' +<% end -%> <% end -%> end <% end -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f4d0b15546..be05e779ea 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -483,6 +483,7 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator if RbConfig::CONFIG['host_os'] =~ /darwin|linux/ assert_gem 'listen' + assert_gem 'spring-watcher-listen' else assert_file 'Gemfile' do |content| assert_no_match(/listen/, content) -- cgit v1.2.3 From bd6971812434e6f016977dc5c39fbc6450433471 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 10 Feb 2016 01:31:00 +0100 Subject: prevent apps in the railties test suite from running the evented monitor --- railties/test/isolation/abstract_unit.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index dddf8bd257..e7a261fa1f 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -154,6 +154,8 @@ module TestHelpers config.action_controller.allow_forgery_protection = false config.log_level = :info RUBY + + remove_from_env_config('development', 'config.file_watcher.*') end def teardown_app @@ -272,10 +274,17 @@ module TestHelpers end def remove_from_config(str) - file = "#{app_path}/config/application.rb" + remove_from_file("#{app_path}/config/application.rb", str) + end + + def remove_from_env_config(env, str) + remove_from_file("#{app_path}/config/environments/#{env}.rb", str) + end + + def remove_from_file(file, str) contents = File.read(file) - contents.sub!(/#{str}/, "") - File.open(file, "w+") { |f| f.puts contents } + contents.sub!(/#{str}/, '') + File.write(file, contents) end def app_file(path, contents, mode = 'w') -- cgit v1.2.3