Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- Fix hardcode test; the strings change as we're using single quotes in the code now
- Move dev deps from gemspec to gemfile
- Disable some annoying linters
- Move to stub rather than just overwriting the whole function
- Fixes for queue_test.rb
  • Loading branch information
ukd1 committed Mar 22, 2024
1 parent 26a064d commit 7dfe5e6
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 91 deletions.
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AllCops:
NewCops: enable
TargetRubyVersion: 3.0
Layout/LineLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Naming/MethodParameterName:
Enabled: false
Metrics/AbcSize:
Enabled: false
Naming/VariableNumber:
Enabled: false
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ source 'https://rubygems.org' do

gemspec

group :development do
gem 'rubocop'
end

group :development, :test do
gem 'activerecord', '>= 5.0.0', '< 6.1'
end

group :test do
gem 'minitest', '~> 5.8'
gem 'minitest-reporters'
Expand Down
6 changes: 3 additions & 3 deletions lib/queue_classic/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def enqueue(method, *args)
# and args argument must be in the form described in the documentation for
# the #enqueue method.
# This method returns a hash with the id of the enqueued job.
def enqueue_at(timestamp, method, *args)
def enqueue_at(timestamp, method, *)
offset = Time.at(timestamp).to_i - Time.now.to_i
enqueue_in(offset, method, *args)
enqueue_in(offset, method, *)
end

# enqueue_in(t,m,a) inserts a row into the jobs table representing a job
Expand Down Expand Up @@ -105,7 +105,7 @@ def lock
RETURNING *
SQL

if r = conn_adapter.execute(s, name)
if (r = conn_adapter.execute(s, name))
{}.tap do |job|
job[:id] = r['id']
job[:q_name] = r['q_name']
Expand Down
1 change: 1 addition & 0 deletions lib/queue_classic/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rails/railtie'

module QC
# Railtie integrates queue_classic with Rails applications.
class Railtie < ::Rails::Railtie
rake_tasks do
load 'queue_classic/tasks.rb'
Expand Down
1 change: 1 addition & 0 deletions lib/queue_classic/setup.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module QC
# Setup is a module that provides methods to create, update and drop the queue_classic tables
module Setup
Root = File.expand_path('../..', File.dirname(__FILE__))
SqlFunctions = File.join(Root, '/sql/ddl.sql')
Expand Down
8 changes: 3 additions & 5 deletions lib/queue_classic/worker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# -*- coding: utf-8 -*-

require_relative 'queue'
require_relative 'conn_adapter'

Expand Down Expand Up @@ -92,11 +90,11 @@ def lock_job
job = nil
while @running
@queues.each do |queue|
if job = queue.lock
if (job = queue.lock)
return [queue, job]
end
end
@conn_adapter.wait(@wait_interval, *@queues.map { |q| q.name })
@conn_adapter.wait(@wait_interval, *@queues.map(&:name))
end
end

Expand Down Expand Up @@ -162,7 +160,7 @@ def log(data)
private

def setup_queues(adapter, queue, queues, top_bound)
names = queues.length > 0 ? queues : [queue]
names = queues.length.positive? ? queues : [queue]
names.map do |name|
QC::Queue.new(name, top_bound).tap do |q|
q.conn_adapter = adapter
Expand Down
8 changes: 4 additions & 4 deletions queue_classic.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'queue_classic/version'
Expand All @@ -14,17 +16,15 @@ Gem::Specification.new do |spec|

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = %w[lib]

spec.metadata = {
'bug_tracker_uri' => 'https://github.com/QueueClassic/queue_classic/issues',
'changelog_uri' => 'https://github.com/QueueClassic/queue_classic/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/QueueClassic/queue_classic'
'source_code_uri' => 'https://github.com/QueueClassic/queue_classic',
'rubygems_mfa_required' => 'true'
}

spec.required_ruby_version = '>= 3.0.0'
spec.add_runtime_dependency 'pg', '>= 1.1', '< 2.0'
spec.add_development_dependency 'activerecord', '>= 5.0.0', '< 6.1'
spec.add_development_dependency 'rubocop'
end
4 changes: 3 additions & 1 deletion test/hard_coding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def test_for_hard_coded_table_names
#
#
#
assert_equal `grep queue_classic_jobs lib -R`.split("\n").sort, ['lib/queue_classic/config.rb: @table_name ||= "queue_classic_jobs"', 'lib/queue_classic/setup.rb: conn.execute("DROP TABLE IF EXISTS queue_classic_jobs CASCADE")'].sort
assert_equal `grep queue_classic_jobs lib -R`.split("\n").sort,
['lib/queue_classic/config.rb: @table_name ||= \'queue_classic_jobs\'',
'lib/queue_classic/setup.rb: conn.execute(\'DROP TABLE IF EXISTS queue_classic_jobs CASCADE\')'].sort
end
end
6 changes: 3 additions & 3 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def capture_stderr_output
end

def capture_debug_output
original_debug = ENV['DEBUG']
original_debug = ENV.fetch('DEBUG', nil)
original_stdout = $stdout

ENV['DEBUG'] = 'true'
Expand All @@ -60,7 +60,7 @@ def capture_debug_output
def with_env(temporary_environment)
original_environment = {}
temporary_environment.each do |name, value|
original_environment[name] = ENV[name]
original_environment[name] = ENV.fetch(name, nil)
ENV[name] = value
end
yield
Expand All @@ -83,7 +83,7 @@ def stub_any_instance(class_name, method_name, definition)
else
message = "#{class_name} does not have method #{method_name}."
message << "\nAvailable methods: #{class_name.instance_methods(false)}"
raise ArgumentError.new message
raise ArgumentError, message
end
ensure
if method_present
Expand Down
6 changes: 3 additions & 3 deletions test/lib/queue_classic_rails_connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ def before_teardown
end

def test_uses_active_record_connection_if_exists
connection = get_connection
connection = test_connection
QC.default_conn_adapter.execute('SELECT 1;')
connection.verify
end

def test_does_not_use_active_record_connection_if_env_var_set
with_env 'QC_RAILS_DATABASE' => 'false' do
connection = get_connection
connection = test_connection
QC.default_conn_adapter.execute('SELECT 1;')
assert_raises(MockExpectationError) { connection.verify }
end
end

private

def get_connection
def test_connection
connection = Minitest::Mock.new
connection.expect(:raw_connection, QC::ConnAdapter.new(active_record_connection_share: true).connection)

Expand Down
Loading

0 comments on commit 7dfe5e6

Please sign in to comment.