entity_store_sequel 0.3.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: 8e81c642170575ae02a6faf8f0ec2c4fe71bf4b00eb2fabfd5f9f8099fdb5bd6
4
- data.tar.gz: 5b0463a52fc3b0382f6d083ad087c353753214a01b1e17220cd61f769aa4e058
3
+ metadata.gz: 1fbaafda3599b05b00d50669608de59f140546e61066def1dbb355d2eea59ccf
4
+ data.tar.gz: 565ac6d7d44085cb366f2250147c20c63f4a1b05143cb8f30286f485172c184b
5
5
  SHA512:
6
- metadata.gz: 727a2f7db49b844f065e25dda18433916a9a5b8773e936ce7cb5ee6c068c3ff238a242aba7548d03b8d8af8e4de1bd4193a81642fe967c3fbe222ee2ef44ad7f
7
- data.tar.gz: a999ecfe3f45f38fc16250f81fb64e73d06e480d753562eca0ce40d900d06c1349f17bd949312c343f4b42cce8d2818ab42c1ec8822c7818ea1e030e7018cb3e
6
+ metadata.gz: a5ab29eb7d354b40cd35411226e8e96d65ca7df0fda329378a849033fc96a13864558eae931966756fef5ae18733806075dcd69cf723c1f28bcebcca2c606c10
7
+ data.tar.gz: c8ffb267c8103f4bf4cd03e56099f55e3d6ecec1b93357176de0e1a24018d1c8191763b7ac5578944eeefd9795fce6dfaa024c88c881a6ebbef5f38449dcec04
@@ -70,10 +70,13 @@ module EntityStoreSequel
70
70
  end
71
71
 
72
72
  def clear_entity_events(id, excluded_types)
73
- events.where(_entity_id: id).each do |event|
74
- next if excluded_types.include?(event[:_type])
75
-
76
- events.where(id: event[:id]).delete
73
+ if excluded_types.empty?
74
+ events.where(_entity_id: id).delete
75
+ else
76
+ events.where(_entity_id: id).select(:id, :_type).each do |event|
77
+ next if excluded_types.include?(event[:_type])
78
+ events.where(id: event[:id]).delete
79
+ end
77
80
  end
78
81
  end
79
82
 
@@ -1,3 +1,3 @@
1
1
  module EntityStoreSequel
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -47,6 +47,21 @@ describe PostgresEntityStore do
47
47
  end
48
48
  end
49
49
 
50
+ class DummyEntityExcludedEvent
51
+ include EntityStore::Event
52
+
53
+ attr_accessor :marker
54
+
55
+ def apply(entity)
56
+ # No-op
57
+ end
58
+
59
+ def ==(other)
60
+ # Crude check relying on inspect, ok for tests
61
+ self.inspect == other.inspect
62
+ end
63
+ end
64
+
50
65
  let(:store) do
51
66
  described_class.connection_string = ENV['SQL_CONNECTION'] || 'postgres://localhost/cronofy_test'
52
67
  described_class.init
@@ -123,23 +138,42 @@ describe PostgresEntityStore do
123
138
  let(:third_event) { DummyEntityNameSet.new(:entity_id => entity_id, :entity_version => 2, :name => random_string) }
124
139
  let(:unrelated_event) { DummyEntityNameSet.new(:entity_id => second_entity_id, :entity_version => 4, :name => random_string) }
125
140
  let(:fourth_event) { DummyEntityNameSet.new(:entity_id => entity_id, :entity_version => 3, :name => random_string) }
141
+ let(:excluded_event) { DummyEntityExcludedEvent.new(:entity_id => entity_id, :entity_version => 5, :marker => random_string) }
126
142
 
127
143
  before do
128
- store.add_events([ second_event, unrelated_event, first_event, third_event, fourth_event ])
144
+ store.add_events([ second_event, unrelated_event, first_event, third_event, fourth_event, excluded_event ])
129
145
  end
130
146
 
131
- subject { store.clear_entity_events(entity_id, []) }
147
+ context "clearing everything" do
148
+ subject { store.clear_entity_events(entity_id, []) }
132
149
 
133
- it "clears the events from the entity" do
134
- subject
135
- events = store.get_events( [ id: entity_id ])[entity_id]
136
- expect(events).to be_empty
150
+ it "clears the events from the entity" do
151
+ subject
152
+ events = store.get_events( [ id: entity_id ])[entity_id]
153
+ expect(events).to be_empty
154
+ end
155
+
156
+ it "does not delete unrelated the events" do
157
+ subject
158
+ events = store.get_events( [ id: second_entity_id ])[second_entity_id]
159
+ expect(events).to eq [unrelated_event]
160
+ end
137
161
  end
138
162
 
139
- it "does not delete unrelated the events" do
140
- subject
141
- events = store.get_events( [ id: second_entity_id ])[second_entity_id]
142
- expect(events.count).to eq(1)
163
+ context "excluding an event type from deletion" do
164
+ subject { store.clear_entity_events(entity_id, [DummyEntityExcludedEvent.to_s]) }
165
+
166
+ it "clears all other events from the entity" do
167
+ subject
168
+ events = store.get_events( [ id: entity_id ])[entity_id]
169
+ expect(events).to eq [excluded_event]
170
+ end
171
+
172
+ it "does not delete unrelated the events" do
173
+ subject
174
+ events = store.get_events( [ id: second_entity_id ])[second_entity_id]
175
+ expect(events).to eq [unrelated_event]
176
+ end
143
177
  end
144
178
  end
145
179
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entity_store_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Binns
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-09 00:00:00.000000000 Z
11
+ date: 2024-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -101,7 +101,7 @@ homepage: http://github.com/cronofy/entity_store_sequel
101
101
  licenses:
102
102
  - MIT
103
103
  metadata: {}
104
- post_install_message:
104
+ post_install_message:
105
105
  rdoc_options: []
106
106
  require_paths:
107
107
  - lib
@@ -116,11 +116,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.0.3
120
- signing_key:
119
+ rubygems_version: 3.4.21
120
+ signing_key:
121
121
  specification_version: 4
122
122
  summary: Sequel body for Entity Store
123
123
  test_files:
124
- - spec/spec_helper.rb
125
- - spec/entity_store_spec.rb
126
124
  - spec/entity_store_sequel/postgres_entity_store_spec.rb
125
+ - spec/entity_store_spec.rb
126
+ - spec/spec_helper.rb