Skip to content

Commit c2bc038

Browse files
committed
Added test for the missing ::Async::Reactor.run.
1 parent 0720377 commit c2bc038

File tree

13 files changed

+29
-37
lines changed

13 files changed

+29
-37
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
AllCops:
22
SuggestExtensions: false
33
TargetRubyVersion: 2.6
4+
NewCops: enable
45

56
Metrics:
67
Enabled: false

.rubocop_todo.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-03-02 20:56:34 UTC using RuboCop version 1.47.0.
3+
# on 2023-07-26 19:57:49 UTC using RuboCop version 1.47.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -77,16 +77,6 @@ Style/GlobalStdStream:
7777
- 'spec/database_adapters/activerecord/activerecord.rb'
7878
- 'tasks/db.rake'
7979

80-
# Offense count: 18
81-
# This cop supports safe autocorrection (--autocorrect).
82-
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
83-
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
84-
# SupportedShorthandSyntax: always, never, either, consistent
85-
Style/HashSyntax:
86-
Exclude:
87-
- 'lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb'
88-
- 'lib/slack-ruby-bot-server/models/team/methods.rb'
89-
9080
# Offense count: 1
9181
# This cop supports unsafe autocorrection (--autocorrect-all).
9282
Style/HashTransformKeys:
@@ -99,6 +89,12 @@ Style/HashTransformValues:
9989
Exclude:
10090
- 'lib/slack-ruby-bot-server/api/helpers/error_helpers.rb'
10191

92+
# Offense count: 2
93+
# This cop supports unsafe autocorrection (--autocorrect-all).
94+
Style/MapToHash:
95+
Exclude:
96+
- 'spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb'
97+
10298
# Offense count: 1
10399
# This cop supports unsafe autocorrection (--autocorrect-all).
104100
# Configuration parameters: EnforcedStyle, Autocorrect.

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
case ENV['DATABASE_ADAPTER']
3+
case ENV.fetch('DATABASE_ADAPTER', nil)
44
when 'mongoid' then
55
gem 'kaminari-mongoid'
66
gem 'mongoid', ENV['MONGOID_VERSION'] || '~> 7.3.0'
@@ -14,7 +14,7 @@ when 'activerecord' then
1414
when nil
1515
warn "Missing ENV['DATABASE_ADAPTER']."
1616
else
17-
warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}."
17+
warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV.fetch('DATABASE_ADAPTER', nil)}."
1818
end
1919

2020
gemspec

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'rspec/core'
55
require 'rspec/core/rake_task'
66

77
RSpec::Core::RakeTask.new(:spec) do |spec|
8-
spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV['DATABASE_ADAPTER']})})
8+
spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV.fetch('DATABASE_ADAPTER', nil)})})
99
end
1010

1111
require 'rubocop/rake_task'

lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class TeamsEndpoint < Grape::API
4141
raise 'Missing SLACK_CLIENT_ID or SLACK_CLIENT_SECRET.' unless ENV.key?('SLACK_CLIENT_ID') && ENV.key?('SLACK_CLIENT_SECRET')
4242

4343
options = {
44-
client_id: ENV['SLACK_CLIENT_ID'],
45-
client_secret: ENV['SLACK_CLIENT_SECRET'],
44+
client_id: ENV.fetch('SLACK_CLIENT_ID', nil),
45+
client_secret: ENV.fetch('SLACK_CLIENT_SECRET', nil),
4646
code: params[:code]
4747
}
4848

lib/slack-ruby-bot-server/api/middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rack/cors'
22
require 'rack-rewrite'
33
require 'rack-server-pages'
4-
require 'otr-activerecord' if SlackRubyBotServer::Config.activerecord? && !defined?(::Rails)
4+
require 'otr-activerecord' if SlackRubyBotServer::Config.activerecord? && !defined?(Rails)
55

66
module SlackRubyBotServer
77
module Api

lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def self.init!
3333
end
3434
end
3535

36-
::Boolean = Grape::API::Boolean
36+
Boolean = Grape::API::Boolean

lib/slack-ruby-bot-server/service.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def start_from_database!
7878
start_intervals!
7979
end
8080

81-
def start_intervals!
82-
::Async::Reactor.run do
81+
def start_intervals!(&_block)
82+
::Async::Reactor.run do |task|
8383
@intervals.each_pair do |period, calls_with_options|
8484
calls_with_options.each do |call_with_options|
8585
call, options = *call_with_options
@@ -88,6 +88,7 @@ def start_intervals!
8888
end
8989
end
9090
end
91+
yield task if block_given?
9192
end
9293
end
9394

slack-ruby-bot-server.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
2424
spec.add_dependency 'rack-rewrite'
2525
spec.add_dependency 'rack-server-pages'
2626
spec.add_dependency 'slack-ruby-client'
27+
spec.metadata['rubygems_mfa_required'] = 'true'
2728
end

spec/database_adapters/activerecord/activerecord.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
yml = ERB.new(File.read(File.expand_path('config/postgresql.yml', __dir__))).result
22
db_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
3-
::YAML.safe_load(yml, aliases: true)[ENV['RACK_ENV']]
3+
YAML.safe_load(yml, aliases: true)[ENV.fetch('RACK_ENV', nil)]
44
else
5-
::YAML.safe_load(yml, [], [], true)[ENV['RACK_ENV']]
5+
YAML.safe_load(yml, [], [], true)[ENV.fetch('RACK_ENV', nil)]
66
end
77
ActiveRecord::Tasks::DatabaseTasks.create(db_config)
88
ActiveRecord::Base.establish_connection(db_config)

0 commit comments

Comments
 (0)