Skip to content

Commit

Permalink
Fix almost all StandardRb offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
bquorning committed Oct 12, 2023
1 parent bb2db8f commit eb96d02
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 33 deletions.
15 changes: 0 additions & 15 deletions .standard_todo.yml
Expand Up @@ -2,26 +2,11 @@
# Remove from this list as you refactor files.
---
ignore:
- active_record_host_pool.gemspec:
- Layout/ExtraSpacing
- Gemspec/DeprecatedAttributeAssignment
- lib/active_record_host_pool/connection_adapter_mixin.rb:
- Style/EmptyMethod
- Style/SingleLineMethods
- Style/ArgumentsForwarding
- Layout/MultilineOperationIndentation
- lib/active_record_host_pool/connection_proxy.rb:
- Style/ArgumentsForwarding
- lib/active_record_host_pool/pool_proxy.rb:
- Style/ArgumentsForwarding
- Style/StringLiteralsInInterpolation
- test/helper.rb:
- Performance/StringIdentifierArgument
- Style/EvalWithLocation
- test/schema.rb:
- Layout/ExtraSpacing
- test/test_arhp_wrong_db.rb:
- Style/EvalWithLocation
- Lint/RescueException
- test/test_thread_safety.rb:
- Layout/SpaceInsideHashLiteralBraces
3 changes: 1 addition & 2 deletions active_record_host_pool.gemspec
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.name = "active_record_host_pool"
s.version = ActiveRecordHostPool::VERSION
s.authors = ["Benjamin Quorning", "Gabe Martin-Dempesy", "Pierre Schambacher", "Ben Osheroff"]
s.email = ["bquorning@zendesk.com", "gabe@zendesk.com", "pschambacher@zendesk.com"]
s.email = ["bquorning@zendesk.com", "gabe@zendesk.com", "pschambacher@zendesk.com"]
s.summary = "Allow ActiveRecord to share a connection to multiple databases on the same host"
s.description = ""
s.extra_rdoc_files = [
Expand All @@ -23,7 +23,6 @@ Gem::Specification.new do |s|
"lib/active_record_host_pool/version.rb"
]
s.homepage = "https://github.com/zendesk/active_record_host_pool"
s.test_files = ["test/database.yml", "test/helper.rb", "test/schema.rb", "test/test_arhp.rb"]
s.license = "MIT"

s.required_ruby_version = ">= 2.7.0"
Expand Down
8 changes: 4 additions & 4 deletions lib/active_record_host_pool/connection_adapter_mixin.rb
Expand Up @@ -76,10 +76,10 @@ def disconnect_with_host_pooling!

def _switch_connection
if _host_pool_current_database &&
(
(_host_pool_current_database != @_cached_current_database) ||
@connection.object_id != @_cached_connection_object_id
)
(
(_host_pool_current_database != @_cached_current_database) ||
@connection.object_id != @_cached_connection_object_id
)
log("select_db #{_host_pool_current_database}", "SQL") do
clear_cache!
raw_connection.select_db(_host_pool_current_database)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record_host_pool/pool_proxy.rb
Expand Up @@ -133,7 +133,7 @@ def _connection_pools

def _pool_key
@_pool_key ||= "#{@config[:host]}/#{@config[:port]}/#{@config[:socket]}/" \
"#{@config[:username]}/#{replica_configuration? && 'replica'}"
"#{@config[:username]}/#{replica_configuration? && "replica"}"
end

def _connection_pool(auto_create = true)
Expand Down
6 changes: 3 additions & 3 deletions test/helper.rb
Expand Up @@ -44,10 +44,10 @@ module ARHPTestSetup
private

def arhp_create_models
return if ARHPTestSetup.const_defined?("Pool1DbA")
return if ARHPTestSetup.const_defined?(:Pool1DbA)

if ActiveRecord::Base.legacy_connection_handling
eval <<-RUBY
eval(<<-RUBY, binding, __FILE__, __LINE__ + 1)
# The placement of the Pool1DbC class is important so that its
# connection will not be the most recent connection established
# for test_pool_1.
Expand Down Expand Up @@ -86,7 +86,7 @@ class Pool3DbE < ActiveRecord::Base
end
RUBY
else
eval <<-RUBY
eval(<<-RUBY, binding, __FILE__, __LINE__ + 1)
class AbstractPool1DbC < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :test_pool_1_db_c }
Expand Down
2 changes: 1 addition & 1 deletion test/schema.rb
Expand Up @@ -7,7 +7,7 @@

ActiveRecord::Schema.define(version: 1) do
create_table "tests", force: true do |t|
t.string "val"
t.string "val"
end

# Add a table only the shard database will have. Conditional
Expand Down
6 changes: 3 additions & 3 deletions test/test_arhp_wrong_db.rb
Expand Up @@ -24,13 +24,13 @@ def test_connecting_to_wrong_db_first
reached_second_exception = false

begin
eval <<-RUBY
eval(<<-RUBY, binding, __FILE__, __LINE__ + 1)
class TestNotThere < ActiveRecord::Base
establish_connection(:test_pool_1_db_not_there)
connection
end
RUBY
rescue Exception => e
rescue => e
assert_match(/(Unknown database|We could not find your database:) '?arhp_test_db_not_there/, e.message)
reached_first_exception = true
end
Expand All @@ -41,7 +41,7 @@ class TestNotThere < ActiveRecord::Base

begin
TestNotThere.connection
rescue Exception => e
rescue => e
# If the pool is caching a bad connection, that connection will be used instead
# of the intended connection.
refute_match(/(Unknown database|We could not find your database:) '?arhp_test_db_not_there/, e.message)
Expand Down
8 changes: 4 additions & 4 deletions test/test_thread_safety.rb
Expand Up @@ -70,12 +70,12 @@ def test_threads_can_query_in_parallel
short_sleep = 0.1

even_threads_do_this = [
{ method: method(:assert_query_host_1_db_a), db_sleep_time: long_sleep },
{ method: method(:assert_query_host_1_db_b), db_sleep_time: short_sleep }
{method: method(:assert_query_host_1_db_a), db_sleep_time: long_sleep},
{method: method(:assert_query_host_1_db_b), db_sleep_time: short_sleep}
]
odd_threads_do_this = [
{ method: method(:assert_query_host_1_db_b), db_sleep_time: short_sleep },
{ method: method(:assert_query_host_1_db_a), db_sleep_time: long_sleep }
{method: method(:assert_query_host_1_db_b), db_sleep_time: short_sleep},
{method: method(:assert_query_host_1_db_a), db_sleep_time: long_sleep}
]

threads = 4.times.map do |n|
Expand Down

0 comments on commit eb96d02

Please sign in to comment.