From 02ba585f8d3fb8fcff53f22b5bbd10bcc8c8c037 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Thu, 5 Jan 2017 04:13:46 +1030 Subject: Simplify the version specifier generated by prereleases "~> 1.2.3.pre4" will automatically allow "1.2.4" -- no need for an explicit range. --- railties/lib/rails/generators/app_base.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ea88afe9f4..ef698bd4ac 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -261,14 +261,13 @@ module Rails end def rails_version_specifier(gem_version = Rails.gem_version) - if gem_version.prerelease? - next_series = gem_version - next_series = next_series.bump while next_series.segments.size > 2 - - [">= #{gem_version}", "< #{next_series}"] - elsif gem_version.segments.size == 3 + if gem_version.segments.size == 3 || gem_version.release.segments.size == 3 + # ~> 1.2.3 + # ~> 1.2.3.pre4 "~> #{gem_version}" else + # ~> 1.2.3, >= 1.2.3.4 + # ~> 1.2.3, >= 1.2.3.4.pre5 patch = gem_version.segments[0, 3].join(".") ["~> #{patch}", ">= #{gem_version}"] end -- cgit v1.2.3 From 4459a18db6fc9294d1f2553e45f59c859602dbad Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Wed, 4 Jan 2017 23:55:15 +0900 Subject: Fix generator command for nested (namespaced) rails engine (take 2) Rewrite https://github.com/rails/rails/pull/27550 085546df45 was reverted (b6ffb5efcb) because it change the return of `namespaced_path` from String to Array. ---------------- If we create nested (namespaced) rails engine such like bukkits-admin, `bin/rails g scaffold User name:string age:integer` will create `bukkits-admin/app/controllers/bukkits/users_controller.rb` but it should create `bukkits-admin/app/controllers/bukkits/admin/users_controller.rb`. In #6643, we changed `namespaced_path` as root path because we supposed application_controller is always in root but nested rails engine's application_controller will not. --- railties/lib/rails/generators/named_base.rb | 8 ++++++-- .../lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 6f1925928b..02557b098a 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -82,6 +82,10 @@ module Rails !options[:skip_namespace] && namespace end + def namespace_dirs + @namespace_dirs ||= namespace.name.split("::").map(&:underscore) + end + def file_path # :doc: @file_path ||= (class_path + [file_name]).join("/") end @@ -95,11 +99,11 @@ module Rails end def namespaced_class_path # :doc: - @namespaced_class_path ||= [namespaced_path] + @class_path + @namespaced_class_path ||= namespace_dirs + @class_path end def namespaced_path # :doc: - @namespaced_path ||= namespace.name.split("::").first.underscore + @namespaced_path ||= namespace_dirs.join("/") end def class_name # :doc: diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index 8840a86d0d..292db35121 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -22,7 +22,7 @@ module TestUnit # :nodoc: def fixture_name @fixture_name ||= if mountable_engine? - "%s_%s" % [namespaced_path, table_name] + (namespace_dirs + [table_name]).join("_") else table_name end -- cgit v1.2.3 From b7dbfe1b4d945a9f3c845f2929c460cb472ce794 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Tue, 31 Jan 2017 21:33:50 +0100 Subject: Avoid documenting private or external classes There are a lot of monkey patches inside the code base but there's no need to document external constants so let's remove them from the documentation Also, since there are monkey patches for some test cases classes, there were sometimes both documented and sneaked under the wrong section in the sidebar. Finally, for future references, the `active_support/vendor` folder has been originally ignored in https://git.io/vDqfA but no longer exists. [ci skip] --- railties/lib/rails/api/task.rb | 9 ++++++--- railties/lib/rails/test_help.rb | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb index bc670b1d75..101e8806d0 100644 --- a/railties/lib/rails/api/task.rb +++ b/railties/lib/rails/api/task.rb @@ -8,8 +8,7 @@ module Rails include: %w( README.rdoc lib/active_support/**/*.rb - ), - exclude: "lib/active_support/vendor/*" + ) }, "activerecord" => { @@ -69,7 +68,11 @@ module Rails README.rdoc lib/**/*.rb ), - exclude: "lib/rails/generators/rails/**/templates/**/*.rb" + exclude: %w( + lib/rails/generators/rails/**/templates/**/*.rb + lib/rails/test_unit/* + lib/rails/api/generator.rb + ) } } diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 5fda160012..0f9bf98737 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -14,10 +14,12 @@ require "active_support/testing/autorun" if defined?(ActiveRecord::Base) ActiveRecord::Migration.maintain_test_schema! - class ActiveSupport::TestCase - include ActiveRecord::TestFixtures - self.fixture_path = "#{Rails.root}/test/fixtures/" - self.file_fixture_path = fixture_path + "files" + module ActiveSupport + class TestCase + include ActiveRecord::TestFixtures + self.fixture_path = "#{Rails.root}/test/fixtures/" + self.file_fixture_path = fixture_path + "files" + end end ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path @@ -27,6 +29,8 @@ if defined?(ActiveRecord::Base) end end +# :enddoc: + class ActionController::TestCase def before_setup # :nodoc: @routes = Rails.application.routes -- cgit v1.2.3 From 870af0679e1a8a1b19053f1d559df5b74af4669f Mon Sep 17 00:00:00 2001 From: Bart de Water Date: Mon, 13 Feb 2017 09:25:08 -0500 Subject: Update backtrace cleaner to use `Regexp#match?` --- railties/lib/rails/backtrace_cleaner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 5c833e12ba..3bd18ebfb5 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -16,7 +16,7 @@ module Rails add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests add_gem_filters - add_silencer { |line| line !~ APP_DIRS_PATTERN } + add_silencer { |line| !APP_DIRS_PATTERN.match?(line) } end private -- cgit v1.2.3 From 56f098155bee7ce74d8ce2f5c1a343d3200c0458 Mon Sep 17 00:00:00 2001 From: Shota Iguchi Date: Wed, 15 Feb 2017 11:10:48 +0900 Subject: Add missing module namespacing wrapper refs: #28011 --- .../generators/test_unit/integration/templates/integration_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb index dea7e22196..118e0f1271 100644 --- a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb +++ b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb @@ -1,7 +1,9 @@ require 'test_helper' +<% module_namespacing do -%> class <%= class_name %>Test < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end end +<% end -%> -- cgit v1.2.3 From f38a660a60ecc5e2f0e0f91e07a18344598cff5e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 8 Feb 2017 18:24:50 +0900 Subject: Prevent multiple values being set to `run_via` When executing the test via rake, since `rake` is set for `run_via`, `ruby` should not be set. Related 2cb6c27310452da11b93d729c3b760ce988106e1 --- railties/lib/rails/commands/test/test_command.rb | 2 +- .../generators/rails/plugin/templates/bin/test.tt | 2 +- railties/lib/rails/test_unit/minitest_plugin.rb | 34 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 7bf8f61137..629fb5b425 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -11,7 +11,7 @@ module Rails def perform(*) $LOAD_PATH << Rails::Command.root.join("test") - Minitest.run_via[:rails] = true + Minitest.run_via = :rails require "active_support/testing/autorun" end diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt index c0fbb84a93..35a9bf8c8b 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt @@ -5,6 +5,6 @@ require 'rails/test_unit/minitest_plugin' Rails::TestUnitReporter.executable = 'bin/test' -Minitest.run_via[:rails] = true +Minitest.run_via = :rails require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index 4df3e7f0f2..7d3da6b529 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -59,18 +59,18 @@ module Minitest options[:color] = true options[:output_inline] = true - options[:patterns] = opts.order! unless run_via[:rake] + options[:patterns] = opts.order! unless run_via.rake? end def self.rake_run(patterns) # :nodoc: - run_via[:rake] = true + self.run_via = :rake unless run_via.set? ::Rails::TestRequirer.require_files(patterns) autorun end module RunRespectingRakeTestopts def run(args = []) - if run_via[:rake] + if run_via.rake? args = Shellwords.split(ENV["TESTOPTS"] || "") end @@ -87,7 +87,7 @@ module Minitest # If run via `ruby` we've been passed the files to run directly, or if run # via `rake` then they have already been eagerly required. - unless run_via[:ruby] || run_via[:rake] + unless run_via.ruby? || run_via.rake? ::Rails::TestRequirer.require_files(options[:patterns]) end @@ -102,7 +102,31 @@ module Minitest reporter << ::Rails::TestUnitReporter.new(options[:io], options) end - mattr_accessor(:run_via) { Hash.new } + def self.run_via=(runner) + if run_via.set? + raise ArgumentError, "run_via already assigned" + else + run_via.runner = runner + end + end + + class RunVia + attr_accessor :runner + alias set? runner + + # Backwardscompatibility with Rails 5.0 generated plugin test scripts. + alias []= runner= + + def ruby? + runner == :ruby + end + + def rake? + runner == :rake + end + end + + mattr_reader(:run_via) { RunVia.new } end # Put Rails as the first plugin minitest initializes so other plugins -- cgit v1.2.3 From 38c2373b5bc4bc66cc424c5e0d6cce5d4ad94df0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 18 Feb 2017 10:59:46 +0900 Subject: Do not run `git init` in dummy application --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 49259f32c8..be211e016d 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -91,6 +91,7 @@ task default: :test opts[:skip_bundle] = true opts[:api] = options.api? opts[:skip_listen] = true + opts[:skip_git] = true invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts @@ -112,7 +113,6 @@ task default: :test def test_dummy_clean inside dummy_path do - remove_file ".gitignore" remove_file "db/seeds.rb" remove_file "doc" remove_file "Gemfile" -- cgit v1.2.3 From e51572dce00c5f011f019397984ed8e82d94fc84 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sat, 18 Feb 2017 22:14:48 +0100 Subject: Share the common implementation between apps and engines. --- railties/lib/rails/command/actions.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/command/actions.rb b/railties/lib/rails/command/actions.rb index fb80e9d997..8fda1c87c6 100644 --- a/railties/lib/rails/command/actions.rb +++ b/railties/lib/rails/command/actions.rb @@ -8,16 +8,16 @@ module Rails Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru")) end - if defined?(ENGINE_PATH) - def require_application_and_environment! - require ENGINE_PATH + def require_application_and_environment! + require ENGINE_PATH if defined?(ENGINE_PATH) - if defined?(APP_PATH) - require APP_PATH - Rails.application.require_environment! - end + if defined?(APP_PATH) + require APP_PATH + Rails.application.require_environment! end + end + if defined?(ENGINE_PATH) def load_tasks Rake.application.init("rails") Rake.application.load_rakefile @@ -29,11 +29,6 @@ module Rails engine.load_generators end else - def require_application_and_environment! - require APP_PATH - Rails.application.require_environment! - end - def load_tasks Rails.application.load_tasks end -- cgit v1.2.3 From 5be10c793650f98b69a13aa3d291b5e9b9fda3ea Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Tue, 31 Jan 2017 22:04:56 +0100 Subject: Properly nest core classes under a "Core Extensions" label Since Active Support is monkey patching a lot of core classes, let's rather document these changes under a new section so they are still documented but not encumbering the sidebar. We can safely remove the rescuing of the `LoadError` since as of cd7cc525, it's not possible to generate the API from an application. [ci skip] [Kasper Timm Hansen & Robin Dupret] --- railties/lib/rails/api/generator.rb | 28 ++++++++++++++++++++++++++++ railties/lib/rails/api/task.rb | 14 +++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 railties/lib/rails/api/generator.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/api/generator.rb b/railties/lib/rails/api/generator.rb new file mode 100644 index 0000000000..dcc491783c --- /dev/null +++ b/railties/lib/rails/api/generator.rb @@ -0,0 +1,28 @@ +require "sdoc" + +class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc: + RDoc::RDoc.add_generator self + + def generate_class_tree_level(classes, visited = {}) + # Only process core extensions on the first visit. + if visited.empty? + core_exts, classes = classes.partition { |klass| core_extension?(klass) } + + super.unshift([ "Core extensions", "", "", build_core_ext_subtree(core_exts, visited) ]) + else + super + end + end + + private + def build_core_ext_subtree(classes, visited) + classes.map do |klass| + [ klass.name, klass.document_self_or_methods ? klass.path : "", "", + generate_class_tree_level(klass.classes_and_modules, visited) ] + end + end + + def core_extension?(klass) + klass.name != "ActiveSupport" && klass.in_files.any? { |file| file.absolute_name.include?("core_ext") } + end +end diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb index 101e8806d0..d1f984be1d 100644 --- a/railties/lib/rails/api/task.rb +++ b/railties/lib/rails/api/task.rb @@ -1,4 +1,5 @@ require "rdoc/task" +require "rails/api/generator" module Rails module API @@ -83,7 +84,7 @@ module Rails # Be lazy computing stuff to have as light impact as possible to # the rest of tasks. before_running_rdoc do - load_and_configure_sdoc + configure_sdoc configure_rdoc_files setup_horo_variables end @@ -94,20 +95,15 @@ module Rails # no-op end - def load_and_configure_sdoc - require "sdoc" - + def configure_sdoc self.title = "Ruby on Rails API" self.rdoc_dir = api_dir options << "-m" << api_main options << "-e" << "UTF-8" - options << "-f" << "sdoc" + options << "-f" << "api" options << "-T" << "rails" - rescue LoadError - $stderr.puts %(Unable to load SDoc, please add\n\n gem 'sdoc', require: false\n\nto the Gemfile.) - exit 1 end def configure_rdoc_files @@ -150,7 +146,7 @@ module Rails end class RepoTask < Task - def load_and_configure_sdoc + def configure_sdoc super options << "-g" # link to GitHub, SDoc flag end -- cgit v1.2.3 From 5b9aa43bc8dafcc2a00eb43741c495262f5ca45e Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 5 Aug 2016 09:36:54 -0400 Subject: Add generators and ability to run system tests * Generates system test requirements with new Rails app * Includes required default gems in Gemfile for Rails app * Generates a single system test case * Generates a system test case with scaffold --- railties/lib/rails/generators.rb | 2 ++ railties/lib/rails/generators/app_base.rb | 3 +++ railties/lib/rails/generators/rails/app/app_generator.rb | 8 ++++++++ railties/lib/rails/generators/rails/app/templates/Gemfile | 5 +++++ .../generators/rails/app/templates/config/application.rb | 1 + .../generators/rails/plugin/templates/rails/application.rb | 1 + .../rails/generators/rails/scaffold/scaffold_generator.rb | 2 ++ railties/lib/rails/generators/rails/system_test/USAGE | 10 ++++++++++ .../generators/rails/system_test/system_test_generator.rb | 7 +++++++ .../rails/generators/test_unit/system/system_generator.rb | 13 +++++++++++++ .../generators/test_unit/system/templates/system_test.rb | 7 +++++++ railties/lib/rails/tasks/statistics.rake | 1 + railties/lib/rails/test_unit/railtie.rb | 1 + railties/lib/rails/test_unit/testing.rake | 5 +++++ 14 files changed, 66 insertions(+) create mode 100644 railties/lib/rails/generators/rails/system_test/USAGE create mode 100644 railties/lib/rails/generators/rails/system_test/system_test_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/system/system_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/system/templates/system_test.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 99bda728ee..cbcbe70fdd 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -53,6 +53,7 @@ module Rails force_plural: false, helper: true, integration_tool: nil, + system_tool: nil, javascripts: true, javascript_engine: :js, orm: false, @@ -151,6 +152,7 @@ module Rails "#{test}:controller", "#{test}:helper", "#{test}:integration", + "#{test}:system", "#{test}:mailer", "#{test}:model", "#{test}:scaffold", diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ea88afe9f4..e55da93f45 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -82,6 +82,9 @@ module Rails class_option :skip_test, type: :boolean, aliases: "-T", default: false, desc: "Skip test files" + class_option :skip_system_test, type: :boolean, default: false, + desc: "Skip system test files" + class_option :dev, type: :boolean, default: false, desc: "Setup the #{name} with Gemfile pointing to your Rails checkout" diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 3cf923faf0..00839c5d4c 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -150,6 +150,10 @@ module Rails template "test/test_helper.rb" end + def system_test + empty_directory_with_keep_file "test/system" + end + def tmp empty_directory_with_keep_file "tmp" empty_directory "tmp/cache" @@ -262,6 +266,10 @@ module Rails build(:test) unless options[:skip_test] end + def create_system_test_files + build(:system_test) unless options[:skip_system_test] || options[:skip_test] || options[:api] + end + def create_tmp_files build(:tmp) end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 24d2fa1284..b082d70cba 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -32,6 +32,11 @@ end group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + <%- unless options.skip_system_test? || options.api? -%> + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '~> 2.7.0' + gem 'selenium-webdriver' + <%- end -%> end group :development do diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index c0a0bd0a3e..2488c79da3 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -14,6 +14,7 @@ require "action_view/railtie" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_sprockets %>require "sprockets/railtie" <%= comment_if :skip_test %>require "rails/test_unit/railtie" +<%= comment_if :skip_system_test %>require "system_testing/railtie" <% end -%> # Require the gems listed in Gemfile, including any gems diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb index d03b1be878..2dc9cc67a6 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb @@ -11,6 +11,7 @@ require "action_view/railtie" require "active_job/railtie" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_test %>require "rails/test_unit/railtie" +<%= comment_if :skip_system_test %>require "system_testing/railtie" <%= comment_if :skip_sprockets %>require "sprockets/railtie" <% end -%> diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index ed6bf7f7d7..bcaa424ca8 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -19,6 +19,8 @@ module Rails hook_for :scaffold_controller, required: true + hook_for :system_tool, as: :system + hook_for :assets do |assets| invoke assets, [controller_name] end diff --git a/railties/lib/rails/generators/rails/system_test/USAGE b/railties/lib/rails/generators/rails/system_test/USAGE new file mode 100644 index 0000000000..f11a99e008 --- /dev/null +++ b/railties/lib/rails/generators/rails/system_test/USAGE @@ -0,0 +1,10 @@ +Description: + Stubs out a new system test. Pass the name of the test, either + CamelCased or under_scored, as an argument. + + This generator invokes the current system tool, which defaults to + TestUnit. + +Example: + `rails generate system_test GeneralStories` creates a GeneralStories + system test in test/system/general_stories_test.rb diff --git a/railties/lib/rails/generators/rails/system_test/system_test_generator.rb b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb new file mode 100644 index 0000000000..35bc168898 --- /dev/null +++ b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb @@ -0,0 +1,7 @@ +module Rails + module Generators + class SystemTestGenerator < NamedBase # :nodoc: + hook_for :system_tool, as: :system + end + end +end diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb new file mode 100644 index 0000000000..4d3b37e645 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit # :nodoc: + module Generators # :nodoc: + class SystemGenerator < Base # :nodoc: + check_class_collision suffix: "Test" + + def create_test_files + template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb new file mode 100644 index 0000000000..75825c880d --- /dev/null +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class <%= class_name.pluralize %>Test < Rails::SystemTestCase + # test 'the truth' do + # assert true + # end +end diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index ba1697186e..cb569be58b 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -17,6 +17,7 @@ STATS_DIRECTORIES = [ %w(Mailer\ tests test/mailers), %w(Job\ tests test/jobs), %w(Integration\ tests test/integration), + %w(System\ tests test/system), ].collect do |name, dir| [ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ] end.select { |name, dir| File.directory?(dir) } diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index 746120e6a1..d3f52e8008 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -11,6 +11,7 @@ module Rails fixture_replacement: nil c.integration_tool :test_unit + c.system_tool :test_unit end initializer "test_unit.line_filtering" do diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 4c157c1262..4dde3d3c97 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -47,4 +47,9 @@ namespace :test do $: << "test" Minitest.rake_run(["test/controllers", "test/mailers", "test/functional"]) end + + task system: "test:prepare" do + $: << "test" + Minitest.rake_run(["test/system"]) + end end -- cgit v1.2.3 From 97d8b7abfe75b6a7617966ad0b3d37ae9fc7adb8 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 5 Aug 2016 09:58:43 -0400 Subject: Add skeleton for Rails::SystemTestCase This skelton is the bare minimum to get system tests to actually run in an application. This of course doesn't yet actually run a test but it is enough for `bin/rails test:system` to attempt to run files in `test/system` that inherit from `Rails::SystemTestCase`. --- railties/lib/rails/test_help.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 0f9bf98737..468b50c0f8 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,6 +7,7 @@ require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" +require 'system_test_case' require "rails/generators/test_case" require "active_support/testing/autorun" @@ -44,3 +45,10 @@ class ActionDispatch::IntegrationTest super end end + +class Rails::SystemTestCase + def before_setup # :nodoc: + @routes = Rails.application.routes + super + end +end -- cgit v1.2.3 From 0dc63281da1c7075ce63d8dba62e4230d72bfc2a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 7 Aug 2016 09:01:16 -0400 Subject: Add configuration option for driver adapter This allows any application to change the driver adapter based on the config settings in the test env. --- railties/lib/rails/all.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 7606ea0e46..73d6efdc9f 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -9,6 +9,7 @@ require "rails" action_cable/engine rails/test_unit/railtie sprockets/railtie + system_testing/railtie ).each do |railtie| begin require railtie -- cgit v1.2.3 From a21e18d5080a2c4808330271885f5664a725d3f3 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 4 Oct 2016 08:48:21 -0400 Subject: Appease Rubocop Rubocop / code climate don't like single quotes and prefer doubles. --- railties/lib/rails/generators/test_unit/system/system_generator.rb | 2 +- railties/lib/rails/test_help.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index 4d3b37e645..a05f0f924d 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -1,4 +1,4 @@ -require 'rails/generators/test_unit' +require "rails/generators/test_unit" module TestUnit # :nodoc: module Generators # :nodoc: diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 468b50c0f8..ab4d371b49 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,7 +7,7 @@ require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" -require 'system_test_case' +require "system_test_case" require "rails/generators/test_case" require "active_support/testing/autorun" -- cgit v1.2.3 From 5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 6 Nov 2016 18:55:15 -0500 Subject: Turn system testing into it's own gem and rename Renames `Rails::SystemTestCase` to `ActionSystemTest` and moves it to a gem under the Rails name. We need to name the class `ActionSystemTestCase` because the gem expects a module but tests themselves expect a class. Adds MIT-LICENSE, CHANGELOG, and README for the future. --- railties/lib/rails/all.rb | 2 +- .../lib/rails/generators/rails/app/templates/config/application.rb | 1 - .../lib/rails/generators/rails/plugin/templates/rails/application.rb | 1 - .../lib/rails/generators/test_unit/system/templates/system_test.rb | 2 +- railties/lib/rails/test_help.rb | 4 ++-- 5 files changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 73d6efdc9f..2cc33ceb5e 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -9,7 +9,7 @@ require "rails" action_cable/engine rails/test_unit/railtie sprockets/railtie - system_testing/railtie + action_system_test/railtie ).each do |railtie| begin require railtie diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 2488c79da3..c0a0bd0a3e 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -14,7 +14,6 @@ require "action_view/railtie" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_sprockets %>require "sprockets/railtie" <%= comment_if :skip_test %>require "rails/test_unit/railtie" -<%= comment_if :skip_system_test %>require "system_testing/railtie" <% end -%> # Require the gems listed in Gemfile, including any gems diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb index 2dc9cc67a6..d03b1be878 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb @@ -11,7 +11,6 @@ require "action_view/railtie" require "active_job/railtie" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_test %>require "rails/test_unit/railtie" -<%= comment_if :skip_system_test %>require "system_testing/railtie" <%= comment_if :skip_sprockets %>require "sprockets/railtie" <% end -%> diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb index 75825c880d..a74e0bb23d 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class <%= class_name.pluralize %>Test < Rails::SystemTestCase +class <%= class_name.pluralize %>Test < ActionSystemTestCase # test 'the truth' do # assert true # end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index ab4d371b49..68fc317a60 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,7 +7,7 @@ require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" -require "system_test_case" +require "action_system_test" require "rails/generators/test_case" require "active_support/testing/autorun" @@ -46,7 +46,7 @@ class ActionDispatch::IntegrationTest end end -class Rails::SystemTestCase +class ActionSystemTestCase def before_setup # :nodoc: @routes = Rails.application.routes super -- cgit v1.2.3 From 1db7a5c285eeb61acc998c0c27788a61bd948d5c Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 7 Nov 2016 15:46:56 -0500 Subject: Don't load ActionSystemTest in production By moving to the TestUnit Railtie, and doing the file requirement inside the onload call we can avoid loading ActionSystemTest in production and load it in the test env. This is important for performance reasons - loading up unnecessary files and object is expensive, especially when they should never be used in production. --- railties/lib/rails/all.rb | 1 - railties/lib/rails/test_unit/railtie.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 2cc33ceb5e..7606ea0e46 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -9,7 +9,6 @@ require "rails" action_cable/engine rails/test_unit/railtie sprockets/railtie - action_system_test/railtie ).each do |railtie| begin require railtie diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index d3f52e8008..694c8d92b1 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -20,6 +20,18 @@ module Rails } end + config.system_testing = ActiveSupport::OrderedOptions.new + + initializer "system_testing.set_configs" do |app| + ActiveSupport.on_load(:active_support_test_case) do + require "action_system_test" + + options = app.config.system_testing + options.driver ||= ActionSystemTest.default_driver + options.each { |k, v| ActionSystemTest.send("#{k}=", v) } + end + end + rake_tasks do load "rails/test_unit/testing.rake" end -- cgit v1.2.3 From 84f82f0a84de0906d195b529a9f780141c43507a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 12 Nov 2016 09:49:28 -0500 Subject: Refactor config settings to use generated file Originally I had set up system testing to have one configuration option to be set in the test environment. After thinking it over I think a generated class on app creation would be best. The reason for this is Capybara has a ton of configuration options that I'm sure some folks want to use. Thinking about how we handle screenshots, database transactions, and a whole bunch of other settings it would be better for users to be able to turn all of that on and off. When an app or scaffold is generated a `test/system_test_helper.rb` test helper will be generated as well. This will contain the class for tests to inherit from `ActionSystemTestCase` which will inherit from `ActionSystemTest::Base`. Here is where users can change the test driver, remove the screenshot helper, and add their additional Capybara configuration. --- railties/lib/rails/generators.rb | 2 +- railties/lib/rails/generators/rails/app/app_generator.rb | 2 ++ .../rails/app/templates/test/system_test_helper.rb | 8 ++++++++ .../rails/plugin/templates/test/system_test_helper.rb | 8 ++++++++ .../rails/generators/rails/scaffold/scaffold_generator.rb | 4 +++- .../generators/rails/system_test/system_test_generator.rb | 2 +- .../rails/generators/test_unit/system/system_generator.rb | 6 +++++- .../generators/test_unit/system/templates/system_test.rb | 2 +- .../test_unit/system/templates/system_test_helper.rb | 8 ++++++++ railties/lib/rails/test_help.rb | 2 +- railties/lib/rails/test_unit/railtie.rb | 14 +------------- 11 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb create mode 100644 railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb create mode 100644 railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index cbcbe70fdd..85f66cc416 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -53,7 +53,6 @@ module Rails force_plural: false, helper: true, integration_tool: nil, - system_tool: nil, javascripts: true, javascript_engine: :js, orm: false, @@ -63,6 +62,7 @@ module Rails stylesheets: true, stylesheet_engine: :css, scaffold_stylesheet: true, + system_tests: nil, test_framework: false, template_engine: :erb } diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 00839c5d4c..acdb66ca85 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -152,6 +152,8 @@ module Rails def system_test empty_directory_with_keep_file "test/system" + + template "test/system_test_helper.rb" end def tmp diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index bcaa424ca8..12d6bc85b2 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -6,6 +6,7 @@ module Rails remove_hook_for :resource_controller remove_class_option :actions + class_option :api, type: :boolean class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets" class_option :stylesheet_engine, desc: "Engine for Stylesheets" class_option :assets, type: :boolean @@ -15,11 +16,12 @@ module Rails def handle_skip @options = @options.merge(stylesheets: false) unless options[:assets] @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet] + @options = @options.merge(system_tests: false) if options[:api] end hook_for :scaffold_controller, required: true - hook_for :system_tool, as: :system + hook_for :system_tests, as: :system hook_for :assets do |assets| invoke assets, [controller_name] diff --git a/railties/lib/rails/generators/rails/system_test/system_test_generator.rb b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb index 35bc168898..901120e892 100644 --- a/railties/lib/rails/generators/rails/system_test/system_test_generator.rb +++ b/railties/lib/rails/generators/rails/system_test/system_test_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class SystemTestGenerator < NamedBase # :nodoc: - hook_for :system_tool, as: :system + hook_for :system_tests, as: :system end end end diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index a05f0f924d..e77ccef009 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -6,7 +6,11 @@ module TestUnit # :nodoc: check_class_collision suffix: "Test" def create_test_files - template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") + if !File.exist?(File.join("test/system_test_helper.rb")) + template "system_test_helper.rb", File.join("test", "system_test_helper.rb") + end + + template "system_test.rb", File.join("test/system", "#{file_name.pluralize}_test.rb") end end end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb index a74e0bb23d..bc3abd25d9 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "system_test_helper" class <%= class_name.pluralize %>Test < ActionSystemTestCase # test 'the truth' do diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb new file mode 100644 index 0000000000..77c4738d6f --- /dev/null +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ActionSystemTestCase < ActionSystemTest::Base + teardown do + take_failed_screenshot + Capybara.reset_sessions! + end +end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 68fc317a60..98bfddb197 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -46,7 +46,7 @@ class ActionDispatch::IntegrationTest end end -class ActionSystemTestCase +class ActionSystemTest::Base def before_setup # :nodoc: @routes = Rails.application.routes super diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index 694c8d92b1..9cc3f73a9c 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -11,7 +11,7 @@ module Rails fixture_replacement: nil c.integration_tool :test_unit - c.system_tool :test_unit + c.system_tests :test_unit end initializer "test_unit.line_filtering" do @@ -20,18 +20,6 @@ module Rails } end - config.system_testing = ActiveSupport::OrderedOptions.new - - initializer "system_testing.set_configs" do |app| - ActiveSupport.on_load(:active_support_test_case) do - require "action_system_test" - - options = app.config.system_testing - options.driver ||= ActionSystemTest.default_driver - options.each { |k, v| ActionSystemTest.send("#{k}=", v) } - end - end - rake_tasks do load "rails/test_unit/testing.rake" end -- cgit v1.2.3 From 1a0ca84a064b07ecab798793a3d7ebe89bb6367c Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 11:50:42 -0500 Subject: Move and rename system tests * Move system tests back into Action Pack * Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase` * Remove private base module and only make file for public `SystemTestCase` class, name private module `SystemTesting` * Rename `ActionSystemTestCase` to `ApplicationSystemTestCase` * Update corresponding documentation and guides * Delete old `ActionSystemTest` files --- .../generators/rails/app/templates/test/system_test_helper.rb | 2 +- .../generators/rails/plugin/templates/test/system_test_helper.rb | 2 +- .../rails/generators/test_unit/system/templates/system_test.rb | 8 +++++--- .../generators/test_unit/system/templates/system_test_helper.rb | 2 +- railties/lib/rails/test_help.rb | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb index 77c4738d6f..1d0ae787f7 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -1,6 +1,6 @@ require "test_helper" -class ActionSystemTestCase < ActionSystemTest::Base +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase teardown do take_failed_screenshot Capybara.reset_sessions! diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb index 77c4738d6f..1d0ae787f7 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -1,6 +1,6 @@ require "test_helper" -class ActionSystemTestCase < ActionSystemTest::Base +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase teardown do take_failed_screenshot Capybara.reset_sessions! diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb index bc3abd25d9..2afc7a4aac 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb @@ -1,7 +1,9 @@ require "system_test_helper" -class <%= class_name.pluralize %>Test < ActionSystemTestCase - # test 'the truth' do - # assert true +class <%= class_name.pluralize %>Test < ApplicationSystemTestCase + # test "visiting the index" do + # visit <%= plural_table_name %>_url + # + # assert_selector "h1", text: "<%= class_name %>" # end end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb index 77c4738d6f..1d0ae787f7 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -1,6 +1,6 @@ require "test_helper" -class ActionSystemTestCase < ActionSystemTest::Base +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase teardown do take_failed_screenshot Capybara.reset_sessions! diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 98bfddb197..75171f2395 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,7 +7,7 @@ require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" -require "action_system_test" +require "action_dispatch/system_test_case" require "rails/generators/test_case" require "active_support/testing/autorun" @@ -46,7 +46,7 @@ class ActionDispatch::IntegrationTest end end -class ActionSystemTest::Base +class ActionDispatch::SystemTestCase def before_setup # :nodoc: @routes = Rails.application.routes super -- cgit v1.2.3 From dbb60ff588f770d01b4b4ebc3905ff305c92ddd1 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 11:54:17 -0500 Subject: Add default configuration to generated system test helper This serves as self documentation so users know how to change the driver. --- .../lib/rails/generators/rails/app/templates/test/system_test_helper.rb | 2 ++ .../rails/generators/rails/plugin/templates/test/system_test_helper.rb | 2 ++ .../rails/generators/test_unit/system/templates/system_test_helper.rb | 2 ++ 3 files changed, 6 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb index 1d0ae787f7..440689b503 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -1,6 +1,8 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + teardown do take_failed_screenshot Capybara.reset_sessions! diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb index 1d0ae787f7..440689b503 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -1,6 +1,8 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + teardown do take_failed_screenshot Capybara.reset_sessions! diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb index 1d0ae787f7..440689b503 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -1,6 +1,8 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + teardown do take_failed_screenshot Capybara.reset_sessions! -- cgit v1.2.3 From 161cf89e134267f9b579f493ca19b12c30d5fd36 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 17:49:21 -0500 Subject: Fix default host in setup, move teardown to helper file * Override integration test default host Integration tests automatically set the default host to 'http://example.com'. This works fine for integration tests because they are not real browser sessions, but doesn't work fine for system tests because they are real browser sessions. We can override this by setting the `host!` in `before_setup. The `Capybara.always_include_port` will allow the test to look at `127.0.0.1:port capybara picks` and properly redirect the test. Any application can override this by setting the `host!` in their system test helper. Generally though, applications are going to be using localhost. In this commit I also moved the setup and teardown into their own module for tidiness. * Move teardown settings into system test case These configuration options can be put into the system test case file instead of the generated system tests helper file. This is an implementation detail and therefore shouldn't be generated with the template. --- .../rails/generators/rails/app/templates/test/system_test_helper.rb | 5 ----- .../generators/rails/plugin/templates/test/system_test_helper.rb | 5 ----- .../generators/test_unit/system/templates/system_test_helper.rb | 5 ----- 3 files changed, 15 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end -- cgit v1.2.3 From 2d61c5d846f8dd3a02080fedce7ab63b8d314db6 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 20 Feb 2017 14:38:46 -0500 Subject: Rename system_test_helper -> application_system_test_case This renames the system test helper file to be application system test case to match what the rest of Rails does. In the future we should consider changing the test_helper to match. --- railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- .../rails/app/templates/test/application_system_test_case.rb | 5 +++++ .../rails/generators/rails/app/templates/test/system_test_helper.rb | 5 ----- .../rails/plugin/templates/test/application_system_test_case.rb | 5 +++++ .../generators/rails/plugin/templates/test/system_test_helper.rb | 5 ----- railties/lib/rails/generators/test_unit/system/system_generator.rb | 4 ++-- .../test_unit/system/templates/application_system_test_case.rb | 5 +++++ .../lib/rails/generators/test_unit/system/templates/system_test.rb | 2 +- .../generators/test_unit/system/templates/system_test_helper.rb | 5 ----- 9 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb delete mode 100644 railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb create mode 100644 railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb delete mode 100644 railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb create mode 100644 railties/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb delete mode 100644 railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index acdb66ca85..18e48c8016 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -153,7 +153,7 @@ module Rails def system_test empty_directory_with_keep_file "test/system" - template "test/system_test_helper.rb" + template "test/application_system_test_case.rb" end def tmp diff --git a/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb b/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb deleted file mode 100644 index d19212abd5..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb b/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb deleted file mode 100644 index d19212abd5..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index e77ccef009..aec415a4e5 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -6,8 +6,8 @@ module TestUnit # :nodoc: check_class_collision suffix: "Test" def create_test_files - if !File.exist?(File.join("test/system_test_helper.rb")) - template "system_test_helper.rb", File.join("test", "system_test_helper.rb") + if !File.exist?(File.join("test/application_system_test_case.rb")) + template "application_system_test_case.rb", File.join("test", "application_system_test_case.rb") end template "system_test.rb", File.join("test/system", "#{file_name.pluralize}_test.rb") diff --git a/railties/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb b/railties/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb index 2afc7a4aac..b5ce2ba5c8 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test.rb @@ -1,4 +1,4 @@ -require "system_test_helper" +require "application_system_test_case" class <%= class_name.pluralize %>Test < ApplicationSystemTestCase # test "visiting the index" do diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb deleted file mode 100644 index d19212abd5..0000000000 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end -- cgit v1.2.3 From bd163bdadf044e75a4812489d9f53a9feeb3cec7 Mon Sep 17 00:00:00 2001 From: Roberto Miranda Date: Fri, 17 Feb 2017 15:14:35 -0500 Subject: Use Puma 3.7.x ref this commit seems that has not been merged into 3.7 https://github.com/puma/puma/commit/42bec4600c51ab8a1c1ee5a0e1b738a4ffd82bf2 --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ea88afe9f4..61c371d2bc 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -190,7 +190,7 @@ module Rails def webserver_gemfile_entry # :doc: return [] if options[:skip_puma] comment = "Use Puma as the app server" - GemfileEntry.new("puma", "~> 3.0", comment) + GemfileEntry.new("puma", "~> 3.7", comment) end def include_all_railties? # :doc: -- cgit v1.2.3 From 8e52ce9c8ed01105b3ebab7b57761c171eeb340c Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 21 Feb 2017 10:58:11 +0900 Subject: Do not display template files on API doc [ci skip] --- railties/lib/rails/api/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb index d1f984be1d..0c0343114f 100644 --- a/railties/lib/rails/api/task.rb +++ b/railties/lib/rails/api/task.rb @@ -70,7 +70,7 @@ module Rails lib/**/*.rb ), exclude: %w( - lib/rails/generators/rails/**/templates/**/*.rb + lib/rails/generators/**/templates/**/*.rb lib/rails/test_unit/* lib/rails/api/generator.rb ) -- cgit v1.2.3 From c1b64429b1af45a4a526b3b5bb5a306a0d51e28a Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 21 Feb 2017 08:25:15 +0100 Subject: Fix run_via[]= backwards compatibility. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` Minitest.run_via[:rails] = true ``` 👆 would break because a simple alias won't catch the second true argument there. --- railties/lib/rails/test_unit/minitest_plugin.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index 7d3da6b529..e44fe78bbd 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -115,7 +115,9 @@ module Minitest alias set? runner # Backwardscompatibility with Rails 5.0 generated plugin test scripts. - alias []= runner= + def []=(runner, *) + @runner = runner + end def ruby? runner == :ruby -- cgit v1.2.3 From 1d8466c38804a555df58ebe214c9aa0e240ad856 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 21 Feb 2017 11:02:39 -0500 Subject: Only load SystemTestCase if Capybara is defined For applications that are upgrading or applications that are choosing to skip system testing Capbyara will not be available. SystemTestCase and friends shoud only be loaded if Capbyara is defined. Fixes #28094 --- railties/lib/rails/test_help.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 75171f2395..09931c108a 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -7,11 +7,14 @@ require "active_support/test_case" require "action_controller" require "action_controller/test_case" require "action_dispatch/testing/integration" -require "action_dispatch/system_test_case" require "rails/generators/test_case" require "active_support/testing/autorun" +if defined?(Capbyara) + require "action_dispatch/system_test_case" +end + if defined?(ActiveRecord::Base) ActiveRecord::Migration.maintain_test_schema! @@ -46,9 +49,11 @@ class ActionDispatch::IntegrationTest end end -class ActionDispatch::SystemTestCase - def before_setup # :nodoc: - @routes = Rails.application.routes - super +if defined? Capybara + class ActionDispatch::SystemTestCase + def before_setup # :nodoc: + @routes = Rails.application.routes + super + end end end -- cgit v1.2.3 From 8e9e94391902b854662ba5eb06cc006cc4e85212 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 21 Feb 2017 17:33:31 +0100 Subject: Revert back to the original of using package.json in the root of the project (#28093) --- railties/lib/rails/generators/rails/app/app_generator.rb | 4 ++-- railties/lib/rails/generators/rails/app/templates/bin/yarn | 2 +- .../generators/rails/app/templates/config/initializers/assets.rb.tt | 2 +- railties/lib/rails/generators/rails/app/templates/gitignore | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 18e48c8016..86326d98ed 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -166,7 +166,7 @@ module Rails empty_directory_with_keep_file "vendor" unless options[:skip_yarn] - template "package.json", "vendor/package.json" + template "package.json" end end end @@ -280,7 +280,7 @@ module Rails build(:vendor) if options[:skip_yarn] - remove_file "vendor/package.json" + remove_file "package.json" end end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/yarn b/railties/lib/rails/generators/rails/app/templates/bin/yarn index 872438cecb..4ae896a8d3 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/yarn +++ b/railties/lib/rails/generators/rails/app/templates/bin/yarn @@ -1,4 +1,4 @@ -VENDOR_PATH = File.expand_path('../vendor', __dir__) +VENDOR_PATH = File.expand_path('..', __dir__) Dir.chdir(VENDOR_PATH) do begin exec "yarnpkg #{ARGV.join(" ")}" diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index f5d03fb117..51196ae743 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -7,7 +7,7 @@ Rails.application.config.assets.version = '1.0' # Rails.application.config.assets.paths << Emoji.images_path <%- unless options[:skip_yarn] -%> # Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('vendor/node_modules') +Rails.application.config.assets.paths << Rails.root.join('node_modules') <%- end -%> # Precompile additional assets. diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 1768b700d9..7221c26729 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -22,8 +22,8 @@ <% end -%> <% unless options[:skip_yarn] -%> -/vendor/node_modules -/vendor/yarn-error.log +/node_modules +/yarn-error.log <% end -%> .byebug_history -- cgit v1.2.3 From ea9566f6cd1b4d3f0d8a5f03283b49423b89044d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 21 Feb 2017 11:46:03 -0500 Subject: Use released arel --- railties/lib/rails/generators/app_base.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index f365ad05c7..49e9044e09 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -246,7 +246,6 @@ module Rails def rails_gemfile_entry dev_edge_common = [ - GemfileEntry.github("arel", "rails/arel") ] if options.dev? [ -- cgit v1.2.3 From 6debcaaeab094559d7a3d2e882e11a7d05c552f3 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 22 Feb 2017 16:22:58 +0900 Subject: Add wrapper for plugin's test runner Currently, private API is directly used in `bin/test`. It is necessary to change `bin/test` when changing private API. To avoid this, provide a wrapper file and modify `bin/test` to just require that file. --- railties/lib/rails/generators/rails/plugin/templates/bin/test.tt | 8 +------- railties/lib/rails/plugin/test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 railties/lib/rails/plugin/test.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt index 35a9bf8c8b..75be76c25f 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt @@ -1,10 +1,4 @@ $: << File.expand_path(File.expand_path('../../test', __FILE__)) require 'bundler/setup' -require 'rails/test_unit/minitest_plugin' - -Rails::TestUnitReporter.executable = 'bin/test' - -Minitest.run_via = :rails - -require "active_support/testing/autorun" +require 'rails/plugin/test' diff --git a/railties/lib/rails/plugin/test.rb b/railties/lib/rails/plugin/test.rb new file mode 100644 index 0000000000..ff043b488e --- /dev/null +++ b/railties/lib/rails/plugin/test.rb @@ -0,0 +1,7 @@ +require "rails/test_unit/minitest_plugin" + +Rails::TestUnitReporter.executable = "bin/test" + +Minitest.run_via = :rails + +require "active_support/testing/autorun" -- cgit v1.2.3 From 11660945696155c86a05260795e1a0afce0d291d Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 23 Feb 2017 15:01:02 +0100 Subject: Add encrypted secrets (#28038) --- railties/lib/rails/application.rb | 14 +-- railties/lib/rails/application/bootstrap.rb | 6 ++ railties/lib/rails/application/configuration.rb | 6 +- railties/lib/rails/command.rb | 27 +++-- railties/lib/rails/command/base.rb | 10 +- railties/lib/rails/commands/secrets/USAGE | 52 ++++++++++ .../lib/rails/commands/secrets/secrets_command.rb | 50 ++++++++++ railties/lib/rails/generators.rb | 1 + .../templates/config/environments/production.rb.tt | 5 + .../rails/app/templates/config/secrets.yml | 6 +- .../encrypted_secrets_generator.rb | 66 ++++++++++++ .../templates/config/secrets.yml.enc | 3 + railties/lib/rails/secrets.rb | 111 +++++++++++++++++++++ 13 files changed, 330 insertions(+), 27 deletions(-) create mode 100644 railties/lib/rails/commands/secrets/USAGE create mode 100644 railties/lib/rails/commands/secrets/secrets_command.rb create mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb create mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc create mode 100644 railties/lib/rails/secrets.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1a6aed7ce4..89f7b5991f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -4,6 +4,7 @@ require "active_support/core_ext/object/blank" require "active_support/key_generator" require "active_support/message_verifier" require "rails/engine" +require "rails/secrets" module Rails # An Engine with the responsibility of coordinating the whole boot process. @@ -385,18 +386,7 @@ module Rails def secrets @secrets ||= begin secrets = ActiveSupport::OrderedOptions.new - yaml = config.paths["config/secrets"].first - - if File.exist?(yaml) - require "erb" - - all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {} - shared_secrets = all_secrets["shared"] - env_secrets = all_secrets[Rails.env] - - secrets.merge!(shared_secrets.deep_symbolize_keys) if shared_secrets - secrets.merge!(env_secrets.deep_symbolize_keys) if env_secrets - end + secrets.merge! Rails::Secrets.parse(config.paths["config/secrets"].existent, env: Rails.env) # Fallback to config.secret_key_base if secrets.secret_key_base isn't set secrets.secret_key_base ||= config.secret_key_base diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 6102af3fff..4223c38146 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -2,6 +2,7 @@ require "fileutils" require "active_support/notifications" require "active_support/dependencies" require "active_support/descendants_tracker" +require "rails/secrets" module Rails class Application @@ -77,6 +78,11 @@ INFO initializer :bootstrap_hook, group: :all do |app| ActiveSupport.run_load_hooks(:before_initialize, app) end + + initializer :set_secrets_root, group: :all do + Rails::Secrets.root = root + Rails::Secrets.read_encrypted_secrets = config.read_encrypted_secrets + end end end end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index b0d33f87a3..b0592151b7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -13,7 +13,8 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, - :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading + :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading, + :read_encrypted_secrets attr_writer :log_level attr_reader :encoding, :api_only @@ -51,6 +52,7 @@ module Rails @debug_exception_response_format = nil @x = Custom.new @enable_dependency_loading = false + @read_encrypted_secrets = false end def encoding=(value) @@ -80,7 +82,7 @@ module Rails @paths ||= begin paths = super paths.add "config/database", with: "config/database.yml" - paths.add "config/secrets", with: "config/secrets.yml" + paths.add "config/secrets", with: "config", glob: "secrets.yml{,.enc}" paths.add "config/environment", with: "config/environment.rb" paths.add "lib/templates" paths.add "log", with: "log/#{Rails.env}.log" diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 13f3b90b6d..73f9684ca4 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -27,15 +27,22 @@ module Rails end # Receives a namespace, arguments and the behavior to invoke the command. - def invoke(namespace, args = [], **config) - namespace = namespace.to_s - namespace = "help" if namespace.blank? || HELP_MAPPINGS.include?(namespace) - namespace = "version" if %w( -v --version ).include? namespace + def invoke(full_namespace, args = [], **config) + namespace = full_namespace = full_namespace.to_s - if command = find_by_namespace(namespace) - command.perform(namespace, args, config) + if char = namespace =~ /:(\w+)$/ + command_name, namespace = $1, namespace.slice(0, char) else - find_by_namespace("rake").perform(namespace, args, config) + command_name = namespace + end + + command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) + namespace = "version" if %w( -v --version ).include?(command_name) + + if command = find_by_namespace(namespace, command_name) + command.perform(command_name, args, config) + else + find_by_namespace("rake").perform(full_namespace, args, config) end end @@ -52,8 +59,10 @@ module Rails # # Notice that "rails:commands:webrat" could be loaded as well, what # Rails looks for is the first and last parts of the namespace. - def find_by_namespace(name) # :nodoc: - lookups = [ name, "rails:#{name}" ] + def find_by_namespace(namespace, command_name = nil) # :nodoc: + lookups = [ namespace ] + lookups << "#{namespace}:#{command_name}" if command_name + lookups.concat lookups.map { |lookup| "rails:#{lookup}" } lookup(lookups) diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb index 1435792536..db20c71861 100644 --- a/railties/lib/rails/command/base.rb +++ b/railties/lib/rails/command/base.rb @@ -56,7 +56,9 @@ module Rails end def perform(command, args, config) # :nodoc: - command = nil if Rails::Command::HELP_MAPPINGS.include?(args.first) + if Rails::Command::HELP_MAPPINGS.include?(args.first) + command, args = "help", [] + end dispatch(command, args.dup, nil, config) end @@ -111,7 +113,7 @@ module Rails # For a `Rails::Command::TestCommand` placed in `rails/command/test_command.rb` # would return `rails/test`. def default_command_root - path = File.expand_path(File.join("../commands", command_name), __dir__) + path = File.expand_path(File.join("../commands", command_root_namespace), __dir__) path if File.exist?(path) end @@ -129,6 +131,10 @@ module Rails super end end + + def command_root_namespace + (namespace.split(":") - %w( rails )).first + end end def help diff --git a/railties/lib/rails/commands/secrets/USAGE b/railties/lib/rails/commands/secrets/USAGE new file mode 100644 index 0000000000..4b7deb4e2a --- /dev/null +++ b/railties/lib/rails/commands/secrets/USAGE @@ -0,0 +1,52 @@ +=== Storing Encrypted Secrets in Source Control + +The Rails `secrets` commands helps encrypting secrets to slim a production +environment's `ENV` hash. It's also useful for atomic deploys: no need to +coordinate key changes to get everything working as the keys are shipped +with the code. + +=== Setup + +Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key` +and `config/secrets.yml.enc` files. + +The latter contains all the keys to be encrypted while the former holds the +encryption key. + +Don't lose the key! Put it in a password manager your team can access. +Should you lose it no one, including you, will be able to access any encrypted +secrets. +Don't commit the key! Add `config/secrets.yml.key` to your source control's +ignore file. If you use Git, Rails handles this for you. + +Rails also looks for the key in `ENV["RAILS_MASTER_KEY"]` if that's easier to +manage. + +You could prepend that to your server's start command like this: + + RAILS_MASTER_KEY="im-the-master-now-hahaha" server.start + + +The `config/secrets.yml.enc` has much the same format as `config/secrets.yml`: + + production: + secret_key_base: so-secret-very-hidden-wow + payment_processing_gateway_key: much-safe-very-gaedwey-wow + +But that's where the similarities between `secrets.yml` and `secrets.yml.enc` +end, e.g. no keys from `secrets.yml` will be moved to `secrets.yml.enc` and +be encrypted. + +A `shared:` top level key is also supported such that any keys there is merged +into the other environments. + +=== Editing Secrets + +After `bin/rails secrets:setup`, run `bin/rails secrets:edit`. + +That command opens a temporary file in `$EDITOR` with the decrypted contents of +`config/secrets.yml.enc` to edit the encrypted secrets. + +When the temporary file is next saved the contents are encrypted and written to +`config/secrets.yml.enc` while the file itself is destroyed to prevent secrets +from leaking. diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb new file mode 100644 index 0000000000..05e0c228e8 --- /dev/null +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -0,0 +1,50 @@ +require "active_support" +require "rails/secrets" + +module Rails + module Command + class SecretsCommand < Rails::Command::Base # :nodoc: + def help + say "Usage:\n #{self.class.banner}" + say "" + say self.class.desc + end + + def setup + require "rails/generators" + require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" + + Rails::Generators::EncryptedSecretsGenerator.start + end + + def edit + require_application_and_environment! + + Rails::Secrets.read_for_editing do |tmp_path| + watch tmp_path do + puts "Waiting for secrets file to be saved. Abort with Ctrl-C." + system("\$EDITOR #{tmp_path}") + end + end + + puts "New secrets encrypted and saved." + rescue Interrupt + puts "Aborted changing encrypted secrets: nothing saved." + rescue Rails::Secrets::MissingKeyError => error + say error.message + end + + private + def watch(tmp_path) + mtime, start_time = File.mtime(tmp_path), Time.now + + yield + + editor_exits_after_open = $?.success? && (Time.now - start_time) < 1 + if editor_exits_after_open + sleep 0.250 until File.mtime(tmp_path) != mtime + end + end + end + end +end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 85f66cc416..3f1bf6a5bb 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -214,6 +214,7 @@ module Rails rails.map! { |n| n.sub(/^rails:/, "") } rails.delete("app") rails.delete("plugin") + rails.delete("encrypted_secrets") hidden_namespaces.each { |n| groups.delete(n.to_s) } diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 4a39e43e57..9c4a77fd1d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -14,6 +14,11 @@ Rails.application.configure do config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true + # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? diff --git a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml index 8e995a5df1..816efcc5b1 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml @@ -23,8 +23,10 @@ development: test: secret_key_base: <%= app_secret %> -# Do not keep production secrets in the repository, -# instead read values from the environment. +# Do not keep production secrets in the unencrypted secrets file. +# Instead, either read values from the environment. +# Or, use `bin/rails secrets:setup` to configure encrypted secrets +# and move the `production:` environment over there. production: secret_key_base: <%%= ENV["SECRET_KEY_BASE"] %> diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb new file mode 100644 index 0000000000..8b29213610 --- /dev/null +++ b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb @@ -0,0 +1,66 @@ +require "rails/generators/base" +require "rails/secrets" + +module Rails + module Generators + class EncryptedSecretsGenerator < Base + def add_secrets_key_file + unless File.exist?("config/secrets.yml.key") || File.exist?("config/secrets.yml.enc") + key = Rails::Secrets.generate_key + + say "Adding config/secrets.yml.key to store the encryption key: #{key}" + say "" + say "Save this in a password manager your team can access." + say "" + say "If you lose the key, no one, including you, can access any encrypted secrets." + + say "" + create_file "config/secrets.yml.key", key + say "" + end + end + + def ignore_key_file + if File.exist?(".gitignore") + unless File.read(".gitignore").include?(key_ignore) + say "Ignoring config/secrets.yml.key so it won't end up in Git history:" + say "" + append_to_file ".gitignore", key_ignore + say "" + end + else + say "IMPORTANT: Don't commit config/secrets.yml.key. Add this to your ignore file:" + say key_ignore, :on_green + say "" + end + end + + def add_encrypted_secrets_file + unless File.exist?("config/secrets.yml.enc") + say "Adding config/secrets.yml.enc to store secrets that needs to be encrypted." + say "" + + template "config/secrets.yml.enc" do |prefill| + say "" + say "For now the file contains this but it's been encrypted with the generated key:" + say "" + say prefill, :on_green + say "" + + Secrets.encrypt(prefill) + end + + say "You can edit encrypted secrets with `bin/rails secrets:edit`." + + say "Add this to your config/environments/production.rb:" + say "config.read_encrypted_secrets = true" + end + end + + private + def key_ignore + [ "", "# Ignore encrypted secrets key file.", "config/secrets.yml.key", "" ].join("\n") + end + end + end +end diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc new file mode 100644 index 0000000000..70426a66a5 --- /dev/null +++ b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc @@ -0,0 +1,3 @@ +# See `secrets.yml` for tips on generating suitable keys. +# production: +# external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289… diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb new file mode 100644 index 0000000000..a083914109 --- /dev/null +++ b/railties/lib/rails/secrets.rb @@ -0,0 +1,111 @@ +require "yaml" + +module Rails + # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘 + class Secrets # :nodoc: + class MissingKeyError < RuntimeError + def initialize + super(<<-end_of_message.squish) + Missing encryption key to decrypt secrets with. + Ask your team for your master key and put it in ENV["RAILS_MASTER_KEY"] + end_of_message + end + end + + @read_encrypted_secrets = false + @root = File # Wonky, but ensures `join` uses the current directory. + + class << self + attr_writer :root + attr_accessor :read_encrypted_secrets + + def parse(paths, env:) + paths.each_with_object(Hash.new) do |path, all_secrets| + require "erb" + + secrets = YAML.load(ERB.new(preprocess(path)).result) || {} + all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"] + all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env] + end + end + + def generate_key + cipher = new_cipher + SecureRandom.hex(cipher.key_len)[0, cipher.key_len] + end + + def key + ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key + end + + def encrypt(text) + cipher(:encrypt, text) + end + + def decrypt(data) + cipher(:decrypt, data) + end + + def read + decrypt(IO.binread(path)) + end + + def write(contents) + IO.binwrite("#{path}.tmp", encrypt(contents)) + FileUtils.mv("#{path}.tmp", path) + end + + def read_for_editing + tmp_path = File.join(Dir.tmpdir, File.basename(path)) + IO.binwrite(tmp_path, read) + + yield tmp_path + + write(IO.binread(tmp_path)) + ensure + FileUtils.rm(tmp_path) if File.exist?(tmp_path) + end + + private + def handle_missing_key + raise MissingKeyError + end + + def read_key_file + if File.exist?(key_path) + IO.binread(key_path).strip + end + end + + def key_path + @root.join("config", "secrets.yml.key") + end + + def path + @root.join("config", "secrets.yml.enc").to_s + end + + def preprocess(path) + if path.end_with?(".enc") + if @read_encrypted_secrets + decrypt(IO.binread(path)) + else + "" + end + else + IO.read(path) + end + end + + def new_cipher + OpenSSL::Cipher.new("aes-256-cbc") + end + + def cipher(mode, data) + cipher = new_cipher.public_send(mode) + cipher.key = key + cipher.update(data) << cipher.final + end + end + end +end -- cgit v1.2.3 From 039380e3eeb24ed17f1824183b94638f0cfff747 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 23 Feb 2017 15:55:15 +0100 Subject: Revert "Add encrypted secrets" (#28127) --- railties/lib/rails/application.rb | 14 ++- railties/lib/rails/application/bootstrap.rb | 6 -- railties/lib/rails/application/configuration.rb | 6 +- railties/lib/rails/command.rb | 27 ++--- railties/lib/rails/command/base.rb | 10 +- railties/lib/rails/commands/secrets/USAGE | 52 ---------- .../lib/rails/commands/secrets/secrets_command.rb | 50 ---------- railties/lib/rails/generators.rb | 1 - .../templates/config/environments/production.rb.tt | 5 - .../rails/app/templates/config/secrets.yml | 6 +- .../encrypted_secrets_generator.rb | 66 ------------ .../templates/config/secrets.yml.enc | 3 - railties/lib/rails/secrets.rb | 111 --------------------- 13 files changed, 27 insertions(+), 330 deletions(-) delete mode 100644 railties/lib/rails/commands/secrets/USAGE delete mode 100644 railties/lib/rails/commands/secrets/secrets_command.rb delete mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb delete mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc delete mode 100644 railties/lib/rails/secrets.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 89f7b5991f..1a6aed7ce4 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -4,7 +4,6 @@ require "active_support/core_ext/object/blank" require "active_support/key_generator" require "active_support/message_verifier" require "rails/engine" -require "rails/secrets" module Rails # An Engine with the responsibility of coordinating the whole boot process. @@ -386,7 +385,18 @@ module Rails def secrets @secrets ||= begin secrets = ActiveSupport::OrderedOptions.new - secrets.merge! Rails::Secrets.parse(config.paths["config/secrets"].existent, env: Rails.env) + yaml = config.paths["config/secrets"].first + + if File.exist?(yaml) + require "erb" + + all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {} + shared_secrets = all_secrets["shared"] + env_secrets = all_secrets[Rails.env] + + secrets.merge!(shared_secrets.deep_symbolize_keys) if shared_secrets + secrets.merge!(env_secrets.deep_symbolize_keys) if env_secrets + end # Fallback to config.secret_key_base if secrets.secret_key_base isn't set secrets.secret_key_base ||= config.secret_key_base diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 4223c38146..6102af3fff 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -2,7 +2,6 @@ require "fileutils" require "active_support/notifications" require "active_support/dependencies" require "active_support/descendants_tracker" -require "rails/secrets" module Rails class Application @@ -78,11 +77,6 @@ INFO initializer :bootstrap_hook, group: :all do |app| ActiveSupport.run_load_hooks(:before_initialize, app) end - - initializer :set_secrets_root, group: :all do - Rails::Secrets.root = root - Rails::Secrets.read_encrypted_secrets = config.read_encrypted_secrets - end end end end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index b0592151b7..b0d33f87a3 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -13,8 +13,7 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, - :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading, - :read_encrypted_secrets + :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading attr_writer :log_level attr_reader :encoding, :api_only @@ -52,7 +51,6 @@ module Rails @debug_exception_response_format = nil @x = Custom.new @enable_dependency_loading = false - @read_encrypted_secrets = false end def encoding=(value) @@ -82,7 +80,7 @@ module Rails @paths ||= begin paths = super paths.add "config/database", with: "config/database.yml" - paths.add "config/secrets", with: "config", glob: "secrets.yml{,.enc}" + paths.add "config/secrets", with: "config/secrets.yml" paths.add "config/environment", with: "config/environment.rb" paths.add "lib/templates" paths.add "log", with: "log/#{Rails.env}.log" diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 73f9684ca4..13f3b90b6d 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -27,22 +27,15 @@ module Rails end # Receives a namespace, arguments and the behavior to invoke the command. - def invoke(full_namespace, args = [], **config) - namespace = full_namespace = full_namespace.to_s + def invoke(namespace, args = [], **config) + namespace = namespace.to_s + namespace = "help" if namespace.blank? || HELP_MAPPINGS.include?(namespace) + namespace = "version" if %w( -v --version ).include? namespace - if char = namespace =~ /:(\w+)$/ - command_name, namespace = $1, namespace.slice(0, char) + if command = find_by_namespace(namespace) + command.perform(namespace, args, config) else - command_name = namespace - end - - command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) - namespace = "version" if %w( -v --version ).include?(command_name) - - if command = find_by_namespace(namespace, command_name) - command.perform(command_name, args, config) - else - find_by_namespace("rake").perform(full_namespace, args, config) + find_by_namespace("rake").perform(namespace, args, config) end end @@ -59,10 +52,8 @@ module Rails # # Notice that "rails:commands:webrat" could be loaded as well, what # Rails looks for is the first and last parts of the namespace. - def find_by_namespace(namespace, command_name = nil) # :nodoc: - lookups = [ namespace ] - lookups << "#{namespace}:#{command_name}" if command_name - lookups.concat lookups.map { |lookup| "rails:#{lookup}" } + def find_by_namespace(name) # :nodoc: + lookups = [ name, "rails:#{name}" ] lookup(lookups) diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb index db20c71861..1435792536 100644 --- a/railties/lib/rails/command/base.rb +++ b/railties/lib/rails/command/base.rb @@ -56,9 +56,7 @@ module Rails end def perform(command, args, config) # :nodoc: - if Rails::Command::HELP_MAPPINGS.include?(args.first) - command, args = "help", [] - end + command = nil if Rails::Command::HELP_MAPPINGS.include?(args.first) dispatch(command, args.dup, nil, config) end @@ -113,7 +111,7 @@ module Rails # For a `Rails::Command::TestCommand` placed in `rails/command/test_command.rb` # would return `rails/test`. def default_command_root - path = File.expand_path(File.join("../commands", command_root_namespace), __dir__) + path = File.expand_path(File.join("../commands", command_name), __dir__) path if File.exist?(path) end @@ -131,10 +129,6 @@ module Rails super end end - - def command_root_namespace - (namespace.split(":") - %w( rails )).first - end end def help diff --git a/railties/lib/rails/commands/secrets/USAGE b/railties/lib/rails/commands/secrets/USAGE deleted file mode 100644 index 4b7deb4e2a..0000000000 --- a/railties/lib/rails/commands/secrets/USAGE +++ /dev/null @@ -1,52 +0,0 @@ -=== Storing Encrypted Secrets in Source Control - -The Rails `secrets` commands helps encrypting secrets to slim a production -environment's `ENV` hash. It's also useful for atomic deploys: no need to -coordinate key changes to get everything working as the keys are shipped -with the code. - -=== Setup - -Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key` -and `config/secrets.yml.enc` files. - -The latter contains all the keys to be encrypted while the former holds the -encryption key. - -Don't lose the key! Put it in a password manager your team can access. -Should you lose it no one, including you, will be able to access any encrypted -secrets. -Don't commit the key! Add `config/secrets.yml.key` to your source control's -ignore file. If you use Git, Rails handles this for you. - -Rails also looks for the key in `ENV["RAILS_MASTER_KEY"]` if that's easier to -manage. - -You could prepend that to your server's start command like this: - - RAILS_MASTER_KEY="im-the-master-now-hahaha" server.start - - -The `config/secrets.yml.enc` has much the same format as `config/secrets.yml`: - - production: - secret_key_base: so-secret-very-hidden-wow - payment_processing_gateway_key: much-safe-very-gaedwey-wow - -But that's where the similarities between `secrets.yml` and `secrets.yml.enc` -end, e.g. no keys from `secrets.yml` will be moved to `secrets.yml.enc` and -be encrypted. - -A `shared:` top level key is also supported such that any keys there is merged -into the other environments. - -=== Editing Secrets - -After `bin/rails secrets:setup`, run `bin/rails secrets:edit`. - -That command opens a temporary file in `$EDITOR` with the decrypted contents of -`config/secrets.yml.enc` to edit the encrypted secrets. - -When the temporary file is next saved the contents are encrypted and written to -`config/secrets.yml.enc` while the file itself is destroyed to prevent secrets -from leaking. diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb deleted file mode 100644 index 05e0c228e8..0000000000 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ /dev/null @@ -1,50 +0,0 @@ -require "active_support" -require "rails/secrets" - -module Rails - module Command - class SecretsCommand < Rails::Command::Base # :nodoc: - def help - say "Usage:\n #{self.class.banner}" - say "" - say self.class.desc - end - - def setup - require "rails/generators" - require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" - - Rails::Generators::EncryptedSecretsGenerator.start - end - - def edit - require_application_and_environment! - - Rails::Secrets.read_for_editing do |tmp_path| - watch tmp_path do - puts "Waiting for secrets file to be saved. Abort with Ctrl-C." - system("\$EDITOR #{tmp_path}") - end - end - - puts "New secrets encrypted and saved." - rescue Interrupt - puts "Aborted changing encrypted secrets: nothing saved." - rescue Rails::Secrets::MissingKeyError => error - say error.message - end - - private - def watch(tmp_path) - mtime, start_time = File.mtime(tmp_path), Time.now - - yield - - editor_exits_after_open = $?.success? && (Time.now - start_time) < 1 - if editor_exits_after_open - sleep 0.250 until File.mtime(tmp_path) != mtime - end - end - end - end -end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 3f1bf6a5bb..85f66cc416 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -214,7 +214,6 @@ module Rails rails.map! { |n| n.sub(/^rails:/, "") } rails.delete("app") rails.delete("plugin") - rails.delete("encrypted_secrets") hidden_namespaces.each { |n| groups.delete(n.to_s) } diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 9c4a77fd1d..4a39e43e57 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -14,11 +14,6 @@ Rails.application.configure do config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Attempt to read encrypted secrets from `config/secrets.yml.enc`. - # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or - # `config/secrets.yml.key`. - config.read_encrypted_secrets = true - # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? diff --git a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml index 816efcc5b1..8e995a5df1 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml @@ -23,10 +23,8 @@ development: test: secret_key_base: <%= app_secret %> -# Do not keep production secrets in the unencrypted secrets file. -# Instead, either read values from the environment. -# Or, use `bin/rails secrets:setup` to configure encrypted secrets -# and move the `production:` environment over there. +# Do not keep production secrets in the repository, +# instead read values from the environment. production: secret_key_base: <%%= ENV["SECRET_KEY_BASE"] %> diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb deleted file mode 100644 index 8b29213610..0000000000 --- a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "rails/generators/base" -require "rails/secrets" - -module Rails - module Generators - class EncryptedSecretsGenerator < Base - def add_secrets_key_file - unless File.exist?("config/secrets.yml.key") || File.exist?("config/secrets.yml.enc") - key = Rails::Secrets.generate_key - - say "Adding config/secrets.yml.key to store the encryption key: #{key}" - say "" - say "Save this in a password manager your team can access." - say "" - say "If you lose the key, no one, including you, can access any encrypted secrets." - - say "" - create_file "config/secrets.yml.key", key - say "" - end - end - - def ignore_key_file - if File.exist?(".gitignore") - unless File.read(".gitignore").include?(key_ignore) - say "Ignoring config/secrets.yml.key so it won't end up in Git history:" - say "" - append_to_file ".gitignore", key_ignore - say "" - end - else - say "IMPORTANT: Don't commit config/secrets.yml.key. Add this to your ignore file:" - say key_ignore, :on_green - say "" - end - end - - def add_encrypted_secrets_file - unless File.exist?("config/secrets.yml.enc") - say "Adding config/secrets.yml.enc to store secrets that needs to be encrypted." - say "" - - template "config/secrets.yml.enc" do |prefill| - say "" - say "For now the file contains this but it's been encrypted with the generated key:" - say "" - say prefill, :on_green - say "" - - Secrets.encrypt(prefill) - end - - say "You can edit encrypted secrets with `bin/rails secrets:edit`." - - say "Add this to your config/environments/production.rb:" - say "config.read_encrypted_secrets = true" - end - end - - private - def key_ignore - [ "", "# Ignore encrypted secrets key file.", "config/secrets.yml.key", "" ].join("\n") - end - end - end -end diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc deleted file mode 100644 index 70426a66a5..0000000000 --- a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +++ /dev/null @@ -1,3 +0,0 @@ -# See `secrets.yml` for tips on generating suitable keys. -# production: -# external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289… diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb deleted file mode 100644 index a083914109..0000000000 --- a/railties/lib/rails/secrets.rb +++ /dev/null @@ -1,111 +0,0 @@ -require "yaml" - -module Rails - # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘 - class Secrets # :nodoc: - class MissingKeyError < RuntimeError - def initialize - super(<<-end_of_message.squish) - Missing encryption key to decrypt secrets with. - Ask your team for your master key and put it in ENV["RAILS_MASTER_KEY"] - end_of_message - end - end - - @read_encrypted_secrets = false - @root = File # Wonky, but ensures `join` uses the current directory. - - class << self - attr_writer :root - attr_accessor :read_encrypted_secrets - - def parse(paths, env:) - paths.each_with_object(Hash.new) do |path, all_secrets| - require "erb" - - secrets = YAML.load(ERB.new(preprocess(path)).result) || {} - all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"] - all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env] - end - end - - def generate_key - cipher = new_cipher - SecureRandom.hex(cipher.key_len)[0, cipher.key_len] - end - - def key - ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key - end - - def encrypt(text) - cipher(:encrypt, text) - end - - def decrypt(data) - cipher(:decrypt, data) - end - - def read - decrypt(IO.binread(path)) - end - - def write(contents) - IO.binwrite("#{path}.tmp", encrypt(contents)) - FileUtils.mv("#{path}.tmp", path) - end - - def read_for_editing - tmp_path = File.join(Dir.tmpdir, File.basename(path)) - IO.binwrite(tmp_path, read) - - yield tmp_path - - write(IO.binread(tmp_path)) - ensure - FileUtils.rm(tmp_path) if File.exist?(tmp_path) - end - - private - def handle_missing_key - raise MissingKeyError - end - - def read_key_file - if File.exist?(key_path) - IO.binread(key_path).strip - end - end - - def key_path - @root.join("config", "secrets.yml.key") - end - - def path - @root.join("config", "secrets.yml.enc").to_s - end - - def preprocess(path) - if path.end_with?(".enc") - if @read_encrypted_secrets - decrypt(IO.binread(path)) - else - "" - end - else - IO.read(path) - end - end - - def new_cipher - OpenSSL::Cipher.new("aes-256-cbc") - end - - def cipher(mode, data) - cipher = new_cipher.public_send(mode) - cipher.key = key - cipher.update(data) << cipher.final - end - end - end -end -- cgit v1.2.3 From fbee4e3ce37674eb928298490a35d3dfd1921e67 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 23 Feb 2017 18:15:28 +0100 Subject: Revert "Revert "Add encrypted secrets"" --- railties/lib/rails/application.rb | 14 +-- railties/lib/rails/application/bootstrap.rb | 6 ++ railties/lib/rails/application/configuration.rb | 6 +- railties/lib/rails/command.rb | 27 +++-- railties/lib/rails/command/base.rb | 10 +- railties/lib/rails/commands/secrets/USAGE | 52 ++++++++++ .../lib/rails/commands/secrets/secrets_command.rb | 50 ++++++++++ railties/lib/rails/generators.rb | 1 + .../templates/config/environments/production.rb.tt | 5 + .../rails/app/templates/config/secrets.yml | 6 +- .../encrypted_secrets_generator.rb | 66 ++++++++++++ .../templates/config/secrets.yml.enc | 3 + railties/lib/rails/secrets.rb | 111 +++++++++++++++++++++ 13 files changed, 330 insertions(+), 27 deletions(-) create mode 100644 railties/lib/rails/commands/secrets/USAGE create mode 100644 railties/lib/rails/commands/secrets/secrets_command.rb create mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb create mode 100644 railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc create mode 100644 railties/lib/rails/secrets.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1a6aed7ce4..89f7b5991f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -4,6 +4,7 @@ require "active_support/core_ext/object/blank" require "active_support/key_generator" require "active_support/message_verifier" require "rails/engine" +require "rails/secrets" module Rails # An Engine with the responsibility of coordinating the whole boot process. @@ -385,18 +386,7 @@ module Rails def secrets @secrets ||= begin secrets = ActiveSupport::OrderedOptions.new - yaml = config.paths["config/secrets"].first - - if File.exist?(yaml) - require "erb" - - all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {} - shared_secrets = all_secrets["shared"] - env_secrets = all_secrets[Rails.env] - - secrets.merge!(shared_secrets.deep_symbolize_keys) if shared_secrets - secrets.merge!(env_secrets.deep_symbolize_keys) if env_secrets - end + secrets.merge! Rails::Secrets.parse(config.paths["config/secrets"].existent, env: Rails.env) # Fallback to config.secret_key_base if secrets.secret_key_base isn't set secrets.secret_key_base ||= config.secret_key_base diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 6102af3fff..4223c38146 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -2,6 +2,7 @@ require "fileutils" require "active_support/notifications" require "active_support/dependencies" require "active_support/descendants_tracker" +require "rails/secrets" module Rails class Application @@ -77,6 +78,11 @@ INFO initializer :bootstrap_hook, group: :all do |app| ActiveSupport.run_load_hooks(:before_initialize, app) end + + initializer :set_secrets_root, group: :all do + Rails::Secrets.root = root + Rails::Secrets.read_encrypted_secrets = config.read_encrypted_secrets + end end end end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index b0d33f87a3..b0592151b7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -13,7 +13,8 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, - :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading + :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading, + :read_encrypted_secrets attr_writer :log_level attr_reader :encoding, :api_only @@ -51,6 +52,7 @@ module Rails @debug_exception_response_format = nil @x = Custom.new @enable_dependency_loading = false + @read_encrypted_secrets = false end def encoding=(value) @@ -80,7 +82,7 @@ module Rails @paths ||= begin paths = super paths.add "config/database", with: "config/database.yml" - paths.add "config/secrets", with: "config/secrets.yml" + paths.add "config/secrets", with: "config", glob: "secrets.yml{,.enc}" paths.add "config/environment", with: "config/environment.rb" paths.add "lib/templates" paths.add "log", with: "log/#{Rails.env}.log" diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 13f3b90b6d..73f9684ca4 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -27,15 +27,22 @@ module Rails end # Receives a namespace, arguments and the behavior to invoke the command. - def invoke(namespace, args = [], **config) - namespace = namespace.to_s - namespace = "help" if namespace.blank? || HELP_MAPPINGS.include?(namespace) - namespace = "version" if %w( -v --version ).include? namespace + def invoke(full_namespace, args = [], **config) + namespace = full_namespace = full_namespace.to_s - if command = find_by_namespace(namespace) - command.perform(namespace, args, config) + if char = namespace =~ /:(\w+)$/ + command_name, namespace = $1, namespace.slice(0, char) else - find_by_namespace("rake").perform(namespace, args, config) + command_name = namespace + end + + command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) + namespace = "version" if %w( -v --version ).include?(command_name) + + if command = find_by_namespace(namespace, command_name) + command.perform(command_name, args, config) + else + find_by_namespace("rake").perform(full_namespace, args, config) end end @@ -52,8 +59,10 @@ module Rails # # Notice that "rails:commands:webrat" could be loaded as well, what # Rails looks for is the first and last parts of the namespace. - def find_by_namespace(name) # :nodoc: - lookups = [ name, "rails:#{name}" ] + def find_by_namespace(namespace, command_name = nil) # :nodoc: + lookups = [ namespace ] + lookups << "#{namespace}:#{command_name}" if command_name + lookups.concat lookups.map { |lookup| "rails:#{lookup}" } lookup(lookups) diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb index 1435792536..db20c71861 100644 --- a/railties/lib/rails/command/base.rb +++ b/railties/lib/rails/command/base.rb @@ -56,7 +56,9 @@ module Rails end def perform(command, args, config) # :nodoc: - command = nil if Rails::Command::HELP_MAPPINGS.include?(args.first) + if Rails::Command::HELP_MAPPINGS.include?(args.first) + command, args = "help", [] + end dispatch(command, args.dup, nil, config) end @@ -111,7 +113,7 @@ module Rails # For a `Rails::Command::TestCommand` placed in `rails/command/test_command.rb` # would return `rails/test`. def default_command_root - path = File.expand_path(File.join("../commands", command_name), __dir__) + path = File.expand_path(File.join("../commands", command_root_namespace), __dir__) path if File.exist?(path) end @@ -129,6 +131,10 @@ module Rails super end end + + def command_root_namespace + (namespace.split(":") - %w( rails )).first + end end def help diff --git a/railties/lib/rails/commands/secrets/USAGE b/railties/lib/rails/commands/secrets/USAGE new file mode 100644 index 0000000000..4b7deb4e2a --- /dev/null +++ b/railties/lib/rails/commands/secrets/USAGE @@ -0,0 +1,52 @@ +=== Storing Encrypted Secrets in Source Control + +The Rails `secrets` commands helps encrypting secrets to slim a production +environment's `ENV` hash. It's also useful for atomic deploys: no need to +coordinate key changes to get everything working as the keys are shipped +with the code. + +=== Setup + +Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key` +and `config/secrets.yml.enc` files. + +The latter contains all the keys to be encrypted while the former holds the +encryption key. + +Don't lose the key! Put it in a password manager your team can access. +Should you lose it no one, including you, will be able to access any encrypted +secrets. +Don't commit the key! Add `config/secrets.yml.key` to your source control's +ignore file. If you use Git, Rails handles this for you. + +Rails also looks for the key in `ENV["RAILS_MASTER_KEY"]` if that's easier to +manage. + +You could prepend that to your server's start command like this: + + RAILS_MASTER_KEY="im-the-master-now-hahaha" server.start + + +The `config/secrets.yml.enc` has much the same format as `config/secrets.yml`: + + production: + secret_key_base: so-secret-very-hidden-wow + payment_processing_gateway_key: much-safe-very-gaedwey-wow + +But that's where the similarities between `secrets.yml` and `secrets.yml.enc` +end, e.g. no keys from `secrets.yml` will be moved to `secrets.yml.enc` and +be encrypted. + +A `shared:` top level key is also supported such that any keys there is merged +into the other environments. + +=== Editing Secrets + +After `bin/rails secrets:setup`, run `bin/rails secrets:edit`. + +That command opens a temporary file in `$EDITOR` with the decrypted contents of +`config/secrets.yml.enc` to edit the encrypted secrets. + +When the temporary file is next saved the contents are encrypted and written to +`config/secrets.yml.enc` while the file itself is destroyed to prevent secrets +from leaking. diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb new file mode 100644 index 0000000000..05e0c228e8 --- /dev/null +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -0,0 +1,50 @@ +require "active_support" +require "rails/secrets" + +module Rails + module Command + class SecretsCommand < Rails::Command::Base # :nodoc: + def help + say "Usage:\n #{self.class.banner}" + say "" + say self.class.desc + end + + def setup + require "rails/generators" + require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" + + Rails::Generators::EncryptedSecretsGenerator.start + end + + def edit + require_application_and_environment! + + Rails::Secrets.read_for_editing do |tmp_path| + watch tmp_path do + puts "Waiting for secrets file to be saved. Abort with Ctrl-C." + system("\$EDITOR #{tmp_path}") + end + end + + puts "New secrets encrypted and saved." + rescue Interrupt + puts "Aborted changing encrypted secrets: nothing saved." + rescue Rails::Secrets::MissingKeyError => error + say error.message + end + + private + def watch(tmp_path) + mtime, start_time = File.mtime(tmp_path), Time.now + + yield + + editor_exits_after_open = $?.success? && (Time.now - start_time) < 1 + if editor_exits_after_open + sleep 0.250 until File.mtime(tmp_path) != mtime + end + end + end + end +end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 85f66cc416..3f1bf6a5bb 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -214,6 +214,7 @@ module Rails rails.map! { |n| n.sub(/^rails:/, "") } rails.delete("app") rails.delete("plugin") + rails.delete("encrypted_secrets") hidden_namespaces.each { |n| groups.delete(n.to_s) } diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 4a39e43e57..9c4a77fd1d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -14,6 +14,11 @@ Rails.application.configure do config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true + # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? diff --git a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml index 8e995a5df1..816efcc5b1 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml @@ -23,8 +23,10 @@ development: test: secret_key_base: <%= app_secret %> -# Do not keep production secrets in the repository, -# instead read values from the environment. +# Do not keep production secrets in the unencrypted secrets file. +# Instead, either read values from the environment. +# Or, use `bin/rails secrets:setup` to configure encrypted secrets +# and move the `production:` environment over there. production: secret_key_base: <%%= ENV["SECRET_KEY_BASE"] %> diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb new file mode 100644 index 0000000000..8b29213610 --- /dev/null +++ b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb @@ -0,0 +1,66 @@ +require "rails/generators/base" +require "rails/secrets" + +module Rails + module Generators + class EncryptedSecretsGenerator < Base + def add_secrets_key_file + unless File.exist?("config/secrets.yml.key") || File.exist?("config/secrets.yml.enc") + key = Rails::Secrets.generate_key + + say "Adding config/secrets.yml.key to store the encryption key: #{key}" + say "" + say "Save this in a password manager your team can access." + say "" + say "If you lose the key, no one, including you, can access any encrypted secrets." + + say "" + create_file "config/secrets.yml.key", key + say "" + end + end + + def ignore_key_file + if File.exist?(".gitignore") + unless File.read(".gitignore").include?(key_ignore) + say "Ignoring config/secrets.yml.key so it won't end up in Git history:" + say "" + append_to_file ".gitignore", key_ignore + say "" + end + else + say "IMPORTANT: Don't commit config/secrets.yml.key. Add this to your ignore file:" + say key_ignore, :on_green + say "" + end + end + + def add_encrypted_secrets_file + unless File.exist?("config/secrets.yml.enc") + say "Adding config/secrets.yml.enc to store secrets that needs to be encrypted." + say "" + + template "config/secrets.yml.enc" do |prefill| + say "" + say "For now the file contains this but it's been encrypted with the generated key:" + say "" + say prefill, :on_green + say "" + + Secrets.encrypt(prefill) + end + + say "You can edit encrypted secrets with `bin/rails secrets:edit`." + + say "Add this to your config/environments/production.rb:" + say "config.read_encrypted_secrets = true" + end + end + + private + def key_ignore + [ "", "# Ignore encrypted secrets key file.", "config/secrets.yml.key", "" ].join("\n") + end + end + end +end diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc new file mode 100644 index 0000000000..70426a66a5 --- /dev/null +++ b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc @@ -0,0 +1,3 @@ +# See `secrets.yml` for tips on generating suitable keys. +# production: +# external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289… diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb new file mode 100644 index 0000000000..a083914109 --- /dev/null +++ b/railties/lib/rails/secrets.rb @@ -0,0 +1,111 @@ +require "yaml" + +module Rails + # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘 + class Secrets # :nodoc: + class MissingKeyError < RuntimeError + def initialize + super(<<-end_of_message.squish) + Missing encryption key to decrypt secrets with. + Ask your team for your master key and put it in ENV["RAILS_MASTER_KEY"] + end_of_message + end + end + + @read_encrypted_secrets = false + @root = File # Wonky, but ensures `join` uses the current directory. + + class << self + attr_writer :root + attr_accessor :read_encrypted_secrets + + def parse(paths, env:) + paths.each_with_object(Hash.new) do |path, all_secrets| + require "erb" + + secrets = YAML.load(ERB.new(preprocess(path)).result) || {} + all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"] + all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env] + end + end + + def generate_key + cipher = new_cipher + SecureRandom.hex(cipher.key_len)[0, cipher.key_len] + end + + def key + ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key + end + + def encrypt(text) + cipher(:encrypt, text) + end + + def decrypt(data) + cipher(:decrypt, data) + end + + def read + decrypt(IO.binread(path)) + end + + def write(contents) + IO.binwrite("#{path}.tmp", encrypt(contents)) + FileUtils.mv("#{path}.tmp", path) + end + + def read_for_editing + tmp_path = File.join(Dir.tmpdir, File.basename(path)) + IO.binwrite(tmp_path, read) + + yield tmp_path + + write(IO.binread(tmp_path)) + ensure + FileUtils.rm(tmp_path) if File.exist?(tmp_path) + end + + private + def handle_missing_key + raise MissingKeyError + end + + def read_key_file + if File.exist?(key_path) + IO.binread(key_path).strip + end + end + + def key_path + @root.join("config", "secrets.yml.key") + end + + def path + @root.join("config", "secrets.yml.enc").to_s + end + + def preprocess(path) + if path.end_with?(".enc") + if @read_encrypted_secrets + decrypt(IO.binread(path)) + else + "" + end + else + IO.read(path) + end + end + + def new_cipher + OpenSSL::Cipher.new("aes-256-cbc") + end + + def cipher(mode, data) + cipher = new_cipher.public_send(mode) + cipher.key = key + cipher.update(data) << cipher.final + end + end + end +end -- cgit v1.2.3 From 1c897f500e0ec995c3ae0685966813ac2811bfb7 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 23 Feb 2017 18:30:49 +0100 Subject: Fix test:units not hitting rake task. By splitting the namespace test:units on :, we'd find our TestCommand, which knew nothing of a units method. So check that a found command also includes the command name we're trying to call. --- railties/lib/rails/command.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 73f9684ca4..d8549db62e 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -39,7 +39,8 @@ module Rails command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) namespace = "version" if %w( -v --version ).include?(command_name) - if command = find_by_namespace(namespace, command_name) + command = find_by_namespace(namespace, command_name) + if command && command.all_commands[command_name] command.perform(command_name, args, config) else find_by_namespace("rake").perform(full_namespace, args, config) -- cgit v1.2.3 From 9fdf326a5f6f7e10594dd6205cfc8e0425fb3e67 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 23 Feb 2017 18:47:23 +0100 Subject: Yank the intricate immediately-exiting editor recognition. Most editors support a wait flag of some kind which prevents their process from exiting until the file or window is closed. Prefer people to assign that themselves than us mucking around with File mtimes or other such things. Example of an editor config: ``` export EDITOR="atom --wait" ``` --- railties/lib/rails/commands/secrets/secrets_command.rb | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 05e0c228e8..3ba8c0c85b 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -21,10 +21,8 @@ module Rails require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| - watch tmp_path do - puts "Waiting for secrets file to be saved. Abort with Ctrl-C." - system("\$EDITOR #{tmp_path}") - end + puts "Waiting for secrets file to be saved. Abort with Ctrl-C." + system("\$EDITOR #{tmp_path}") end puts "New secrets encrypted and saved." @@ -33,18 +31,6 @@ module Rails rescue Rails::Secrets::MissingKeyError => error say error.message end - - private - def watch(tmp_path) - mtime, start_time = File.mtime(tmp_path), Time.now - - yield - - editor_exits_after_open = $?.success? && (Time.now - start_time) < 1 - if editor_exits_after_open - sleep 0.250 until File.mtime(tmp_path) != mtime - end - end end end end -- cgit v1.2.3 From a9bc4776386c2e7b45de1bb94fb1972d6e1b2d3c Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 23 Feb 2017 20:33:26 +0100 Subject: Use double quotes in the generated plugin test script. --- railties/lib/rails/generators/rails/plugin/templates/bin/test.tt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt index 75be76c25f..8385e6a8a2 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt @@ -1,4 +1,4 @@ -$: << File.expand_path(File.expand_path('../../test', __FILE__)) +$: << File.expand_path(File.expand_path("../../test", __FILE__)) -require 'bundler/setup' -require 'rails/plugin/test' +require "bundler/setup" +require "rails/plugin/test" -- cgit v1.2.3 From 7ffd4c849dcfa4691477fe9dc4dbd2df6c9c6b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 23 Feb 2017 14:48:38 -0500 Subject: Fix Rakefile loading generator relatively --- railties/lib/rails/api/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb index 0c0343114f..49267c2329 100644 --- a/railties/lib/rails/api/task.rb +++ b/railties/lib/rails/api/task.rb @@ -1,5 +1,5 @@ require "rdoc/task" -require "rails/api/generator" +require_relative "generator" module Rails module API -- cgit v1.2.3 From f4acdd83ff76e2338895073ed914c525e7bb33b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 23 Feb 2017 14:53:12 -0500 Subject: Preparing for 5.1.0.beta1 release --- railties/lib/rails/gem_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/gem_version.rb b/railties/lib/rails/gem_version.rb index 9c49e0655a..3174ffb0dc 100644 --- a/railties/lib/rails/gem_version.rb +++ b/railties/lib/rails/gem_version.rb @@ -8,7 +8,7 @@ module Rails MAJOR = 5 MINOR = 1 TINY = 0 - PRE = "alpha" + PRE = "beta1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From 08d4aaae0c8110e75237d26029b696a2bcd00b1f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 24 Feb 2017 09:13:44 +0900 Subject: Make version short-cut alias to work --- railties/lib/rails/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index d8549db62e..dd16e4c66a 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -37,7 +37,7 @@ module Rails end command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) - namespace = "version" if %w( -v --version ).include?(command_name) + command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name) command = find_by_namespace(namespace, command_name) if command && command.all_commands[command_name] -- cgit v1.2.3 From e69a0e34494de8d91f53c0e1647690a8775a9536 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 24 Feb 2017 09:17:13 +0900 Subject: Make help short-cut alias to work --- railties/lib/rails/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index dd16e4c66a..0d4e6dc5a1 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -36,7 +36,7 @@ module Rails command_name = namespace end - command_name = "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) + command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name) command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name) command = find_by_namespace(namespace, command_name) -- cgit v1.2.3 From 35a7a292645ee895e522769f657491e42d2a793a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 18 Feb 2017 16:42:48 +0900 Subject: Make adding gemfile entry work even if specify only the plugin name Whether the command was executed within the rails application is checked by whether or not the application's path matches `app_path`. https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/generators/rails/plugin/plugin_generator.rb#L439..L441 Therefore, if only plugin name is specified in `app_path`, addition to Gemfile is not done. However, in the rails guide an example of specifying only plugin name is given, and it is considered that there are many cases where only plugin name is specified. For that reason, made it work even if only plugin name was specified. --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 49259f32c8..d8a41d4afe 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -432,7 +432,7 @@ end end def inside_application? - rails_app_path && app_path =~ /^#{rails_app_path}/ + rails_app_path && destination_root.start_with?(rails_app_path.to_s) end def relative_path -- cgit v1.2.3 From 87a8206dbca1d6992e91eeea9a6c56e7c53e0ef1 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 24 Feb 2017 23:45:05 +0900 Subject: does not show hidden namespaces in generator's help --- railties/lib/rails/commands/generate/generate_command.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index aa8dab71b0..2718b453a8 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -4,6 +4,9 @@ module Rails module Command class GenerateCommand < Base # :nodoc: def help + require_application_and_environment! + load_generators + Rails::Generators.help self.class.command_name end -- cgit v1.2.3 From 6ac4dabbcfa092ddda24ae9ee4698a55eb495021 Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 23 Feb 2017 16:22:50 -0600 Subject: [close #24435] Send user_supplied_options to server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently when Puma gets a `:Port` it doesn't know if it is Rails' default port or if it is one that is specified by a user. Because of this it assumes that the port passed in is always a user defined port and therefor 3000 always "wins" even if you specify `port` inside of the `config/puma.rb` file when booting your server with `rails s`. The fix is to record the options that are explicitly passed in from the user and pass those to the Puma server (or all servers really). Puma then has enough information to know when `:Port` is the default and when it is user defined. I went ahead and did this for all values rails server exposes as server side options for completeness. The hardest thing was converting the input say `-p` or `--port` into the appropriate "name", in this case `Port`. There may be a more straightforward way to do this with Thor, but I'm not an expert here. Move logic for parsing user options to method Better variable name for iteration Explicitly test `--port` user input ✂️ Update array if environment variables are used --- .../lib/rails/commands/server/server_command.rb | 55 +++++++++++++++++----- 1 file changed, 44 insertions(+), 11 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index d58721f648..cde8b575b5 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -133,22 +133,55 @@ module Rails no_commands do def server_options { - server: @server, - log_stdout: @log_stdout, - Port: port, - Host: host, - DoNotReverseLookup: true, - config: options[:config], - environment: environment, - daemonize: options[:daemon], - pid: pid, - caching: options["dev-caching"], - restart_cmd: restart_command + user_supplied_options: user_supplied_options, + server: @server, + log_stdout: @log_stdout, + Port: port, + Host: host, + DoNotReverseLookup: true, + config: options[:config], + environment: environment, + daemonize: options[:daemon], + pid: pid, + caching: options["dev-caching"], + restart_cmd: restart_command } end end private + def user_supplied_options + @user_supplied_options ||= begin + # Convert incoming options array to a hash of flags + # ["-p", "3001", "-c", "foo"] # => {"-p" => true, "-c" => true} + user_flag = {} + @original_options.each_with_index { |command, i| user_flag[command] = true if i.even? } + + # Collect all options that the user has explicitly defined so we can + # differentiate them from defaults + user_supplied_options = [] + self.class.class_options.select do |key, option| + if option.aliases.any? { |name| user_flag[name] } || user_flag["--#{option.name}"] + name = option.name.to_sym + case name + when :port + name = :Port + when :binding + name = :Host + when :"dev-caching" + name = :caching + when :daemonize + name = :daemon + end + user_supplied_options << name + end + end + user_supplied_options << :Host if ENV["Host"] + user_supplied_options << :Port if ENV["PORT"] + user_supplied_options.uniq + end + end + def port ENV.fetch("PORT", options[:port]).to_i end -- cgit v1.2.3 From 0d8256433acde8bebcbeb21cc1f7e3fa7524d961 Mon Sep 17 00:00:00 2001 From: dixpac Date: Sat, 25 Feb 2017 12:48:15 +0100 Subject: Imporove docs for Rails::AppGenerator [ci skip] Add example so its easier to understand how one can overide an app generator. --- railties/lib/rails/generators/rails/app/app_generator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 86326d98ed..442258c9d1 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -32,6 +32,14 @@ module Rails # This allows you to override entire operations, like the creation of the # Gemfile, README, or JavaScript files, without needing to know exactly # what those operations do so you can create another template action. + # + # class CustomAppBuilder < Rails::AppBuilder + # def test + # @generator.gem "rspec-rails", group: [:development, :test] + # run "bundle install" + # generate "rspec:install" + # end + # end class AppBuilder def rakefile template "Rakefile" -- cgit v1.2.3 From a070dfa0c5b64084108977176b914ffb32ceac5f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 25 Feb 2017 13:08:26 +0900 Subject: Only load SystemTestCase if Puma is defined SystemTestCase supports only Puma, and always load puma's file. https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/system_testing/server.rb#L1 For that reason, the case of use Capybara but do not use Puma, it will cause an error. So we need to check about Puma is defined as well. --- railties/lib/rails/test_help.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 09931c108a..8e290239bd 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -11,7 +11,7 @@ require "rails/generators/test_case" require "active_support/testing/autorun" -if defined?(Capbyara) +if defined?(Capybara) && defined?(Puma) require "action_dispatch/system_test_case" end @@ -49,7 +49,7 @@ class ActionDispatch::IntegrationTest end end -if defined? Capybara +if defined?(Capybara) && defined?(Puma) class ActionDispatch::SystemTestCase def before_setup # :nodoc: @routes = Rails.application.routes -- cgit v1.2.3 From 60aeb6a8f9f1fc161a921c2219650c19b6e753e7 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 27 Feb 2017 17:29:16 +0900 Subject: Set correct host except development environment Currently `localhost` is used for the default host in all environments. But up to Rails 5.0, `0.0.0.0` is used except for development. So fixed to use the same value as 5.0. Fixes #28184 --- railties/lib/rails/commands/server/server_command.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index cde8b575b5..1fa27a3155 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -99,8 +99,9 @@ module Rails class_option :port, aliases: "-p", type: :numeric, desc: "Runs Rails on the specified port.", banner: :port, default: 3000 - class_option :binding, aliases: "-b", type: :string, default: "localhost", - desc: "Binds Rails to the specified IP.", banner: :IP + class_option :binding, aliases: "-b", type: :string, + desc: "Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.", + banner: :IP class_option :config, aliases: "-c", type: :string, default: "config.ru", desc: "Uses a custom rackup configuration.", banner: :file class_option :daemon, aliases: "-d", type: :boolean, default: false, @@ -187,7 +188,10 @@ module Rails end def host - ENV.fetch("HOST", options[:binding]) + unless (default_host = options[:binding]) + default_host = environment == "development" ? "localhost" : "0.0.0.0" + end + ENV.fetch("HOST", default_host) end def environment -- cgit v1.2.3 From 0192020dd01affc09d2e721ead8e134e51df05d5 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 28 Feb 2017 07:52:55 +0900 Subject: Use released webpacker in new applications Because webpacker 1.0 already released. --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 04f6341471..56e286f259 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -322,7 +322,7 @@ module Rails return [] unless options[:webpack] comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" - GemfileEntry.github "webpacker", "rails/webpacker", nil, comment + GemfileEntry.new "webpacker", nil, comment end def jbuilder_gemfile_entry -- cgit v1.2.3 From 07ccb1e133c9fd25ab215e260a616cb019bfe13f Mon Sep 17 00:00:00 2001 From: Viktor Fonic Date: Thu, 23 Feb 2017 13:07:15 +0700 Subject: Skip turbolinks for engine test application When `rails new plugin` is invoked, turbolinks should be skipped in the dummy test application generated by the plugin generator. --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 3fcd8607f0..ca48919f9a 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -92,6 +92,7 @@ task default: :test opts[:api] = options.api? opts[:skip_listen] = true opts[:skip_git] = true + opts[:skip_turbolinks] = true invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts -- cgit v1.2.3 From 0434700b0375ffb29869f4234660f5e94250ab53 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 1 Mar 2017 08:18:47 +0900 Subject: `HOST` must be all capital letters Ref: https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server/server_command.rb#L194 --- railties/lib/rails/commands/server/server_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 1fa27a3155..7e8c86fb49 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -177,7 +177,7 @@ module Rails user_supplied_options << name end end - user_supplied_options << :Host if ENV["Host"] + user_supplied_options << :Host if ENV["HOST"] user_supplied_options << :Port if ENV["PORT"] user_supplied_options.uniq end -- cgit v1.2.3 From 5c421239c3cbbb587a54a18548cf734492f6341a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 1 Mar 2017 22:19:15 +0900 Subject: Use appropriate type for `test_framework` option This fixes the following warning. ``` Expected string default value for '--test-framework'; got false (boolean) ``` --- railties/lib/rails/generators.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 3f1bf6a5bb..8ec805370b 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -63,7 +63,7 @@ module Rails stylesheet_engine: :css, scaffold_stylesheet: true, system_tests: nil, - test_framework: false, + test_framework: nil, template_engine: :erb } } -- cgit v1.2.3 From 82f7dc6178f86e5e2dd82f9e528475a6acee6cd8 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 1 Mar 2017 20:40:39 +0100 Subject: Tell users how to assign a $EDITOR. In case there's no $EDITOR assigned users would see a cryptic: ``` % EDITOR= bin/rails secrets:edit Waiting for secrets file to be saved. Abort with Ctrl-C. sh: /var/folders/wd/xnncwqp96rj0v1y2nms64mq80000gn/T/secrets.yml.enc: Permission denied New secrets encrypted and saved. ``` That error is misleading, so give a hint in this easily detectable case. Fixes #28143. --- railties/lib/rails/commands/secrets/secrets_command.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 3ba8c0c85b..9438eeb9f7 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -18,6 +18,17 @@ module Rails end def edit + if ENV["EDITOR"].empty? + say "No $EDITOR to open decrypted secrets in. Assign one like this:" + say "" + say %(EDITOR="mate --wait" bin/rails secrets:edit) + say "" + say "For editors that fork and exit immediately, it's important to pass a wait flag," + say "otherwise the secrets will be saved immediately with no chance to edit." + + return + end + require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| -- cgit v1.2.3 From 84bc9a50d35f57135932b3ef6d9984f87d1c2229 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Wed, 1 Mar 2017 20:42:54 +0100 Subject: Put it to me straight: just say it. Prefer Thor's say method to Kernel's plain puts. --- railties/lib/rails/commands/secrets/secrets_command.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 9438eeb9f7..65db81ac73 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -32,13 +32,13 @@ module Rails require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| - puts "Waiting for secrets file to be saved. Abort with Ctrl-C." + say "Waiting for secrets file to be saved. Abort with Ctrl-C." system("\$EDITOR #{tmp_path}") end - puts "New secrets encrypted and saved." + say "New secrets encrypted and saved." rescue Interrupt - puts "Aborted changing encrypted secrets: nothing saved." + say "Aborted changing encrypted secrets: nothing saved." rescue Rails::Secrets::MissingKeyError => error say error.message end -- cgit v1.2.3 From 6aa6f9ae44ed999e972a58f729bdc5b2fcdc127b Mon Sep 17 00:00:00 2001 From: Stephen Touset Date: Thu, 23 Feb 2017 14:41:40 -0800 Subject: Default Secrets to AES-128-GCM, using ActiveSupport::MessageEncryptor Fixes #28135. --- railties/lib/rails/secrets.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index a083914109..3d68e30d1d 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -1,4 +1,4 @@ -require "yaml" +require "active_support/message_encryptor" module Rails # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘 @@ -12,6 +12,8 @@ module Rails end end + CIPHER = "aes-128-gcm" + @read_encrypted_secrets = false @root = File # Wonky, but ensures `join` uses the current directory. @@ -30,20 +32,22 @@ module Rails end def generate_key - cipher = new_cipher - SecureRandom.hex(cipher.key_len)[0, cipher.key_len] + SecureRandom.hex( + OpenSSL::Cipher.new(CIPHER).key_len + ) end def key - ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key + [(ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key)] + .pack("H*") end - def encrypt(text) - cipher(:encrypt, text) + def encrypt(data) + encryptor.encrypt_and_sign(data) end def decrypt(data) - cipher(:decrypt, data) + encryptor.decrypt_and_verify(data) end def read @@ -97,14 +101,8 @@ module Rails end end - def new_cipher - OpenSSL::Cipher.new("aes-256-cbc") - end - - def cipher(mode, data) - cipher = new_cipher.public_send(mode) - cipher.key = key - cipher.update(data) << cipher.final + def encryptor + @encryptor ||= ActiveSupport::MessageEncryptor.new(key, cipher: CIPHER) end end end -- cgit v1.2.3 From 3279394c45dadb5ae33ce5c2af0018a36009830b Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 2 Mar 2017 07:54:53 +0900 Subject: Convert `ENV["EDITOR"]` to string before check In order to avoid `NoMethodError` when it is nil. Follow up to 82f7dc6178f86e5e2dd82f9e528475a6acee6cd8 --- railties/lib/rails/commands/secrets/secrets_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 65db81ac73..b9ae5d8b3b 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -18,7 +18,7 @@ module Rails end def edit - if ENV["EDITOR"].empty? + if ENV["EDITOR"].to_s.empty? say "No $EDITOR to open decrypted secrets in. Assign one like this:" say "" say %(EDITOR="mate --wait" bin/rails secrets:edit) -- cgit v1.2.3 From f2eb3417f24cddf8a407d1cc4ae6ea4ec62d3aab Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 2 Mar 2017 19:28:54 +0100 Subject: Add back yaml require. --- railties/lib/rails/secrets.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index 3d68e30d1d..f42515f47d 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -1,3 +1,4 @@ +require "yaml" require "active_support/message_encryptor" module Rails -- cgit v1.2.3 From e3b4554f231beb789b981dfb5e32789f5ad4d17b Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 2 Mar 2017 19:38:01 +0100 Subject: Move key packing into encryptor. --- railties/lib/rails/secrets.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index f42515f47d..77d9249c56 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -39,8 +39,7 @@ module Rails end def key - [(ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key)] - .pack("H*") + ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key end def encrypt(data) @@ -103,7 +102,7 @@ module Rails end def encryptor - @encryptor ||= ActiveSupport::MessageEncryptor.new(key, cipher: CIPHER) + @encryptor ||= ActiveSupport::MessageEncryptor.new([ key ].pack("H*"), cipher: CIPHER) end end end -- cgit v1.2.3 From d22f8796919b2e8eeadce1d74ad4cf33f695e57e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 2 Mar 2017 19:38:42 +0100 Subject: Inline CIPHER constant. --- railties/lib/rails/secrets.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index 77d9249c56..2a95712cd9 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -13,8 +13,7 @@ module Rails end end - CIPHER = "aes-128-gcm" - + @cipher = "aes-128-gcm" @read_encrypted_secrets = false @root = File # Wonky, but ensures `join` uses the current directory. @@ -33,9 +32,7 @@ module Rails end def generate_key - SecureRandom.hex( - OpenSSL::Cipher.new(CIPHER).key_len - ) + SecureRandom.hex(OpenSSL::Cipher.new(@cipher).key_len) end def key @@ -102,7 +99,7 @@ module Rails end def encryptor - @encryptor ||= ActiveSupport::MessageEncryptor.new([ key ].pack("H*"), cipher: CIPHER) + @encryptor ||= ActiveSupport::MessageEncryptor.new([ key ].pack("H*"), cipher: @cipher) end end end -- cgit v1.2.3 From bcbb8c718d88ebbe152aecff61bcc30ba394adaf Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Thu, 2 Mar 2017 18:10:29 +0000 Subject: Update `database.yml` when `rails new -d oracle` specified - Install "activerecord-oracle_enhanced-adapter". Oracle adapter used to be a bundled one. Now it is a 3rd party one. Also "ruby-oci8" is a required gem for CRuby, not for JRuby. - Remove oracle entry for JRuby since Oracle enhanced adapter supports both CRuby and JRuby with single gem. - Change adapter name from `oracle` to `oracle_enhanced` in the oracle.yml. Not changing `-d oracle` - Update `DATABASE_URL` entry to use a dash instead of an underscore Refer https://github.com/rails/rails/commit/d72a0cbc807a14d3eec02a53317d11b9d9fa5815 for the reason. --- railties/lib/rails/generators/app_base.rb | 3 +-- .../generators/rails/app/templates/config/databases/oracle.yml | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 56e286f259..ebe8cfea60 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -280,7 +280,7 @@ module Rails case options[:database] when "mysql" then ["mysql2", [">= 0.3.18", "< 0.5"]] when "postgresql" then ["pg", ["~> 0.18"]] - when "oracle" then ["ruby-oci8", nil] + when "oracle" then ["activerecord-oracle_enhanced-adapter", nil] when "frontbase" then ["ruby-frontbase", nil] when "sqlserver" then ["activerecord-sqlserver-adapter", nil] when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil] @@ -296,7 +296,6 @@ module Rails case options[:database] when "postgresql" then options[:database].replace "jdbcpostgresql" when "mysql" then options[:database].replace "jdbcmysql" - when "oracle" then options[:database].replace "jdbc" when "sqlite3" then options[:database].replace "jdbcsqlite3" end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/oracle.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/oracle.yml index d2499ea4fb..6da0601b24 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/oracle.yml @@ -1,4 +1,4 @@ -# Oracle/OCI 8i, 9, 10g +# Oracle/OCI 11g or higher recommended # # Requires Ruby/OCI8: # https://github.com/kubo/ruby-oci8 @@ -17,7 +17,7 @@ # cursor_sharing: similar # default: &default - adapter: oracle + adapter: oracle_enhanced pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: <%= app_name %> password: @@ -45,7 +45,9 @@ test: # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # -# DATABASE_URL="oracle://myuser:mypass@localhost/somedatabase" +# DATABASE_URL="oracle-enhanced://myuser:mypass@localhost/somedatabase" +# +# Note that the adapter name uses a dash instead of an underscore. # # You can use this database configuration with: # -- cgit v1.2.3 From 54ee15a203d7463534c2188141c6fb0090c9dc44 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 26 Feb 2017 21:05:13 +0900 Subject: Show correct commands in help Currently rails' help shows only namespace. However, the secrets command needs to specify command. Therefore, I fixed the command to display in help. --- railties/lib/rails/command/base.rb | 8 +++++++- railties/lib/rails/commands/destroy/destroy_command.rb | 6 ++++-- railties/lib/rails/commands/generate/generate_command.rb | 10 ++++++---- railties/lib/rails/commands/new/new_command.rb | 6 ++++-- railties/lib/rails/commands/runner/runner_command.rb | 8 +++++--- railties/lib/rails/commands/secrets/secrets_command.rb | 10 ++++++---- railties/lib/rails/commands/test/test_command.rb | 6 ++++-- 7 files changed, 36 insertions(+), 18 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb index db20c71861..4f074df473 100644 --- a/railties/lib/rails/command/base.rb +++ b/railties/lib/rails/command/base.rb @@ -64,7 +64,7 @@ module Rails end def printing_commands - namespace.sub(/^rails:/, "") + namespaced_commands end def executable @@ -135,6 +135,12 @@ module Rails def command_root_namespace (namespace.split(":") - %w( rails )).first end + + def namespaced_commands + commands.keys.map do |key| + key == command_root_namespace ? key : "#{command_root_namespace}:#{key}" + end + end end def help diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 5b552b2070..c802910b5d 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -3,8 +3,10 @@ require "rails/generators" module Rails module Command class DestroyCommand < Base # :nodoc: - def help - Rails::Generators.help self.class.command_name + no_commands do + def help + Rails::Generators.help self.class.command_name + end end def perform(*) diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 2718b453a8..9dd7ad1012 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -3,11 +3,13 @@ require "rails/generators" module Rails module Command class GenerateCommand < Base # :nodoc: - def help - require_application_and_environment! - load_generators + no_commands do + def help + require_application_and_environment! + load_generators - Rails::Generators.help self.class.command_name + Rails::Generators.help self.class.command_name + end end def perform(*) diff --git a/railties/lib/rails/commands/new/new_command.rb b/railties/lib/rails/commands/new/new_command.rb index 74d1fa5021..207dd5d995 100644 --- a/railties/lib/rails/commands/new/new_command.rb +++ b/railties/lib/rails/commands/new/new_command.rb @@ -1,8 +1,10 @@ module Rails module Command class NewCommand < Base # :nodoc: - def help - Rails::Command.invoke :application, [ "--help" ] + no_commands do + def help + Rails::Command.invoke :application, [ "--help" ] + end end def perform(*) diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 4989a7837d..056ad980b9 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -5,9 +5,11 @@ module Rails default: Rails::Command.environment.dup, desc: "The environment for the runner to operate under (test/development/production)" - def help - super - puts self.class.desc + no_commands do + def help + super + puts self.class.desc + end end def self.banner(*) diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 3ba8c0c85b..c6d9ec0008 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -4,10 +4,12 @@ require "rails/secrets" module Rails module Command class SecretsCommand < Rails::Command::Base # :nodoc: - def help - say "Usage:\n #{self.class.banner}" - say "" - say self.class.desc + no_commands do + def help + say "Usage:\n #{self.class.banner}" + say "" + say self.class.desc + end end def setup diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 629fb5b425..65e16900ba 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -4,8 +4,10 @@ require "rails/test_unit/minitest_plugin" module Rails module Command class TestCommand < Base # :nodoc: - def help - perform # Hand over help printing to minitest. + no_commands do + def help + perform # Hand over help printing to minitest. + end end def perform(*) -- cgit v1.2.3 From d3e7d91050da858bd5ec6a061b96466bd9ac85ef Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 3 Mar 2017 14:34:31 -0500 Subject: Remove unnecessary system test code It turns out that we don't need to require system tests in the railties test helper so we can remove it. If you're using system tests they will be loaded by inheriting from ActionDispatch::SystemTestCase and the routes will be loaded by ActionDispatch::IntegrationTest. --- railties/lib/rails/test_help.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 8e290239bd..0f9bf98737 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -11,10 +11,6 @@ require "rails/generators/test_case" require "active_support/testing/autorun" -if defined?(Capybara) && defined?(Puma) - require "action_dispatch/system_test_case" -end - if defined?(ActiveRecord::Base) ActiveRecord::Migration.maintain_test_schema! @@ -48,12 +44,3 @@ class ActionDispatch::IntegrationTest super end end - -if defined?(Capybara) && defined?(Puma) - class ActionDispatch::SystemTestCase - def before_setup # :nodoc: - @routes = Rails.application.routes - super - end - end -end -- cgit v1.2.3 From 49d61aed4cc52b8c649f74d23781b3d3f6e01f41 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 4 Mar 2017 12:05:18 +0900 Subject: A private method can't be called with `self.` So calling `filename_with_extensions` omitting the second argument like this https://github.com/slim-template/slim-rails/blob/8dbc1fbf859ebfa95b0884a0196a6ad9f0ca9cd5/lib/generators/slim/scaffold/scaffold_generator.rb#L10 causes NoMethodError. fixes #28275 --- railties/lib/rails/generators/erb.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/erb.rb b/railties/lib/rails/generators/erb.rb index d5e326d6ee..97d9ab29d4 100644 --- a/railties/lib/rails/generators/erb.rb +++ b/railties/lib/rails/generators/erb.rb @@ -17,8 +17,8 @@ module Erb # :nodoc: :erb end - def filename_with_extensions(name, format = self.format) - [name, format, handler].compact.join(".") + def filename_with_extensions(name, file_format = format) + [name, file_format, handler].compact.join(".") end end end -- cgit v1.2.3 From 4a77213eead0e33a8158e47525bad3d5e1996300 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sat, 4 Mar 2017 14:54:03 +0100 Subject: Avoid running system tests by default These tests may be expansive so let's only allow users to run them through `bin/rails test:system` or by passing a path to the `test` command. The same applies for `bin/rake test`. Refs #28109. --- railties/lib/rails/test_unit/minitest_plugin.rb | 12 +++++++++--- railties/lib/rails/test_unit/test_requirer.rb | 7 +++++-- railties/lib/rails/test_unit/testing.rake | 10 +++++----- 3 files changed, 19 insertions(+), 10 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index e44fe78bbd..8decdb0f4f 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -62,9 +62,9 @@ module Minitest options[:patterns] = opts.order! unless run_via.rake? end - def self.rake_run(patterns) # :nodoc: + def self.rake_run(patterns, exclude_patterns = []) # :nodoc: self.run_via = :rake unless run_via.set? - ::Rails::TestRequirer.require_files(patterns) + ::Rails::TestRequirer.require_files(patterns, exclude_patterns) autorun end @@ -88,7 +88,13 @@ module Minitest # If run via `ruby` we've been passed the files to run directly, or if run # via `rake` then they have already been eagerly required. unless run_via.ruby? || run_via.rake? - ::Rails::TestRequirer.require_files(options[:patterns]) + # If there are no given patterns, we can assume that the user + # simply runs the `bin/rails test` command without extra arguments. + if options[:patterns].empty? + ::Rails::TestRequirer.require_files(options[:patterns], ["test/system/**/*"]) + else + ::Rails::TestRequirer.require_files(options[:patterns]) + end end unless options[:full_backtrace] || ENV["BACKTRACE"] diff --git a/railties/lib/rails/test_unit/test_requirer.rb b/railties/lib/rails/test_unit/test_requirer.rb index fe35934abc..92e5fcf0bc 100644 --- a/railties/lib/rails/test_unit/test_requirer.rb +++ b/railties/lib/rails/test_unit/test_requirer.rb @@ -4,10 +4,13 @@ require "rake/file_list" module Rails class TestRequirer # :nodoc: class << self - def require_files(patterns) + def require_files(patterns, exclude_patterns = []) patterns = expand_patterns(patterns) - Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"].to_a.each do |file| + file_list = Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"] + file_list.exclude(exclude_patterns) + + file_list.to_a.each do |file| require File.expand_path(file) end end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 4dde3d3c97..ef19bd7626 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -4,15 +4,15 @@ require "rails/test_unit/minitest_plugin" task default: :test -desc "Runs all tests in test folder" +desc "Runs all tests in test folder except system ones" task :test do $: << "test" - pattern = if ENV.key?("TEST") - ENV["TEST"] + + if ENV.key?("TEST") + Minitest.rake_run([ENV["TEST"]]) else - "test" + Minitest.rake_run(["test"], ["test/system/**/*"]) end - Minitest.rake_run([pattern]) end namespace :test do -- cgit v1.2.3 From b16dcc872bb3c094cf1f1d890bdd302593acbbe8 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 9 Mar 2017 20:19:58 +0100 Subject: [ci skip] Document read_encrypted_secrets config. Mostly just that it's there. Closes #28193. --- railties/lib/rails/commands/secrets/USAGE | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/secrets/USAGE b/railties/lib/rails/commands/secrets/USAGE index 4b7deb4e2a..96e322fe91 100644 --- a/railties/lib/rails/commands/secrets/USAGE +++ b/railties/lib/rails/commands/secrets/USAGE @@ -40,6 +40,14 @@ be encrypted. A `shared:` top level key is also supported such that any keys there is merged into the other environments. +Additionally, Rails won't read encrypted secrets out of the box even if you have +the key. Add this: + + config.read_encrypted_secrets = true + +to the environment you'd like to read encrypted secrets. `bin/rails secrets:setup` +inserts this into the production environment by default. + === Editing Secrets After `bin/rails secrets:setup`, run `bin/rails secrets:edit`. -- cgit v1.2.3 From bd1b24199a71f7b2a171cce69b8e0e9b1c77f8b2 Mon Sep 17 00:00:00 2001 From: Ivan Velasquez Date: Mon, 13 Mar 2017 19:37:40 -0600 Subject: user form with instead of form for in scaffold generator --- railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb index 519b6c8603..8fd85ffb8a 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%%= form_for(<%= singular_table_name %>) do |f| %> +<%%= form_with(model: <%= singular_table_name %>) do |f| %> <%% if <%= singular_table_name %>.errors.any? %>

