aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb1
-rw-r--r--actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb2
-rw-r--r--actionview/CHANGELOG.md4
-rw-r--r--actionview/lib/action_view.rb1
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/connection_adapters/schema_cache.rb13
-rw-r--r--activerecord/lib/active_record/errors.rb4
-rw-r--r--activerecord/lib/active_record/model_schema.rb3
-rw-r--r--activerecord/test/cases/base_test.rb8
-rw-r--r--guides/source/initialization.md2
-rw-r--r--railties/CHANGELOG.md2
-rw-r--r--railties/lib/rails/commands/server/server_command.rb11
-rw-r--r--railties/test/commands/server_test.rb23
13 files changed, 64 insertions, 14 deletions
diff --git a/actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb b/actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb
index d051dfe665..8713f545f5 100644
--- a/actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb
+++ b/actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb
@@ -21,6 +21,7 @@ module Rails
private
def new_mail
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h).tap do |mail|
+ mail[:bcc]&.include_in_headers = true
params[:mail][:attachments].to_a.each do |attachment|
mail.add_file(filename: attachment.path, content: attachment.read)
end
diff --git a/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb b/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
index fcd9ad839f..1b8ca7bd5e 100644
--- a/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
+++ b/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
@@ -10,6 +10,7 @@ class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispa
mail: {
from: "Jason Fried <jason@37signals.com>",
to: "Replies <replies@example.com>",
+ bcc: "Bcc <bcc@example.com>",
in_reply_to: "<4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>",
subject: "Hey there",
body: "How's it going?"
@@ -20,6 +21,7 @@ class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispa
mail = ActionMailbox::InboundEmail.last.mail
assert_equal %w[ jason@37signals.com ], mail.from
assert_equal %w[ replies@example.com ], mail.to
+ assert_equal %w[ bcc@example.com ], mail.bcc
assert_equal "4e6e35f5a38b4_479f13bb90078178@small-app-01.mail", mail.in_reply_to
assert_equal "Hey there", mail.subject
assert_equal "How's it going?", mail.body.decoded
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index c663ec3bbc..f2f57e6a36 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add autoload for SyntaxErrorInTemplate so syntax errors are correctly raised by DebugExceptions.
+
+ *Guilherme Mansur*, *Gannon McGibbon*
+
* `RenderingHelper` supports rendering objects that `respond_to?` `:render_in`
*Joel Hawksley*, *Natasha Umer*, *Aaron Patterson*, *Shawn Allen*, *Emily Plummer*, *Diana Mounter*, *John Hawthorn*, *Nathan Herald*, *Zaid Zawaideh*, *Zach Ahn*
diff --git a/actionview/lib/action_view.rb b/actionview/lib/action_view.rb
index 7f85bf2a5e..11b4563548 100644
--- a/actionview/lib/action_view.rb
+++ b/actionview/lib/action_view.rb
@@ -77,6 +77,7 @@ module ActionView
autoload :ActionViewError
autoload :EncodingError
autoload :TemplateError
+ autoload :SyntaxErrorInTemplate
autoload :WrongEncodingError
end
end
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 8d4b01e995..8642227a2b 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
+
+ *Guilherme Mansur*, *Eugene Kenny*
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
Fixes #36022.
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
index 218d6c168a..5da26171bb 100644
--- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -27,7 +27,6 @@ module ActiveRecord
def encode_with(coder)
coder["columns"] = @columns
- coder["columns_hash"] = @columns_hash
coder["primary_keys"] = @primary_keys
coder["data_sources"] = @data_sources
coder["indexes"] = @indexes
@@ -37,7 +36,7 @@ module ActiveRecord
def init_with(coder)
@columns = coder["columns"]
- @columns_hash = coder["columns_hash"]
+ @columns_hash = {}
@primary_keys = coder["primary_keys"]
@data_sources = coder["data_sources"]
@indexes = coder["indexes"] || {}
@@ -79,9 +78,7 @@ module ActiveRecord
# Get the columns for a table as a hash, key is the column name
# value is the column object.
def columns_hash(table_name)
- @columns_hash[table_name] ||= Hash[columns(table_name).map { |col|
- [col.name, col]
- }]
+ @columns_hash[table_name] ||= columns(table_name).index_by(&:name)
end
# Checks whether the columns hash is already cached for a table.
@@ -124,15 +121,15 @@ module ActiveRecord
def marshal_dump
# if we get current version during initialization, it happens stack over flow.
@version = connection.migration_context.current_version
- [@version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes, database_version]
+ [@version, @columns, {}, @primary_keys, @data_sources, @indexes, database_version]
end
def marshal_load(array)
- @version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes, @database_version = array
+ @version, @columns, _columns_hash, @primary_keys, @data_sources, @indexes, @database_version = array
@indexes ||= {}
+ @columns_hash = {}
@columns = deep_deduplicate(@columns)
- @columns_hash = deep_deduplicate(@columns_hash)
@primary_keys = deep_deduplicate(@primary_keys)
@data_sources = deep_deduplicate(@data_sources)
@indexes = deep_deduplicate(@indexes)
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index 60cf9818c1..c8c06375a3 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -38,6 +38,10 @@ module ActiveRecord
class AdapterNotSpecified < ActiveRecordError
end
+ # Raised when a model makes a query but it has not specified an associated table.
+ class TableNotSpecified < ActiveRecordError
+ end
+
# Raised when Active Record cannot find database adapter specified in
# +config/database.yml+ or programmatically.
class AdapterNotFound < ActiveRecordError
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index 2a45f63d64..18f19af6be 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -482,6 +482,9 @@ module ActiveRecord
end
def load_schema!
+ unless table_name
+ raise ActiveRecord::TableNotSpecified, "#{self} has no table configured. Set one with #{self}.table_name="
+ end
@columns_hash = connection.schema_cache.columns_hash(table_name).except(*ignored_columns)
@columns_hash.each do |name, column|
define_attribute(
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 983a46a2d0..1324bdf9b8 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1415,6 +1415,14 @@ class BasicsTest < ActiveRecord::TestCase
assert_not_includes SymbolIgnoredDeveloper.columns_hash.keys, "first_name"
end
+ test ".columns_hash raises an error if the record has an empty table name" do
+ expected_message = "FirstAbstractClass has no table configured. Set one with FirstAbstractClass.table_name="
+ exception = assert_raises(ActiveRecord::TableNotSpecified) do
+ FirstAbstractClass.columns_hash
+ end
+ assert_equal expected_message, exception.message
+ end
+
test "ignored columns have no attribute methods" do
assert_not_respond_to Developer.new, :first_name
assert_not_respond_to Developer.new, :first_name=
diff --git a/guides/source/initialization.md b/guides/source/initialization.md
index 817c6b17bc..c19b2cffc5 100644
--- a/guides/source/initialization.md
+++ b/guides/source/initialization.md
@@ -289,7 +289,7 @@ def default_options
environment: (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup,
daemonize: false,
caching: nil,
- pid: Options::DEFAULT_PID_PATH,
+ pid: ENV.fetch("PIDFILE", Options::DEFAULT_PIDFILE).dup,
restart_cmd: restart_command)
end
```
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 7bc7391f9e..cfb30719da 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,5 @@
+* Support using environment variable to set pidfile
+ *Ben Thorner*
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/railties/CHANGELOG.md) for previous changes.
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index 982b83ead5..84248e03c1 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -99,7 +99,7 @@ module Rails
RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn)
DEFAULT_PORT = 3000
- DEFAULT_PID_PATH = "tmp/pids/server.pid"
+ DEFAULT_PIDFILE = "tmp/pids/server.pid"
argument :using, optional: true
@@ -114,8 +114,8 @@ module Rails
desc: "Runs server as a Daemon."
class_option :using, aliases: "-u", type: :string,
desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
- class_option :pid, aliases: "-P", type: :string, default: DEFAULT_PID_PATH,
- desc: "Specifies the PID file."
+ class_option :pid, aliases: "-P", type: :string,
+ desc: "Specifies the PID file - defaults to #{DEFAULT_PIDFILE}."
class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
desc: "Specifies whether to perform caching in development."
class_option :restart, type: :boolean, default: nil, hide: true
@@ -207,6 +207,7 @@ module Rails
end
user_supplied_options << :Host if ENV["HOST"] || ENV["BINDING"]
user_supplied_options << :Port if ENV["PORT"]
+ user_supplied_options << :pid if ENV["PIDFILE"]
user_supplied_options.uniq
end
end
@@ -253,7 +254,7 @@ module Rails
end
def pid
- File.expand_path(options[:pid])
+ File.expand_path(options[:pid] || ENV.fetch("PIDFILE", DEFAULT_PIDFILE))
end
def self.banner(*)
@@ -261,7 +262,7 @@ module Rails
end
def prepare_restart
- FileUtils.rm_f(options[:pid]) if options[:restart]
+ FileUtils.rm_f(pid) if options[:restart]
end
def deprecate_positional_rack_server_and_rewrite_to_option(original_options)
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index b78370a233..c9026e2d95 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -116,6 +116,13 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
end
end
+ def test_environment_with_pidfile
+ switch_env "PIDFILE", "/tmp/rails.pid" do
+ options = parse_arguments
+ assert_equal "/tmp/rails.pid", options[:pid]
+ end
+ end
+
def test_caching_without_option
args = []
options = parse_arguments(args)
@@ -234,6 +241,12 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
options = parse_arguments(args)
assert_equal "127.0.0.1", options[:Host]
end
+
+ switch_env "PIDFILE", "/tmp/rails.pid" do
+ args = ["-P", "/somewhere/else.pid"]
+ options = parse_arguments(args)
+ assert_equal "/somewhere/else.pid", options[:pid]
+ end
end
def test_records_user_supplied_options
@@ -253,6 +266,16 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
server_options = parse_arguments
assert_equal [:Host], server_options[:user_supplied_options]
end
+
+ switch_env "PORT", "3001" do
+ server_options = parse_arguments
+ assert_equal [:Port], server_options[:user_supplied_options]
+ end
+
+ switch_env "PIDFILE", "/tmp/server.pid" do
+ server_options = parse_arguments
+ assert_equal [:pid], server_options[:user_supplied_options]
+ end
end
def test_default_options