spec/sidekiq/merger/merge_spec.rb in sidekiq-merger-0.0.9 vs spec/sidekiq/merger/merge_spec.rb in sidekiq-merger-0.0.10
- old
+ new
@@ -1,30 +1,15 @@
require "spec_helper"
-describe Sidekiq::Merger::Merge do
+describe Sidekiq::Merger::Merge, worker_class: true do
subject { described_class.new(worker_class, queue, args, redis: redis) }
let(:args) { "foo" }
let(:redis) { Sidekiq::Merger::Redis.new }
let(:queue) { "queue" }
let(:now) { Time.now }
let(:execution_time) { now + 10.seconds }
- let(:options) { { key: -> (args) { args.to_json } } }
- let(:worker_class) do
- local_options = options
- Class.new do
- include Sidekiq::Worker
-
- sidekiq_options merger: local_options
-
- def self.name
- "name"
- end
-
- def perform(args)
- end
- end
- end
+ let(:worker_options) { { key: -> (args) { args.to_json } } }
before { Timecop.freeze(now) }
describe ".all" do
it "returns all the keys" do
redis.redis do |conn|
@@ -62,50 +47,50 @@
end
end
describe ".merge_key" do
let(:args) { "foo" }
- let(:options) { {} }
+ let(:worker_options) { {} }
it "returns an empty string" do
expect(described_class.merge_key(worker_class, args)).to eq ""
end
context "string key" do
- let(:options) { { key: "bar" } }
+ let(:worker_options) { { key: "bar" } }
it "returns the string" do
expect(described_class.merge_key(worker_class, args)).to eq "bar"
end
end
context "other type key" do
- let(:options) { { key: [1, 2, 3] } }
+ let(:worker_options) { { key: [1, 2, 3] } }
it "returns nil" do
expect(described_class.merge_key(worker_class, args)).to eq "[1,2,3]"
end
end
context "proc key" do
let(:args) { [1, 2, 3] }
- let(:options) { { key: -> (args) { args[0].to_s } } }
+ let(:worker_options) { { key: -> (args) { args[0].to_s } } }
it "returns the result of the proc" do
expect(described_class.merge_key(worker_class, args)).to eq "1"
end
context "non-string result" do
- let(:options) { { key: -> (args) { args[0] } } }
+ let(:worker_options) { { key: -> (args) { args[0] } } }
it "returns nil" do
expect(described_class.merge_key(worker_class, args)).to eq "1"
end
end
end
end
describe "#add" do
it "adds the args in lazy merge" do
- expect(redis).to receive(:push_message).with("name:queue:foo", [1, 2, 3], execution_time)
+ expect(redis).to receive(:push_message).with("some_worker:queue:foo", [1, 2, 3], execution_time)
subject.add([1, 2, 3], execution_time)
end
context "with unique option" do
- let(:options) { { key: -> (args) { args.to_json }, unique: true } }
+ let(:worker_options) { { key: -> (args) { args.to_json }, unique: true } }
it "adds the args in lazy merge" do
- expect(redis).to receive(:push_message).with("name:queue:foo", [1, 2, 3], execution_time)
+ expect(redis).to receive(:push_message).with("some_worker:queue:foo", [1, 2, 3], execution_time)
subject.add([1, 2, 3], execution_time)
end
context "the args has alredy been added" do
before { subject.add([1, 2, 3], execution_time) }
it "adds the args in lazy merge" do
@@ -116,11 +101,11 @@
end
end
describe "#delete" do
it "adds the args in lazy merge" do
- expect(redis).to receive(:delete_message).with("name:queue:foo", [1, 2, 3])
+ expect(redis).to receive(:delete_message).with("some_worker:queue:foo", [1, 2, 3])
subject.delete([1, 2, 3])
end
end
describe "#delete_all" do
@@ -193,9 +178,9 @@
end
end
describe "#full_merge_key" do
it "returns full merge key" do
- expect(subject.full_merge_key).to eq "name:queue:foo"
+ expect(subject.full_merge_key).to eq "some_worker:queue:foo"
end
end
end