<%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:

-- cgit v1.2.3 From bc35e63909ef922a0031728350c227ab8e9326fe Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 14 Mar 2017 16:46:19 +0900 Subject: Make destroy command work within engines Instead of calling methods of Rails.application directly, we need to use a method that is considered for the rails engine. --- railties/lib/rails/commands/destroy/destroy_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index c802910b5d..794673851d 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -14,9 +14,9 @@ module Rails return help unless generator require_application_and_environment! - Rails.application.load_generators + load_generators - Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails.root + Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails::Command.root end end end -- cgit v1.2.3 From 031487568d8f1e8147602dd42c877f475bdc046c Mon Sep 17 00:00:00 2001 From: Ivan Velasquez Date: Tue, 14 Mar 2017 08:40:25 -0600 Subject: disable remote submits --- railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb index 8fd85ffb8a..ac8a568071 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%%= form_with(model: <%= singular_table_name %>) do |f| %> +<%%= form_with(model: <%= singular_table_name %>, local: true) do |f| %> <%% if <%= singular_table_name %>.errors.any? %>

<%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:

-- cgit v1.2.3 From ad44d7a054f3897154d5c275ddecade4032d0d54 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 14 Mar 2017 17:16:32 -0500 Subject: Raise when using a bad symlink There was a case where a dev made a symlink that worked on some machines and not on others. The issue manifested itself on a machine with `RAILS_ENV=staging` as the had their `config/environments/staging.rb` symlinked to another config file. The behavior was very hard to track down. Current behavior: If you use a bad symlink in a file, you get no warnings or failures or anything. If you have a bad symlink it just ignores the file as if it didn't exist (`File.exist?` returns false for a bad symlink). Patch behavior: With this patch when a file is not present we check if a symlink exists. If it does, that indicates there is a bad symlink and we should raise ``` File "config/environments/staging.rb" is a symlink that does not point to a valid file ``` --- railties/lib/rails/paths.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index af3be10a31..6bdb673215 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -205,7 +205,14 @@ module Rails # Returns all expanded paths but only if they exist in the filesystem. def existent - expanded.select { |f| File.exist?(f) } + expanded.select do |f| + does_exist = File.exist?(f) + + if !does_exist && File.symlink?(f) + raise "File #{f.inspect} is a symlink that does not point to a valid file" + end + does_exist + end end def existent_directories -- cgit v1.2.3 From eadbc82c47fd157ed4f1eb4c4983ab0734023106 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 17 Mar 2017 08:18:55 -0400 Subject: Bump Capybara and include Minitest::Assertions Capybara was updated in teamcapybara/capybara#1841 to use Minitest style assertions so that system test output shows x number of assertions, x numbe of failures, etc. Before: ``` 6 runs, 0 assertions, 0 failures, 0 errors, 0 skips ``` After: ``` 6 runs, 7 assertions, 1 failures, 0 errors, 0 skips ``` This change bumps Capybara from 2.7.0 to 2.13.0 and includes the required minitest assertion file in the test case. :tada: --- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index b082d70cba..ab4aa04fff 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -34,7 +34,7 @@ group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] <%- unless options.skip_system_test? || options.api? -%> # Adds support for Capybara system testing and selenium driver - gem 'capybara', '~> 2.7.0' + gem 'capybara', '~> 2.13.0' gem 'selenium-webdriver' <%- end -%> end -- cgit v1.2.3 From 4183ee882055f997fe61804ba43ee4c168b2477c Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 18 Mar 2017 07:30:30 +1030 Subject: Track the version-compatible config settings inside railties Instead of forcing new applications to carry an initializer that just switches things to what their default "should" be, we can handle it internally. The initializer is then only used by upgraders: it shows what the new default would be (commented out), while their upgraded application continues to operate as it did before. Under this model, a multiply-upgraded application could accumulate several new_framework_defaults_*.rb files, for each release series it has traversed. A given release series only needs to generate the latest, though, because we don't support `rails app:upgrade` while skipping releases. --- railties/lib/rails/application/configuration.rb | 28 ++++++++++++++++ .../rails/generators/rails/app/app_generator.rb | 8 +++++ .../rails/app/templates/config/application.rb | 3 ++ .../initializers/new_framework_defaults.rb.tt | 37 ---------------------- .../initializers/new_framework_defaults_5_1.rb.tt | 13 ++++++++ 5 files changed, 52 insertions(+), 37 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt create mode 100644 railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index b0592151b7..027207bbb2 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -55,6 +55,34 @@ module Rails @read_encrypted_secrets = false end + def load_defaults(target_version) + case target_version.to_s + when "5.0" + if defined?(action_controller) + action_controller.per_form_csrf_tokens = true + action_controller.forgery_protection_origin_check = true + end + + ActiveSupport.to_time_preserves_timezone = true + + if defined?(active_record) + active_record.belongs_to_required_by_default = true + end + + self.ssl_options = { hsts: { subdomains: true } } + + when "5.1" + load_defaults "5.0" + + if defined?(assets) + assets.unknown_asset_fallback = false + end + + else + raise "Unknown version #{target_version.to_s.inspect}" + end + end + def encoding=(value) @encoding = value silence_warnings do diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 442258c9d1..38830ba38f 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -371,6 +371,14 @@ module Rails end end + def delete_new_framework_defaults + # Sprockets owns the only new default for 5.1: if it's disabled, + # we don't want the file. + unless options[:update] && !options[:skip_sprockets] + remove_file "config/initializers/new_framework_defaults_5_1.rb" + end + end + def delete_bin_yarn_if_skip_yarn_option remove_file "bin/yarn" if options[:skip_yarn] end diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index c0a0bd0a3e..d5d214052f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -22,6 +22,9 @@ Bundler.require(*Rails.groups) module <%= app_const_base %> class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults <%= Rails::VERSION::STRING.to_f %> + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt deleted file mode 100644 index bd844f0503..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +++ /dev/null @@ -1,37 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 5.0 upgrade. -# -<%- if options[:update] -%> -# Once upgraded flip defaults one by one to migrate to the new default. -# -<%- end -%> -# Read the Guide for Upgrading Ruby on Rails for more info on each option. -<%- unless options[:api] -%> - -# Enable per-form CSRF tokens. Previous versions had false. -Rails.application.config.action_controller.per_form_csrf_tokens = <%= options[:update] ? false : true %> - -# Enable origin-checking CSRF mitigation. Previous versions had false. -Rails.application.config.action_controller.forgery_protection_origin_check = <%= options[:update] ? false : true %> -<%- end -%> - -# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. -# Previous versions had false. -ActiveSupport.to_time_preserves_timezone = <%= options[:update] ? false : true %> -<%- unless options[:skip_active_record] -%> - -# Require `belongs_to` associations by default. Previous versions had false. -Rails.application.config.active_record.belongs_to_required_by_default = <%= options[:update] ? false : true %> -<%- end -%> -<%- unless options[:update] -%> - -# Configure SSL options to enable HSTS with subdomains. Previous versions had false. -Rails.application.config.ssl_options = { hsts: { subdomains: true } } -<%- end -%> -<%- unless options[:skip_sprockets] -%> - -# Unknown asset fallback will return the path passed in when the given -# asset is not present in the asset pipeline. -Rails.application.config.assets.unknown_asset_fallback = <%= options[:update] ? true : false %> -<%- end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt new file mode 100644 index 0000000000..5f5545c4c7 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt @@ -0,0 +1,13 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +<%- unless options[:skip_sprockets] -%> + +# Unknown asset fallback will return the path passed in when the given +# asset is not present in the asset pipeline. +# Rails.application.config.assets.unknown_asset_fallback = false +<%- end -%> -- cgit v1.2.3 From 53e6fe96b5664e92ee6cd64d08681254fc816f44 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 19 Mar 2017 17:20:41 +0900 Subject: Correctly check whether key is defined in configuration It can not check correctly with `defined?` ```ruby irb(main):001:0> Rails.application.config.active_record => {:maintain_test_schema=>true, :belongs_to_required_by_default=>true} irb(main):002:0> defined?(Rails.application.config.active_record) => nil ``` Follow up to #28469 --- railties/lib/rails/application/configuration.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 027207bbb2..819e801740 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -58,14 +58,14 @@ module Rails def load_defaults(target_version) case target_version.to_s when "5.0" - if defined?(action_controller) + if respond_to?(:action_controller) action_controller.per_form_csrf_tokens = true action_controller.forgery_protection_origin_check = true end ActiveSupport.to_time_preserves_timezone = true - if defined?(active_record) + if respond_to?(:active_record) active_record.belongs_to_required_by_default = true end @@ -74,7 +74,7 @@ module Rails when "5.1" load_defaults "5.0" - if defined?(assets) + if respond_to?(:assets) assets.unknown_asset_fallback = false end -- cgit v1.2.3 From a42351acbc5406ab0825befe641144b4cb1ee6bf Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 16 Jan 2017 22:27:51 +0900 Subject: Add `app:update` task to engines Occasionally we update the file generated by engine. Therefore, I think that there is a task for updating as well as application in the engine, it is convenient for updating. --- railties/lib/rails/engine/updater.rb | 19 +++++++++++++++++++ .../rails/generators/rails/plugin/plugin_generator.rb | 2 +- railties/lib/rails/tasks/engine.rake | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 railties/lib/rails/engine/updater.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/engine/updater.rb b/railties/lib/rails/engine/updater.rb new file mode 100644 index 0000000000..2ecf994a5c --- /dev/null +++ b/railties/lib/rails/engine/updater.rb @@ -0,0 +1,19 @@ +require "rails/generators" +require "rails/generators/rails/plugin/plugin_generator" + +module Rails + class Engine + class Updater + class << self + def generator + @generator ||= Rails::Generators::PluginGenerator.new ["plugin"], + { engine: true }, destination_root: ENGINE_ROOT + end + + def run(action) + generator.send(action) + end + end + end + end +end diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index ca48919f9a..118e44d9d0 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -301,7 +301,7 @@ task default: :test end def engine? - full? || mountable? + full? || mountable? || options[:engine] end def full? diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index c92b42f6c1..177b138090 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -1,6 +1,17 @@ task "load_app" do namespace :app do load APP_RAKEFILE + + desc "Update some initially generated files" + task update: [ "update:bin" ] + + namespace :update do + require "rails/engine/updater" + # desc "Adds new executables to the engine bin/ directory" + task :bin do + Rails::Engine::Updater.run(:create_bin_files) + end + end end task environment: "app:environment" -- cgit v1.2.3 From 8ff7ca5d112a5db5c1449f687e5bdc15e3670579 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 20 Mar 2017 19:57:56 +0100 Subject: Default to yielding a `form` variable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More intention revealing and means `f` can go F itself 😋 --- .../generators/erb/scaffold/templates/_form.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb index ac8a568071..73c00ad41a 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%%= form_with(model: <%= singular_table_name %>, local: true) do |f| %> +<%%= form_with(model: <%= singular_table_name %>, local: true) do |form| %> <%% if <%= singular_table_name %>.errors.any? %>

