aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application/configuration.rb4
-rw-r--r--railties/lib/rails/application/default_middleware_stack.rb2
-rw-r--r--railties/lib/rails/generators/actions.rb5
-rw-r--r--railties/lib/rails/generators/app_base.rb8
-rw-r--r--railties/lib/rails/generators/generated_attribute.rb32
-rw-r--r--railties/lib/rails/generators/rails/helper/helper_generator.rb5
-rw-r--r--railties/lib/rails/generators/test_unit/integration/integration_generator.rb6
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb5
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt8
-rw-r--r--railties/lib/rails/generators/test_unit/system/system_generator.rb5
-rw-r--r--railties/lib/rails/info.rb2
-rw-r--r--railties/lib/rails/info_controller.rb2
-rw-r--r--railties/lib/rails/mailers_controller.rb2
-rw-r--r--railties/lib/rails/templates/rails/welcome/index.html.erb2
14 files changed, 62 insertions, 26 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index f30e5d2a0f..22a82c051d 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "ipaddr"
require "active_support/core_ext/kernel/reporting"
require "active_support/file_update_checker"
require "rails/engine/configuration"
@@ -11,7 +12,7 @@ module Rails
attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
:cache_classes, :cache_store, :consider_all_requests_local, :console,
:eager_load, :exceptions_app, :file_watcher, :filter_parameters,
- :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
+ :force_ssl, :helpers_paths, :hosts, :logger, :log_formatter, :log_tags,
:railties_order, :relative_url_root, :secret_key_base, :secret_token,
:ssl_options, :public_file_server,
:session_options, :time_zone, :reload_classes_only_on_change,
@@ -29,6 +30,7 @@ module Rails
@filter_parameters = []
@filter_redirect = []
@helpers_paths = []
+ @hosts = Array(([IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0"), "localhost"] if Rails.env.development?))
@public_file_server = ActiveSupport::OrderedOptions.new
@public_file_server.enabled = true
@public_file_server.index_name = "index"
diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb
index 433a7ab41f..193cc59f3a 100644
--- a/railties/lib/rails/application/default_middleware_stack.rb
+++ b/railties/lib/rails/application/default_middleware_stack.rb
@@ -13,6 +13,8 @@ module Rails
def build_stack
ActionDispatch::MiddlewareStack.new do |middleware|
+ middleware.use ::ActionDispatch::HostAuthorization, config.hosts, config.action_dispatch.hosts_response_app
+
if config.force_ssl
middleware.use ::ActionDispatch::SSL, config.ssl_options
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 78d2471890..4646a55316 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -221,9 +221,11 @@ module Rails
# generate(:authenticated, "user session")
def generate(what, *args)
log :generate, what
+
+ options = args.extract_options!
argument = args.flat_map(&:to_s).join(" ")
- in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) }
+ execute_command :rails, "generate #{what} #{argument}", options
end
# Runs the supplied rake task (invoked with 'rake ...')
@@ -307,6 +309,7 @@ module Rails
config = { verbose: false }
config[:capture] = options[:capture] if options[:capture]
+ config[:abort_on_failure] = options[:abort_on_failure] if options[:abort_on_failure]
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
end
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 4dc4d27a46..f3b99ff937 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -364,7 +364,7 @@ module Rails
gems
end
- def bundle_command(command)
+ def bundle_command(command, env = {})
say_status :run, "bundle #{command}"
# We are going to shell out rather than invoking Bundler::CLI.new(command)
@@ -381,9 +381,9 @@ module Rails
Bundler.with_clean_env do
full_command = %Q["#{Gem.ruby}" "#{_bundle_command}" #{command}]
if options[:quiet]
- system(full_command, out: File::NULL)
+ system(env, full_command, out: File::NULL)
else
- system(full_command)
+ system(env, full_command)
end
end
end
@@ -417,7 +417,7 @@ module Rails
end
def run_bundle
- bundle_command("install") if bundle_install?
+ bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
end
def run_webpack
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb
index 3f20f5a718..a8f7729fd3 100644
--- a/railties/lib/rails/generators/generated_attribute.rb
+++ b/railties/lib/rails/generators/generated_attribute.rb
@@ -39,23 +39,23 @@ module Rails
private
- # parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
- # when declaring options curly brackets should be used
- def parse_type_and_options(type)
- case type
- when /(string|text|binary|integer)\{(\d+)\}/
- return $1, limit: $2.to_i
- when /decimal\{(\d+)[,.-](\d+)\}/
- return :decimal, precision: $1.to_i, scale: $2.to_i
- when /(references|belongs_to)\{(.+)\}/
- type = $1
- provided_options = $2.split(/[,.-]/)
- options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
- return type, options
- else
- return type, {}
+ # parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
+ # when declaring options curly brackets should be used
+ def parse_type_and_options(type)
+ case type
+ when /(string|text|binary|integer)\{(\d+)\}/
+ return $1, limit: $2.to_i
+ when /decimal\{(\d+)[,.-](\d+)\}/
+ return :decimal, precision: $1.to_i, scale: $2.to_i
+ when /(references|belongs_to)\{(.+)\}/
+ type = $1
+ provided_options = $2.split(/[,.-]/)
+ options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
+ return type, options
+ else
+ return type, {}
+ end
end
- end
end
def initialize(name, type = nil, index_type = false, attr_options = {})
diff --git a/railties/lib/rails/generators/rails/helper/helper_generator.rb b/railties/lib/rails/generators/rails/helper/helper_generator.rb
index 3837c10ca0..542eb4c9e8 100644
--- a/railties/lib/rails/generators/rails/helper/helper_generator.rb
+++ b/railties/lib/rails/generators/rails/helper/helper_generator.rb
@@ -10,6 +10,11 @@ module Rails
end
hook_for :test_framework
+
+ private
+ def file_name
+ @_file_name ||= super.sub(/_helper\z/i, "")
+ end
end
end
end
diff --git a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb
index ae307c5cd9..ba27ed329b 100644
--- a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb
+++ b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb
@@ -10,6 +10,12 @@ module TestUnit # :nodoc:
def create_test_files
template "integration_test.rb", File.join("test/integration", class_path, "#{file_name}_test.rb")
end
+
+ private
+
+ def file_name
+ @_file_name ||= super.sub(/_test\z/i, "")
+ end
end
end
end
diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
index e2e8b18eab..6df50c3217 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
@@ -54,6 +54,11 @@ module TestUnit # :nodoc:
end
end.sort.to_h
end
+
+ def boolean?(name)
+ attribute = attributes.find { |attr| attr.name == name }
+ attribute&.type == :boolean
+ end
end
end
end
diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt b/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt
index 15bd7956b6..4f5bbf1108 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt
+++ b/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt
@@ -16,8 +16,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
click_on "New <%= class_name.titleize %>"
<%- attributes_hash.each do |attr, value| -%>
+ <%- if boolean?(attr) -%>
+ check "<%= attr.humanize %>" if <%= value %>
+ <%- else -%>
fill_in "<%= attr.humanize %>", with: <%= value %>
<%- end -%>
+ <%- end -%>
click_on "Create <%= human_name %>"
assert_text "<%= human_name %> was successfully created"
@@ -29,8 +33,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
click_on "Edit", match: :first
<%- attributes_hash.each do |attr, value| -%>
+ <%- if boolean?(attr) -%>
+ check "<%= attr.humanize %>" if <%= value %>
+ <%- else -%>
fill_in "<%= attr.humanize %>", with: <%= value %>
<%- end -%>
+ <%- end -%>
click_on "Update <%= human_name %>"
assert_text "<%= human_name %> was successfully updated"
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 08504d4124..adecf74b70 100644
--- a/railties/lib/rails/generators/test_unit/system/system_generator.rb
+++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb
@@ -14,6 +14,11 @@ module TestUnit # :nodoc:
template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb")
end
+
+ private
+ def file_name
+ @_file_name ||= super.sub(/_test\z/i, "")
+ end
end
end
end
diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb
index b8173c8d11..c68405619d 100644
--- a/railties/lib/rails/info.rb
+++ b/railties/lib/rails/info.rb
@@ -67,7 +67,7 @@ module Rails
# The Ruby version and platform, e.g. "2.0.0-p247 (x86_64-darwin12.4.0)".
property "Ruby version" do
- "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
+ RUBY_DESCRIPTION
end
# The RubyGems version, if it's installed.
diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb
index 50fe176946..14459623ac 100644
--- a/railties/lib/rails/info_controller.rb
+++ b/railties/lib/rails/info_controller.rb
@@ -4,7 +4,7 @@ require "rails/application_controller"
require "action_dispatch/routing/inspector"
class Rails::InfoController < Rails::ApplicationController # :nodoc:
- prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
+ prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
layout -> { request.xhr? ? false : "application" }
before_action :require_local!
diff --git a/railties/lib/rails/mailers_controller.rb b/railties/lib/rails/mailers_controller.rb
index e2d36d7654..95dae3ec2d 100644
--- a/railties/lib/rails/mailers_controller.rb
+++ b/railties/lib/rails/mailers_controller.rb
@@ -3,7 +3,7 @@
require "rails/application_controller"
class Rails::MailersController < Rails::ApplicationController # :nodoc:
- prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
+ prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
before_action :require_local!, unless: :show_previews?
before_action :find_preview, :set_locale, only: :preview
diff --git a/railties/lib/rails/templates/rails/welcome/index.html.erb b/railties/lib/rails/templates/rails/welcome/index.html.erb
index b6823457c0..6750e01029 100644
--- a/railties/lib/rails/templates/rails/welcome/index.html.erb
+++ b/railties/lib/rails/templates/rails/welcome/index.html.erb
@@ -66,7 +66,7 @@
<p class="version">
<strong>Rails version:</strong> <%= Rails.version %><br />
- <strong>Ruby version:</strong> <%= RUBY_VERSION %> (<%= RUBY_PLATFORM %>)
+ <strong>Ruby version:</strong> <%= RUBY_DESCRIPTION %>
</p>
</section>
</div>