redstream 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48ab0cf09dec323cf89c4bebe065054535f24402182208ee62ab0524e0d45fa3
4
- data.tar.gz: 4264929febdbe55dfd240893d8f1327244937a835e2535cdf943342529e926a4
3
+ metadata.gz: 6be694edcad63b15c2e7a6630047080556a412fc1b52f874e4f793e8f07f80b9
4
+ data.tar.gz: f140446d6fbebc97533de509ff622fe32b121cd89af2c5f0cc2b856f5e820e02
5
5
  SHA512:
6
- metadata.gz: 2507c6ebdeb7e4e1c0088af3f7711dce068b614c490222cb69a3634696c8be695e9485750f3c032f1b87d17653135bd59397a09bacc3d3d121f9fbce94251b9a
7
- data.tar.gz: 66cf9439eebf813c7bca3426bb466189babec062da87eeb6f0a1a893d497fdf80cafe0bb63764aee7c1a56a07bdfbae9aebce91a2ff1eb2f8b4da4074a6f69af
6
+ metadata.gz: 2b38daa5a07f1761fa47340c4d479b974b30937479a6a73897ad8d8e47c9d45328ef976d20b8a74a7cb0488d35985864d162b3adbb66133e56195cb016b09ab4
7
+ data.tar.gz: 0b625e0f6fea967e69ba319115dd9bfd727b68aec369a83a0842bb39805b0389ebef33bae5cf2559314d54724a9fd28d5a517ab8cbdc88f14db1ec5a601c12ee
@@ -1,6 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
- * v0.1.0
3
+ ## v0.1.1
4
+ * Fix missing queue message in `after_commit on: :destroy`
4
5
 
5
- - No longer queue/delay in after_save/after_commit if no changes occurred
6
- - Added Redstream.stream_size
6
+ ## v0.1.0
7
+ * No longer queue/delay in `after_save`/`after_commit` if no changes occurred
8
+ * Added `Redstream.stream_size`
@@ -32,7 +32,8 @@ module Redstream
32
32
  after_save { |object| producer.delay(object) if object.saved_changes.present? }
33
33
  after_touch { |object| producer.delay(object) }
34
34
  after_destroy { |object| producer.delay(object) }
35
- after_commit { |object| producer.queue(object) if object.saved_changes.present? }
35
+ after_commit(on: [:create, :update]) { |object| producer.queue(object) if object.saved_changes.present? }
36
+ after_commit(on: :destroy) { |object| producer.queue(object) }
36
37
  end
37
38
 
38
39
  def redstream_name
@@ -1,3 +1,3 @@
1
1
  module Redstream
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,74 +2,72 @@ require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe Redstream::Model do
4
4
  describe "after_save" do
5
- it "adds a delay message after save" do
6
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(0)
7
-
8
- time = Time.now
5
+ it "adds a delay message after_save" do
6
+ expect { create(:product) }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
7
+ end
9
8
 
10
- product = Timecop.freeze(time) do
11
- create(:product)
12
- end
9
+ it "adds the correct payload for the delay message" do
10
+ product = create(:product)
13
11
 
14
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(1)
15
12
  expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").first[1]).to eq("payload" => JSON.dump(product.redstream_payload))
16
13
  end
17
14
 
18
- it "does not a delay message after save if there are no changes" do
15
+ it "adds a queue message after_save on commit" do
16
+ expect { create(:product) }.to change { redis.xlen(Redstream.stream_key_name("products")) }
17
+ end
18
+
19
+ it "does not add a delay message after_save if there are no changes" do
19
20
  product = create(:product)
20
21
 
21
22
  expect { product.save }.not_to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
22
23
  end
24
+
25
+ it "does not add a queue messages after_save on commit if there are no changes" do
26
+ product = create(:product)
27
+
28
+ expect { product.save }.not_to change { redis.xlen(Redstream.stream_key_name("products")) }
29
+ end
23
30
  end
24
31
 
25
32
  describe "after_touch" do
26
33
  it "adds a delay message after touch" do
27
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(0)
28
-
29
34
  product = create(:product)
30
35
 
31
- time = Time.now
36
+ expect { product.touch }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
37
+ end
32
38
 
33
- Timecop.freeze(time) do
34
- product.touch
35
- end
39
+ it "sets the correct payload for the delay message" do
40
+ product = create(:product)
41
+ product.touch
36
42
 
37
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(2)
38
43
  expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
39
44
  end
45
+
46
+ it "adds a queue message after touch commit" do
47
+ product = create(:product)
48
+
49
+ expect { product.touch }.to change { redis.xlen(Redstream.stream_key_name("products")) }
50
+ end
40
51
  end
41
52
 
42
53
  describe "after_destroy" do
43
54
  it "adds a delay message after destroy" do
44
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(0)
45
-
46
55
  product = create(:product)
47
56
 
48
- time = Time.now
49
-
50
- Timecop.freeze(time) do
51
- product.touch
52
- end
53
-
54
- expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(2)
55
- expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
57
+ expect { product.destroy }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
56
58
  end
57
- end
58
-
59
- describe "after_commit" do
60
- it "adds a queue message after commit" do
61
- expect(redis.xlen(Redstream.stream_key_name("products"))).to eq(0)
62
59
 
60
+ it "sets the correct payload for the delay message" do
63
61
  product = create(:product)
62
+ product.destroy
64
63
 
65
- expect(redis.xlen(Redstream.stream_key_name("products"))).to eq(1)
66
- expect(redis.xrange(Redstream.stream_key_name("products"), "-", "+").first[1]).to eq("payload" => JSON.dump(product.redstream_payload))
64
+ expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
67
65
  end
68
66
 
69
- it "does not add a queue message after commit if there are no changes" do
67
+ it "adds a queue messages after destroy on commit" do
70
68
  product = create(:product)
71
69
 
72
- expect { product.save }.not_to change { redis.xlen(Redstream.stream_key_name("products")) }
70
+ expect { product.destroy }.to change { redis.xlen(Redstream.stream_key_name("products")) }.by(1)
73
71
  end
74
72
  end
75
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-10 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -288,8 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  - !ruby/object:Gem::Version
289
289
  version: '0'
290
290
  requirements: []
291
- rubyforge_project:
292
- rubygems_version: 2.7.3
291
+ rubygems_version: 3.0.3
293
292
  signing_key:
294
293
  specification_version: 4
295
294
  summary: Using redis streams to keep your primary database in sync with secondary