<%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:

@@ -14,21 +14,21 @@ <% attributes.each do |attribute| -%>
<% if attribute.password_digest? -%> - <%%= f.label :password %> - <%%= f.password_field :password %> + <%%= form.label :password %> + <%%= form.password_field :password %>
- <%%= f.label :password_confirmation %> - <%%= f.password_field :password_confirmation %> + <%%= form.label :password_confirmation %> + <%%= form.password_field :password_confirmation %> <% else -%> - <%%= f.label :<%= attribute.column_name %> %> - <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %> + <%%= form.label :<%= attribute.column_name %> %> + <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %> <% end -%>
<% end -%>
- <%%= f.submit %> + <%%= form.submit %>
<%% end %> -- cgit v1.2.3 From d0accc23b3d01a7d35e73c5dc901014d883ef5f7 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 21 Mar 2017 19:07:40 -0400 Subject: CLI arg "host" has precedence over ENV var "host" This is a regression from when the server command switched to its own argument parser, as opposed to Rack's. Rack's argument parser, when provided with a "host" argument, gives that value precedence over environment variables. --- railties/lib/rails/commands/server/server_command.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 7e8c86fb49..278fe63c51 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -188,10 +188,12 @@ module Rails end def host - unless (default_host = options[:binding]) + if options[:binding] + options[:binding] + else default_host = environment == "development" ? "localhost" : "0.0.0.0" + ENV.fetch("HOST", default_host) end - ENV.fetch("HOST", default_host) end def environment -- cgit v1.2.3 From 6c08d480f13d3332c878ca8a120a03fcd78f7ba2 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 22 Mar 2017 10:11:39 +1030 Subject: Start Rails 5.2 development --- railties/lib/rails/application/configuration.rb | 3 +++ railties/lib/rails/gem_version.rb | 4 ++-- railties/lib/rails/generators/app_base.rb | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 819e801740..c3b91b8af9 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -78,6 +78,9 @@ module Rails assets.unknown_asset_fallback = false end + when "5.2" + load_defaults "5.1" + else raise "Unknown version #{target_version.to_s.inspect}" end diff --git a/railties/lib/rails/gem_version.rb b/railties/lib/rails/gem_version.rb index 3174ffb0dc..7bacf2e0ba 100644 --- a/railties/lib/rails/gem_version.rb +++ b/railties/lib/rails/gem_version.rb @@ -6,9 +6,9 @@ module Rails module VERSION MAJOR = 5 - MINOR = 1 + MINOR = 2 TINY = 0 - PRE = "beta1" + PRE = "alpha" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ebe8cfea60..3e7f69e9eb 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -246,6 +246,7 @@ module Rails def rails_gemfile_entry dev_edge_common = [ + GemfileEntry.github("arel", "rails/arel"), ] if options.dev? [ -- cgit v1.2.3 From 142db6269bf6486440627d9cd884dc0e33179313 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 22 Mar 2017 21:49:33 +0900 Subject: Don't comment out config.file_watcher during Rails upgrade This is necessary only when updating to Rails 5.0, it is not necessary for updating to 5.1. Related #24243 --- railties/lib/rails/generators/rails/app/app_generator.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 38830ba38f..b32878cf0b 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -109,8 +109,6 @@ module Rails config - gsub_file "config/environments/development.rb", /^(\s+)config\.file_watcher/, '\1# config.file_watcher' - unless cookie_serializer_config_exist gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal" end -- cgit v1.2.3 From a06a643e0572b8c983738c068ae637d020188c97 Mon Sep 17 00:00:00 2001 From: Robert Thau Date: Tue, 21 Mar 2017 23:07:07 -0400 Subject: Correctly reset ARGV for "rails runner `CODE' arg arg arg..." The code itself should not be in the ARGV vector. Fixes #28515 --- railties/lib/rails/commands/runner/runner_command.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 056ad980b9..6864a9726b 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -16,7 +16,7 @@ module Rails "#{super} [<'Some.ruby(code)'> | ]" end - def perform(code_or_file = nil, *file_argv) + def perform(code_or_file = nil, *command_argv) unless code_or_file help exit 1 @@ -27,9 +27,10 @@ module Rails require_application_and_environment! Rails.application.load_runner + ARGV.replace(command_argv) + if File.exist?(code_or_file) $0 = code_or_file - ARGV.replace(file_argv) Kernel.load code_or_file else begin -- cgit v1.2.3 From 4f943eb7bae64b8add3f8cde054b80457f7da89b Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 22 Mar 2017 05:54:30 -0700 Subject: Don't add a dummy API key to every new Rails app Every new Rails app is currently generated with `Rails.application.secrets[:api_key]` set to `123`. This comes from a line in `config/secrets.yml` that, in my opinion, should be left commented out to only serve as a syntax example, rather than being actually set in every Rails app. Additionally, we might want to give a better example than `123`, since in the same file we are suggesting to > Make sure the secret is at least 30 characters and all random, > no regular words or you'll be exposed to dictionary attacks. The result of this commit is that `config/secrets.yml` will include something like: ```yaml # Shared secrets are available across all environments. # shared: # api_key: f56930851993982510d5bd9236f4108f6fe7c15448f1c6923a51872e0dbae1a24d274b318abb6518b540dfb51079c61640885f607467e5ed1053849be7587d61 ``` rather than this: ```yaml # Shared secrets are available across all environments. shared: api_key: 123 ``` --- railties/lib/rails/generators/rails/app/templates/config/secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml index 816efcc5b1..ea9d47396c 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/secrets.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/secrets.yml @@ -12,8 +12,8 @@ # Shared secrets are available across all environments. -shared: - api_key: 123 +# shared: +# api_key: a1B2c3D4e5F6 # Environmental secrets are only available for that specific environment. -- cgit v1.2.3 From 1c6d394da188071588d07957ca7ad67025cab637 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 22 Mar 2017 15:51:02 -0700 Subject: List options for `rails new --webpack=WEBPACK` When you type `rails new -h`, the `--database=DATABASE` options display this useful message: > Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) However, the `--webpack=WEBPACK` option only displays this: > Preconfigure for app-like JavaScript with Webpack so it's hard to know *which* values are valid for `WEBPACK`. This commit improves the help message to display: > Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular) The implication of this commit is that the list needs to be manually updated whenever rails/webpacker adds support for a new framework. However, I don't imagine this list to change very frequently, and I think that the benefit of display the list to the users is greater than the hustle of updating the list when needed. --- railties/lib/rails/generators/app_base.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 3e7f69e9eb..fbb6b5039c 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -13,6 +13,7 @@ module Rails DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver ) JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc ) DATABASES.concat(JDBC_DATABASES) + WEBPACKS = %w( react vue angular ) attr_accessor :rails_template add_shebang_option! @@ -34,7 +35,7 @@ module Rails desc: "Preconfigure for selected JavaScript library" class_option :webpack, type: :string, default: nil, - desc: "Preconfigure for app-like JavaScript with Webpack" + desc: "Preconfigure for app-like JavaScript with Webpack (options: #{WEBPACKS.join('/')})" class_option :skip_yarn, type: :boolean, default: false, desc: "Don't use Yarn for managing JavaScript dependencies" -- cgit v1.2.3 From 42198064c35ff3b701496309f90df2abc229efbe Mon Sep 17 00:00:00 2001 From: claudiob Date: Thu, 23 Mar 2017 08:07:04 -0700 Subject: Remove -j (--javascript) option from `rails new` The "-j" option was added 5 years ago (https://github.com/rails/rails/commit/d9c39c3a) when we wanted to support prototype-rails and jquery-rails. Prototype is not as popular and jQuery is not a requirement anymore. Still the "-j" option can be used to install *any* gem that ends in "-rails". This "might" open security issues and does not bring great benefits anymore. If you know which "-rails"-ending gem you want to install, you can manually add it to the Gemfile just like any other gem. --- railties/lib/rails/generators/app_base.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index fbb6b5039c..56cd494955 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -31,9 +31,6 @@ module Rails class_option :database, type: :string, aliases: "-d", default: "sqlite3", desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})" - class_option :javascript, type: :string, aliases: "-j", - desc: "Preconfigure for selected JavaScript library" - class_option :webpack, type: :string, default: nil, desc: "Preconfigure for app-like JavaScript with Webpack (options: #{WEBPACKS.join('/')})" @@ -342,11 +339,6 @@ module Rails gems = [javascript_runtime_gemfile_entry] gems << coffee_gemfile_entry unless options[:skip_coffee] - if options[:javascript] - gems << GemfileEntry.version("#{options[:javascript]}-rails", nil, - "Use #{options[:javascript]} as the JavaScript library") - end - unless options[:skip_turbolinks] gems << GemfileEntry.version("turbolinks", "~> 5", "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks") -- cgit v1.2.3 From 166a388301b17bb6b0c56527b010af9164a22fa7 Mon Sep 17 00:00:00 2001 From: Jess Brown Date: Thu, 23 Mar 2017 14:30:45 -0400 Subject: make it clear how to enable caching since this is a new change, many will be coming here to toggle the true/false config and not find it. This will allow them to quickly implement the change. --- .../generators/rails/app/templates/config/environments/development.rb.tt | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 511b4a82eb..451b9ef28b 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 @@ -13,6 +13,7 @@ Rails.application.configure do config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. + # run rails dev:cache to toggle caching if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true -- cgit v1.2.3 From a9124e1afdb4f3b5f84e83bc2a524761a8b996f1 Mon Sep 17 00:00:00 2001 From: Jess Brown Date: Thu, 23 Mar 2017 18:16:45 -0400 Subject: add proper punctuation --- .../rails/app/templates/config/environments/development.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 451b9ef28b..b75b65c8df 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 @@ -13,7 +13,7 @@ Rails.application.configure do config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - # run rails dev:cache to toggle caching + # Run rails dev:cache to toggle caching. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true -- cgit v1.2.3 From e7c4fe581c6eab18df706875eb57df82e27a1e8f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 24 Mar 2017 08:31:30 +0900 Subject: Remove unnecessary files to API-only Applications when `app:task` task executed --- .../rails/generators/rails/app/app_generator.rb | 33 ++++++++++++++++++++++ railties/lib/rails/tasks/framework.rake | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index b32878cf0b..2c935dd998 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -84,6 +84,16 @@ module Rails chmod "bin", 0755 & ~File.umask, verbose: false end + def bin_when_updating + bin_yarn_exist = File.exist?("bin/yarn") + + bin + + if options[:api] && !bin_yarn_exist + remove_file "bin/yarn" + end + end + def config empty_directory "config" @@ -106,6 +116,8 @@ module Rails cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb") action_cable_config_exist = File.exist?("config/cable.yml") rack_cors_config_exist = File.exist?("config/initializers/cors.rb") + assets_config_exist = File.exist?("config/initializers/assets.rb") + new_framework_defaults_5_1_exist = File.exist?("config/initializers/new_framework_defaults_5_1.rb") config @@ -120,6 +132,22 @@ module Rails unless rack_cors_config_exist remove_file "config/initializers/cors.rb" end + + if options[:api] + unless cookie_serializer_config_exist + remove_file "config/initializers/cookies_serializer.rb" + end + + unless assets_config_exist + remove_file "config/initializers/assets.rb" + end + + # Sprockets owns the only new default for 5.1: + # In API-only Applications, we don't want the file. + unless new_framework_defaults_5_1_exist + remove_file "config/initializers/new_framework_defaults_5_1.rb" + end + end end def database_yml @@ -230,6 +258,11 @@ module Rails build(:bin) end + def update_bin_files + build(:bin_when_updating) + end + remove_task :update_bin_files + def create_config_files build(:config) end diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index f5586b53f0..32a6b109bc 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -63,7 +63,7 @@ namespace :app do # desc "Adds new executables to the application bin/ directory" task :bin do - RailsUpdate.invoke_from_app_generator :create_bin_files + RailsUpdate.invoke_from_app_generator :update_bin_files end task :upgrade_guide_info do -- cgit v1.2.3 From 27f103fc7e3260efe0b8dde66bf5354f2202ee32 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sun, 26 Mar 2017 11:42:39 +0200 Subject: add field ids when generating a scaffold form. This is a follow up to a6d065e. When using `form_with` you must supply field ids manually. Since the scaffold generator is using labels we need to make sure that they are linked up properly. --- railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb | 6 +++--- railties/lib/rails/generators/named_base.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb index 73c00ad41a..4f2e84f924 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -15,15 +15,15 @@
<% if attribute.password_digest? -%> <%%= form.label :password %> - <%%= form.password_field :password %> + <%%= form.password_field :password, id: :<%= field_id(:password) %> %>
<%%= form.label :password_confirmation %> - <%%= form.password_field :password_confirmation %> + <%%= form.password_field :password_confirmation, id: :<%= field_id(:password_confirmation) %> %> <% else -%> <%%= form.label :<%= attribute.column_name %> %> - <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %> + <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, id: :<%= field_id(attribute.column_name) %> %> <% end -%>
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 02557b098a..46001f306a 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -149,6 +149,10 @@ module Rails "new_#{singular_table_name}_url" end + def field_id(attribute_name) + [singular_table_name, attribute_name].join('_') + end + def singular_table_name # :doc: @singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name) end -- cgit v1.2.3 From 9a0ad3f5efd34983baf873235356517c680860ee Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 27 Mar 2017 08:29:20 +0900 Subject: Do not show hidden namespaces in destroy commnad help --- railties/lib/rails/commands/destroy/destroy_command.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 794673851d..281732a936 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -5,6 +5,9 @@ module Rails class DestroyCommand < Base # :nodoc: no_commands do def help + require_application_and_environment! + load_generators + Rails::Generators.help self.class.command_name end end -- cgit v1.2.3 From 72b4265766400a752dae27a3d7d94ccd86df00cb Mon Sep 17 00:00:00 2001 From: ota42y Date: Thu, 23 Mar 2017 13:40:15 +0900 Subject: ignore system test gems on Gemfile when execute with --skip-test option --- railties/lib/rails/generators/app_base.rb | 4 ++++ railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index fbb6b5039c..8c3d74ad80 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -413,6 +413,10 @@ module Rails !options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin") end + def depends_on_system_test? + !(options[:skip_system_test] || options[:skip_test] || options[:api]) + end + def depend_on_listen? !options[:skip_listen] && os_supports_listen_out_of_the_box? end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index b32878cf0b..66e72f8cdc 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -275,7 +275,7 @@ module Rails end def create_system_test_files - build(:system_test) unless options[:skip_system_test] || options[:skip_test] || options[:api] + build(:system_test) if depends_on_system_test? end def create_tmp_files diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index ab4aa04fff..06f0dd6d6d 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -32,7 +32,7 @@ end group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] - <%- unless options.skip_system_test? || options.api? -%> + <%- if depends_on_system_test? -%> # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13.0' gem 'selenium-webdriver' -- cgit v1.2.3 From 794a6ca71ebdd3794710c503131580e9cb02982c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 27 Mar 2017 19:19:44 -0400 Subject: Apply the log_level default Since 4.2 the default log level in production is now debug. We removed the deprecation in c2e865849beadd99866e521a93d733da7d1b5255 but we don't reflected the default value. We are not appling it. Closes #28558 --- railties/lib/rails/application/configuration.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index c3b91b8af9..7c49fabba5 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -14,9 +14,8 @@ module Rails :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, :beginning_of_week, :filter_redirect, :x, :enable_dependency_loading, - :read_encrypted_secrets + :read_encrypted_secrets, :log_level - attr_writer :log_level attr_reader :encoding, :api_only def initialize(*) @@ -35,7 +34,7 @@ module Rails @session_store = nil @time_zone = "UTC" @beginning_of_week = :monday - @log_level = nil + @log_level = :debug @generators = app_generators @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @railties_order = [:all] @@ -152,10 +151,6 @@ module Rails raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace end - def log_level - @log_level ||= (Rails.env.production? ? :info : :debug) - end - def colorize_logging ActiveSupport::LogSubscriber.colorize_logging end -- cgit v1.2.3 From fcf2430cb4e1efd6bf843bea3a39ff0531db1488 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 29 Mar 2017 07:56:54 +0900 Subject: Remove unnecessary `javascript` option check Follow up to #28546 --- .../rails/app/templates/app/assets/javascripts/application.js.tt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 25870f19c8..4206002a1b 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -1,7 +1,7 @@ // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's // vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the @@ -11,9 +11,6 @@ // about supported directives. // <% unless options[:skip_javascript] -%> -<% if options[:javascript] -%> -//= require <%= options[:javascript] %> -<% end -%> //= require rails-ujs <% unless options[:skip_turbolinks] -%> //= require turbolinks -- cgit v1.2.3 From bc76ecf6550375176e46f3ea296607744d12bbfe Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Sun, 19 Mar 2017 23:28:57 +0900 Subject: Fix the example code for `Rails.groups` [ci skip] `Rails.groups` contains `Rails.env` that is inspected as String. --- railties/lib/rails.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 00add5829d..6d8bf28943 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -87,8 +87,8 @@ module Rails # groups assets: [:development, :test] # # # Returns - # # => [:default, :development, :assets] for Rails.env == "development" - # # => [:default, :production] for Rails.env == "production" + # # => [:default, "development", :assets] for Rails.env == "development" + # # => [:default, "production"] for Rails.env == "production" def groups(*groups) hash = groups.extract_options! env = Rails.env -- cgit v1.2.3