Skip to content

Commit

Permalink
Merge branch 'main' into flavorjones-rubocop-percent-x-command-literals
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed May 6, 2024
2 parents 8c313a3 + 9ad3685 commit 9b952c8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ def build_statement_pool
#
# This is an internal hook to make possible connection adapters to build
# custom result objects with connection-specific data.
def build_result(columns:, rows:, column_types: {})
def build_result(columns:, rows:, column_types: nil)
ActiveRecord::Result.new(columns, rows, column_types)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: fa
fmod = result.fmod i
types[fname] = types[i] = get_oid_type(ftype, fmod, fname)
end
build_result(columns: fields, rows: result.values, column_types: types)
build_result(columns: fields, rows: result.values, column_types: types.freeze)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,9 @@ def initialize(...)
dirname = File.dirname(@config[:database])
unless File.directory?(dirname)
begin
Dir.mkdir(dirname)
rescue Errno::ENOENT => error
if error.message.include?("No such file or directory")
raise ActiveRecord::NoDatabaseError.new(connection_pool: @pool)
else
raise
end
FileUtils.mkdir_p(dirname)
rescue SystemCallError
raise ActiveRecord::NoDatabaseError.new(connection_pool: @pool)
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions activerecord/lib/active_record/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def self.empty(async: false) # :nodoc:
end
end

def initialize(columns, rows, column_types = {})
def initialize(columns, rows, column_types = nil)
@columns = columns
@rows = rows
@hash_rows = nil
@column_types = column_types
@column_types = column_types || EMPTY_HASH
end

# Returns true if this result set includes the column named +name+
Expand Down Expand Up @@ -192,7 +192,11 @@ def hash_rows
end
end

EMPTY = new([].freeze, [].freeze, {}.freeze).freeze
empty_array = [].freeze
EMPTY_HASH = {}.freeze
private_constant :EMPTY_HASH

EMPTY = new(empty_array, empty_array, EMPTY_HASH).freeze
private_constant :EMPTY

EMPTY_ASYNC = FutureResult.wrap(EMPTY).freeze
Expand Down
10 changes: 6 additions & 4 deletions activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def setup
)
end

def test_bad_connection
error = assert_raise ActiveRecord::NoDatabaseError do
connection = SQLite3Adapter.new(adapter: "sqlite3", database: "/tmp/should/_not/_exist/-cinco-dog.db")
def test_database_should_get_created_when_missing_parent_directories_for_database_path
dir = Dir.mktmpdir
db_path = File.join(dir, "_not_exist/-cinco-dog.sqlite3")
assert_nothing_raised do
connection = SQLite3Adapter.new(adapter: "sqlite3", database: db_path)
connection.drop_table "ex", if_exists: true
end
assert_kind_of ActiveRecord::ConnectionAdapters::NullPool, error.connection_pool
assert SQLite3Adapter.database_exists?(adapter: "sqlite3", database: db_path)
end

def test_database_exists_returns_false_when_the_database_does_not_exist
Expand Down
5 changes: 2 additions & 3 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,13 @@ def enable_reloading=(value)
end

def read_encrypted_secrets
Rails.deprecator.warn(%x(config.read_encrypted_secrets is deprecated and will be removed in Rails 7.3.))
Rails.deprecator.warn("'config.read_encrypted_secrets' is deprecated and will be removed in Rails 7.3.")
end

def read_encrypted_secrets=(value)
Rails.deprecator.warn(%x(config.read_encrypted_secrets is deprecated and will be removed in Rails 7.3.))
Rails.deprecator.warn("'config.read_encrypted_secrets=' is deprecated and will be removed in Rails 7.3.")
end


def encoding=(value)
@encoding = value
silence_warnings do
Expand Down
12 changes: 6 additions & 6 deletions railties/test/application/console_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def teardown
teardown_app
end

def write_prompt(command, expected_output = nil)
def write_prompt(command, expected_output = nil, prompt: "> ")
@primary.puts command
assert_output command, @primary
assert_output expected_output, @primary, 100 if expected_output
assert_output "> ", @primary
assert_output prompt, @primary
end

def spawn_console(options, wait_for_prompt: true, env: {})
Expand Down Expand Up @@ -123,21 +123,21 @@ def test_production_console_prompt
options = "-e production"
spawn_console(options)

write_prompt "123", "app-template(prod)> 123"
write_prompt "123", prompt: "app-template(prod)>"
end

def test_development_console_prompt
options = "-e development"
spawn_console(options)

write_prompt "123", "app-template(dev)> 123"
write_prompt "123", prompt: "app-template(dev)> "
end

def test_test_console_prompt
options = "-e test"
spawn_console(options)

write_prompt "123", "app-template(test)> 123"
write_prompt "123", prompt: "app-template(test)> "
end

def test_helper_helper_method
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_console_respects_user_defined_prompt_mode
options = "-e test"
spawn_console(options, env: { "IRBRC" => irbrc.path })

write_prompt "123", ">> 123"
write_prompt "123", prompt: ">> "
ensure
File.unlink(irbrc)
end
Expand Down

0 comments on commit 9b952c8

Please sign in to comment.