sidekiq-merger 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60636bc150095c22b100fdbbeeb75dd9e9ed77de
4
- data.tar.gz: 8a889756673e47f928c96204210a57ee39ec8e5f
3
+ metadata.gz: 7acc8bcc7c43fe634d4be54f9a4ce5c09135da27
4
+ data.tar.gz: ae19824415ac8fe3a38cd876977334f7e41ffaa2
5
5
  SHA512:
6
- metadata.gz: 7a166d4979d485fcf98b962859f1f550b1e9966f2243de3d1ba51f82e955c4fd95b54210f8b0506c90f9d05c74f68a828eff64324a43c3a0e6a8eeb80096bef5
7
- data.tar.gz: 6289d83637fcc81e87b35e4d01d671fb0d26114253d65b804cabe8cf2b029c3b91a4436d921240d8abad6a84a50074cb3bdd8ef7cbe1e5279f0ab3ea16719ff0
6
+ metadata.gz: 8fe75f849916a6c70177f68bc9f4326b873d7715e43efdc42db5f26206f7561dd2db4a986c229e32fbe43e40b915ac769db94c6d03b10aaab0a78d27a777e9e5
7
+ data.tar.gz: 6a0ef14b3ebac1b36ff959da8d35a28454757b5cbe4ea89efb0799fec10d2c34f4d7e324e67b482c432f24812758f79d640401ad1bec877419abcb2e0dc1cf78
@@ -26,10 +26,11 @@ class Sidekiq::Merger::Merge
26
26
  options = get_options(worker_class)
27
27
  merge_key = options["key"]
28
28
  if merge_key.respond_to?(:call)
29
- merge_key.call(args)
30
- else
31
- merge_key
29
+ merge_key = merge_key.call(args)
32
30
  end
31
+ merge_key = "" if merge_key.nil?
32
+ merge_key = merge_key.to_json unless merge_key.is_a?(String)
33
+ merge_key
33
34
  end
34
35
 
35
36
  def get_options(worker_class)
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Merger
3
- VERSION = "0.0.8".freeze
3
+ VERSION = "0.0.9".freeze
4
4
  end
5
5
  end
@@ -1,7 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Sidekiq::Merger::Merge do
4
- subject { described_class.new(worker_class, queue, "foo", redis: redis) }
4
+ subject { described_class.new(worker_class, queue, args, redis: redis) }
5
+ let(:args) { "foo" }
5
6
  let(:redis) { Sidekiq::Merger::Redis.new }
6
7
  let(:queue) { "queue" }
7
8
  let(:now) { Time.now }
@@ -61,6 +62,39 @@ describe Sidekiq::Merger::Merge do
61
62
  end
62
63
  end
63
64
 
65
+ describe ".merge_key" do
66
+ let(:args) { "foo" }
67
+ let(:options) { {} }
68
+ it "returns an empty string" do
69
+ expect(described_class.merge_key(worker_class, args)).to eq ""
70
+ end
71
+ context "string key" do
72
+ let(:options) { { key: "bar" } }
73
+ it "returns the string" do
74
+ expect(described_class.merge_key(worker_class, args)).to eq "bar"
75
+ end
76
+ end
77
+ context "other type key" do
78
+ let(:options) { { key: [1, 2, 3] } }
79
+ it "returns nil" do
80
+ expect(described_class.merge_key(worker_class, args)).to eq "[1,2,3]"
81
+ end
82
+ end
83
+ context "proc key" do
84
+ let(:args) { [1, 2, 3] }
85
+ let(:options) { { key: -> (args) { args[0].to_s } } }
86
+ it "returns the result of the proc" do
87
+ expect(described_class.merge_key(worker_class, args)).to eq "1"
88
+ end
89
+ context "non-string result" do
90
+ let(:options) { { key: -> (args) { args[0] } } }
91
+ it "returns nil" do
92
+ expect(described_class.merge_key(worker_class, args)).to eq "1"
93
+ end
94
+ end
95
+ end
96
+ end
97
+
64
98
  describe "#add" do
65
99
  it "adds the args in lazy merge" do
66
100
  expect(redis).to receive(:push_message).with("name:queue:foo", [1, 2, 3], execution_time)
@@ -89,7 +123,36 @@ describe Sidekiq::Merger::Merge do
89
123
  end
90
124
  end
91
125
 
126
+ describe "#delete_all" do
127
+ before do
128
+ subject.add([1, 2, 3], execution_time)
129
+ subject.add([2, 3, 4], execution_time)
130
+ end
131
+ it "deletes all" do
132
+ expect {
133
+ subject.delete_all
134
+ }.to change { subject.size }.from(2).to(0)
135
+ end
136
+ end
137
+
92
138
  describe "#size" do
139
+ before do
140
+ subject.add([1, 2, 3], execution_time)
141
+ subject.add([2, 3, 4], execution_time)
142
+ end
143
+ it "returns the size" do
144
+ expect(subject.size).to eq 2
145
+ end
146
+ end
147
+
148
+ describe "#all_args" do
149
+ before do
150
+ subject.add([1, 2, 3], execution_time)
151
+ subject.add([2, 3, 4], execution_time)
152
+ end
153
+ it "returns all args" do
154
+ expect(subject.all_args).to contain_exactly [1, 2, 3], [2, 3, 4]
155
+ end
93
156
  end
94
157
 
95
158
  describe "#flush" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-merger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - dtaniwaki