Skip to content

Commit

Permalink
Minor adjustments (#268)
Browse files Browse the repository at this point in the history
* Minor fixes to make the tests in the rails app work

* Improve rubocop linting
  • Loading branch information
mhenrixon authored Jun 6, 2018
1 parent 43f6070 commit f8d41f2
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ rails_example/spec/examples.txt
/sidekiq/

/spec/examples.txt

/gemfiles/.bundle/
8 changes: 4 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
AllCops:
Include:
- '**/Rakefile'
- '**/lib'
- '**/bin'
- '**/spec'
- 'lib/**/*.rb'
- 'bin/**/*.rb'
- 'spec/**/*.rb'
Exclude:
- 'Gemfile.lock'
- 'gemfiles/**/*'
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5

Lint/HandleExceptions:
Enabled: true
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_script:
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- if [[ "${STYLE}" = "true" ]]; then bundle exec rubocop - P; fi;
- if [[ "${STYLE}" = "true" ]]; then bundle exec rubocop -P; fi;
- bundle exec rspec spec
- if [[ "${STYLE}" = "true" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi;

Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def current_time
begin
instant = SidekiqUniqueJobs.connection(@redis_pool, &:time)
Time.at(instant[0], instant[1])
rescue
rescue StandardError
@use_local_time = true
current_time
end
Expand Down
1 change: 1 addition & 0 deletions lib/sidekiq_unique_jobs/unique_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ def unique_args_method
@unique_args_method ||= Sidekiq.default_worker_options.stringify_keys[UNIQUE_ARGS_KEY]
end
end
# rubocop:enable ClassLength
end
2 changes: 1 addition & 1 deletion rails_example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

group :development, :test do
gem 'dockerspec'
gem 'factory_girl_rails'
gem 'factory_bot_rails'
gem 'fuubar'
gem 'mock_redis'
gem 'rspec-rails'
Expand Down
3 changes: 0 additions & 3 deletions rails_example/config/initializers/new_framework_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@

# Require `belongs_to` associations by default. Previous versions had false.
Rails.application.config.active_record.belongs_to_required_by_default = false

# Do not halt callback chains when a callback returns false. Previous versions had true.
ActiveSupport.halt_callback_chains_on_return_false = true
22 changes: 11 additions & 11 deletions rails_example/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -12,16 +10,18 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20_160_724_111_322) do
ActiveRecord::Schema.define(version: 2016_07_24_111322) do

# These are extensions that must be enabled in order to support this database
enable_extension 'plpgsql'
enable_extension "plpgsql"

create_table 'posts', force: :cascade do |t|
t.string 'title'
t.text 'body'
t.string 'excerpt'
t.integer 'read_count'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
create_table "posts", id: :serial, force: :cascade do |t|
t.string "title"
t.text "body"
t.string "excerpt"
t.integer "read_count"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
get :duplicate_simple, params: { id: 11 }
Sidekiq.redis do |conn|
expect(conn.keys).to match_array(expected_keys)
expect(conn.keys.size).to eq(3)
expect(conn.llen('queue:default')).to eq(0)
end
end
Expand Down
2 changes: 1 addition & 1 deletion rails_example/spec/factories/posts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

FactoryGirl.define do
FactoryBot.define do
factory :post do
title 'MyString'
body 'MyText'
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/main_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ class MainJob
sidekiq_options queue: :customqueue, unique: :until_executed,
log_duplicate_payload: true

def perform(_); end
def perform(_arg); end
end
2 changes: 1 addition & 1 deletion spec/jobs/notify_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class NotifyWorker
sidekiq_options queue: :notify_worker,
unique: :until_executed

def perform(id, _blob)
def perform(_id, _blob)
# puts "NotifyWorker -- #{id}"
end
end
4 changes: 2 additions & 2 deletions spec/jobs/until_global_timeout_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class UntilGlobalTimeoutJob
include Sidekiq::Worker
sidekiq_options unique: :until_timeout

def perform(x)
TestClass.run(x)
def perform(arg)
TestClass.run(arg)
end
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new" # rubocop:disable Security/Eval
eval("$#{stream} = StringIO.new") # rubocop:disable Security/Eval, Style/EvalWithLocation
yield
result = eval("$#{stream}").string # rubocop:disable Security/Eval
result = eval("$#{stream}").string # rubocop:disable Security/Eval, Style/EvalWithLocation
ensure
eval("$#{stream} = #{stream.upcase}") # rubocop:disable Security/Eval
eval("$#{stream} = #{stream.upcase}") # rubocop:disable Security/Eval, Style/EvalWithLocation
end

result
Expand Down
24 changes: 12 additions & 12 deletions spec/unit/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
describe '#help' do
let(:output) { capture(:stdout) { described_class.start(%w[help]) } }
let(:banner) do
<<~EOS
<<~HEADER
Commands:
jobs console # drop into a console with easy access to helper methods
jobs del PATTERN # deletes unique keys from redis by pattern
jobs help [COMMAND] # Describe available commands or one specific command
jobs keys PATTERN # list all unique keys and their expiry time
EOS
HEADER
end

it 'displays help' do
Expand All @@ -24,7 +24,7 @@
describe '#help del' do
let(:output) { capture(:stdout) { described_class.start(%w[help del]) } }
let(:banner) do
<<~EOS
<<~HEADER
Usage:
jobs del PATTERN
Expand All @@ -34,7 +34,7 @@
# Default: 1000
deletes unique keys from redis by pattern
EOS
HEADER
end

it 'displays help about the `del` command' do
Expand All @@ -45,7 +45,7 @@
describe '#help keys' do
let(:output) { capture(:stdout) { described_class.start(%w[help keys]) } }
let(:banner) do
<<~EOS
<<~HEADER
Usage:
jobs keys PATTERN
Expand All @@ -54,7 +54,7 @@
# Default: 1000
list all unique keys and their expiry time
EOS
HEADER
end

it 'displays help about the `key` command' do
Expand Down Expand Up @@ -90,10 +90,10 @@
after { SidekiqUniqueJobs::Util.del('*', 1000, false) }

let(:expected) do
<<~EOS
<<~HEADER
Found 2 keys matching '#{pattern}':
uniquejobs:abcdefab:EXISTS uniquejobs:abcdefab:GRABBED
EOS
HEADER
end
specify do
expect(output).to eq(expected)
Expand All @@ -103,9 +103,9 @@

describe '.del' do
let(:expected) do
<<~EOS
<<~HEADER
Deleted 2 keys matching '*'
EOS
HEADER
end

before do
Expand All @@ -121,11 +121,11 @@

describe '.console', ruby_ver: '>= 2.5.1' do
let(:expected) do
<<~EOS
<<~HEADER
Use `keys '*', 1000 to display the first 1000 unique keys matching '*'
Use `del '*', 1000, true (default) to see how many keys would be deleted for the pattern '*'
Use `del '*', 1000, false to delete the first 1000 keys matching '*'
EOS
HEADER
end
let(:output) { capture(:stdout) { described_class.start(%w[console]) } }

Expand Down

0 comments on commit f8d41f2

Please sign in to comment.