sequel_bitemporal 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/sequel/plugins/bitemporal.rb +12 -11
- data/sequel_bitemporal.gemspec +3 -3
- data/spec/bitemporal_date_spec.rb +147 -135
- data/spec/bitemporal_date_with_range_spec.rb +127 -127
- data/spec/bitemporal_serialization_spec.rb +7 -7
- data/spec/bitemporal_time_spec.rb +82 -82
- data/spec/bitemporal_time_with_range_spec.rb +85 -85
- data/spec/spec_helper.rb +0 -1
- data/spec/support/bitemporal_matchers.rb +11 -11
- metadata +8 -7
@@ -12,34 +12,34 @@ if DbHelpers.pg?
|
|
12
12
|
Timecop.return
|
13
13
|
end
|
14
14
|
it "checks version class is given" do
|
15
|
-
|
15
|
+
expect{
|
16
16
|
@version_class.plugin :bitemporal
|
17
|
-
}.
|
17
|
+
}.to raise_error Sequel::Error, "please specify version class to use for bitemporal plugin"
|
18
18
|
end
|
19
19
|
it "checks required columns are present" do
|
20
|
-
|
20
|
+
expect{
|
21
21
|
@version_class.plugin :bitemporal, :version_class => @master_class
|
22
|
-
}.
|
22
|
+
}.to raise_error Sequel::Error, "bitemporal plugin requires the following missing columns on version class: master_id, valid_from, valid_to, created_at, expired_at"
|
23
23
|
end
|
24
24
|
it "propagates errors from version to master" do
|
25
25
|
master = @master_class.new
|
26
|
-
master.
|
26
|
+
expect(master).to be_valid
|
27
27
|
master.attributes = {name: "Single Standard"}
|
28
|
-
master.
|
29
|
-
master.errors.
|
28
|
+
expect(master).not_to be_valid
|
29
|
+
expect(master.errors).to eq({price: ["is required"]})
|
30
30
|
end
|
31
31
|
it "#update_attributes returns false instead of raising errors" do
|
32
32
|
master = @master_class.new
|
33
|
-
master.update_attributes(name: "Single Standard").
|
34
|
-
master.
|
35
|
-
master.errors.
|
36
|
-
master.update_attributes(price: 98).
|
33
|
+
expect(master.update_attributes(name: "Single Standard")).to be_falsey
|
34
|
+
expect(master).to be_new
|
35
|
+
expect(master.errors).to eq({price: ["is required"]})
|
36
|
+
expect(master.update_attributes(price: 98)).to be_truthy
|
37
37
|
end
|
38
38
|
it "allows creating a master and its first version in one step" do
|
39
39
|
master = @master_class.new
|
40
|
-
master.update_attributes(name: "Single Standard", price: 98).
|
41
|
-
master.
|
42
|
-
master.
|
40
|
+
expect(master.update_attributes(name: "Single Standard", price: 98)).to be_truthy
|
41
|
+
expect(master).not_to be_new
|
42
|
+
expect(master).to have_versions %Q{
|
43
43
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
44
44
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | MAX TIME | true |
|
45
45
|
}
|
@@ -47,7 +47,7 @@ if DbHelpers.pg?
|
|
47
47
|
it "allows creating a new version in the past" do
|
48
48
|
master = @master_class.new
|
49
49
|
master.update_attributes name: "Single Standard", price: 98, valid_from: Time.now-hour
|
50
|
-
master.
|
50
|
+
expect(master).to have_versions %Q{
|
51
51
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
52
52
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 09:00:00 +0000 | MAX TIME | true |
|
53
53
|
}
|
@@ -55,7 +55,7 @@ if DbHelpers.pg?
|
|
55
55
|
it "allows creating a new version in the future" do
|
56
56
|
master = @master_class.new
|
57
57
|
master.update_attributes name: "Single Standard", price: 98, valid_from: Time.now+hour
|
58
|
-
master.
|
58
|
+
expect(master).to have_versions %Q{
|
59
59
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
60
60
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 11:00:00 +0000 | MAX TIME | |
|
61
61
|
}
|
@@ -64,7 +64,7 @@ if DbHelpers.pg?
|
|
64
64
|
master = @master_class.new
|
65
65
|
master.update_attributes name: "Single Standard", price: 98
|
66
66
|
master.update_attributes name: "Single Standard", price: 94
|
67
|
-
master.
|
67
|
+
expect(master).to have_versions %Q{
|
68
68
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
69
69
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
70
70
|
| Single Standard | 94 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | MAX TIME | true |
|
@@ -75,7 +75,7 @@ if DbHelpers.pg?
|
|
75
75
|
master.update_attributes name: "Single Standard", price: 98
|
76
76
|
master.update_attributes price: 94
|
77
77
|
master.update_attributes name: "King Size"
|
78
|
-
master.
|
78
|
+
expect(master).to have_versions %Q{
|
79
79
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
80
80
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
81
81
|
| Single Standard | 94 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
@@ -87,7 +87,7 @@ if DbHelpers.pg?
|
|
87
87
|
master.update_attributes name: "Single Standard", price: 98
|
88
88
|
Timecop.freeze Time.now+hour
|
89
89
|
master.update_attributes price: 94
|
90
|
-
master.
|
90
|
+
expect(master).to have_versions %Q{
|
91
91
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
92
92
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
93
93
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
@@ -98,9 +98,9 @@ if DbHelpers.pg?
|
|
98
98
|
master = @master_class.new
|
99
99
|
master.update_attributes name: "Single Standard", price: 98, valid_to: Time.now+hour
|
100
100
|
Timecop.freeze Time.now+hour
|
101
|
-
master.update_attributes(price: 94).
|
101
|
+
expect(master.update_attributes(price: 94)).to be_falsey
|
102
102
|
master.update_attributes name: "Single Standard", price: 94
|
103
|
-
master.
|
103
|
+
expect(master).to have_versions %Q{
|
104
104
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
105
105
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
106
106
|
| Single Standard | 94 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 11:00:00 +0000 | MAX TIME | true |
|
@@ -111,7 +111,7 @@ if DbHelpers.pg?
|
|
111
111
|
master.update_attributes name: "Single Standard", price: 98
|
112
112
|
Timecop.freeze Time.now+hour
|
113
113
|
master.update_attributes valid_to: Time.now+10*hour
|
114
|
-
master.
|
114
|
+
expect(master).to have_versions %Q{
|
115
115
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
116
116
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
117
117
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
@@ -126,12 +126,12 @@ if DbHelpers.pg?
|
|
126
126
|
master = @master_class.new
|
127
127
|
master.update_attributes name: "Single Standard", price: 98, valid_to: Time.now+2*hour
|
128
128
|
Timecop.freeze Time.now+hour
|
129
|
-
master.
|
129
|
+
expect(master).to have_versions %Q{
|
130
130
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
131
131
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | true |
|
132
132
|
}
|
133
133
|
master.update_attributes valid_to: nil
|
134
|
-
master.
|
134
|
+
expect(master).to have_versions %Q{
|
135
135
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
136
136
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
137
137
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
@@ -147,7 +147,7 @@ if DbHelpers.pg?
|
|
147
147
|
master.update_attributes name: "Single Standard", price: 98
|
148
148
|
master.update_attributes price: 98
|
149
149
|
master.update_attributes name: "Single Standard", price: 98
|
150
|
-
master.
|
150
|
+
expect(master).to have_versions %Q{
|
151
151
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
152
152
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000| MAX TIME | true |
|
153
153
|
}
|
@@ -158,7 +158,7 @@ if DbHelpers.pg?
|
|
158
158
|
Timecop.freeze Time.now+hour
|
159
159
|
master.update_attributes price: 98, valid_from: Time.now-2*hour
|
160
160
|
master.update_attributes price: 98, valid_from: Time.now+1*hour
|
161
|
-
master.
|
161
|
+
expect(master).to have_versions %Q{
|
162
162
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
163
163
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | MAX TIME | true |
|
164
164
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 09:00:00 +0000 | 2009-11-28 10:00:00 +0000 | |
|
@@ -175,7 +175,7 @@ if DbHelpers.pg?
|
|
175
175
|
master.update_attributes name: "Single Standard", price: 95, valid_from: Time.now+4*hour, valid_to: Time.now+6*hour
|
176
176
|
Timecop.freeze Time.now+hour
|
177
177
|
master.update_attributes name: "King Size", valid_to: nil
|
178
|
-
master.
|
178
|
+
expect(master).to have_versions %Q{
|
179
179
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
180
180
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
181
181
|
| Single Standard | 94 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 12:00:00 +0000 | 2009-11-28 14:00:00 +0000 | |
|
@@ -191,7 +191,7 @@ if DbHelpers.pg?
|
|
191
191
|
master.update_attributes name: "Single Standard", price: 95, valid_from: Time.now+4*hour, valid_to: Time.now+6*hour
|
192
192
|
Timecop.freeze Time.now+hour
|
193
193
|
master.update_attributes name: "King Size", valid_to: Time.now+4*hour
|
194
|
-
master.
|
194
|
+
expect(master).to have_versions %Q{
|
195
195
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
196
196
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
197
197
|
| Single Standard | 94 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 12:00:00 +0000 | 2009-11-28 14:00:00 +0000 | |
|
@@ -208,7 +208,7 @@ if DbHelpers.pg?
|
|
208
208
|
master.update_attributes name: "Single Standard", price: 95, valid_from: Time.now+4*hour, valid_to: Time.now+6*hour
|
209
209
|
Timecop.freeze Time.now+hour
|
210
210
|
master.update_attributes name: "King Size", valid_to: Time.utc(9999)
|
211
|
-
master.
|
211
|
+
expect(master).to have_versions %Q{
|
212
212
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
213
213
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
214
214
|
| Single Standard | 94 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 12:00:00 +0000 | 2009-11-28 14:00:00 +0000 | |
|
@@ -222,8 +222,8 @@ if DbHelpers.pg?
|
|
222
222
|
master.update_attributes name: "Single Standard", price: 98
|
223
223
|
master.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
224
224
|
Timecop.freeze Time.now+hour
|
225
|
-
master.current_version.destroy.
|
226
|
-
master.
|
225
|
+
expect(master.current_version.destroy).to be_truthy
|
226
|
+
expect(master).to have_versions %Q{
|
227
227
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
228
228
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
229
229
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
@@ -236,8 +236,8 @@ if DbHelpers.pg?
|
|
236
236
|
master.update_attributes name: "Single Standard", price: 98
|
237
237
|
master.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
238
238
|
Timecop.freeze Time.now+hour
|
239
|
-
master.versions.last.destroy.
|
240
|
-
master.
|
239
|
+
expect(master.versions.last.destroy).to be_truthy
|
240
|
+
expect(master).to have_versions %Q{
|
241
241
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
242
242
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
243
243
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
@@ -250,8 +250,8 @@ if DbHelpers.pg?
|
|
250
250
|
master.update_attributes name: "Single Standard", price: 98
|
251
251
|
master.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
252
252
|
Timecop.freeze Time.now+hour
|
253
|
-
master.destroy.
|
254
|
-
master.
|
253
|
+
expect(master.destroy).to be_truthy
|
254
|
+
expect(master).to have_versions %Q{
|
255
255
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
256
256
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
257
257
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
|
@@ -265,7 +265,7 @@ if DbHelpers.pg?
|
|
265
265
|
master2 = @master_class.find id: master.id
|
266
266
|
master.update_attributes name: "Single Standard", price: 94
|
267
267
|
master2.update_attributes name: "Single Standard", price: 95
|
268
|
-
master.
|
268
|
+
expect(master).to have_versions %Q{
|
269
269
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
270
270
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
271
271
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
@@ -280,7 +280,7 @@ if DbHelpers.pg?
|
|
280
280
|
master2 = @master_class.find id: master.id
|
281
281
|
master.update_attributes price: 94
|
282
282
|
master2.update_attributes name: "King Size"
|
283
|
-
master.
|
283
|
+
expect(master).to have_versions %Q{
|
284
284
|
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
285
285
|
| Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
|
286
286
|
| Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | |
|
@@ -292,10 +292,10 @@ if DbHelpers.pg?
|
|
292
292
|
master = @master_class.new
|
293
293
|
master.update_attributes name: "Single Standard", price: 98
|
294
294
|
master.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
295
|
-
@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.
|
295
|
+
expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be
|
296
296
|
Timecop.freeze Time.now+hour
|
297
297
|
master.destroy
|
298
|
-
@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.
|
298
|
+
expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be_nil
|
299
299
|
end
|
300
300
|
it "allows loading masters with a current version" do
|
301
301
|
master_destroyed = @master_class.new
|
@@ -305,52 +305,52 @@ if DbHelpers.pg?
|
|
305
305
|
master_with_current.update_attributes name: "Single Standard", price: 94
|
306
306
|
master_with_future = @master_class.new
|
307
307
|
master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
308
|
-
@master_class.with_current_version.all.
|
308
|
+
expect(@master_class.with_current_version.all.size).to eq(1)
|
309
309
|
end
|
310
310
|
it "gets pending or current version attributes" do
|
311
311
|
master = @master_class.new
|
312
|
-
master.attributes.
|
313
|
-
master.pending_version.
|
314
|
-
master.current_version.
|
315
|
-
master.pending_or_current_version.name.
|
316
|
-
master.name.
|
312
|
+
expect(master.attributes).to eq({})
|
313
|
+
expect(master.pending_version).to be_nil
|
314
|
+
expect(master.current_version).to be_nil
|
315
|
+
expect(master.pending_or_current_version.name).to be_nil
|
316
|
+
expect(master.name).to be_nil
|
317
317
|
|
318
318
|
master.update_attributes name: "Single Standard", price: 98
|
319
|
-
master.attributes[:name].
|
320
|
-
master.pending_version.
|
321
|
-
master.pending_or_current_version.name.
|
322
|
-
master.name.
|
319
|
+
expect(master.attributes[:name]).to eq("Single Standard")
|
320
|
+
expect(master.pending_version).to be_nil
|
321
|
+
expect(master.pending_or_current_version.name).to eq("Single Standard")
|
322
|
+
expect(master.name).to eq("Single Standard")
|
323
323
|
|
324
324
|
master.attributes = {name: "King Size"}
|
325
|
-
master.attributes[:name].
|
326
|
-
master.pending_version.
|
327
|
-
master.pending_or_current_version.name.
|
328
|
-
master.name.
|
325
|
+
expect(master.attributes[:name]).to eq("King Size")
|
326
|
+
expect(master.pending_version).to be
|
327
|
+
expect(master.pending_or_current_version.name).to eq("King Size")
|
328
|
+
expect(master.name).to eq("King Size")
|
329
329
|
end
|
330
330
|
it "allows to go back in time" do
|
331
331
|
master = @master_class.new
|
332
332
|
master.update_attributes name: "Single Standard", price: 98
|
333
333
|
Timecop.freeze Time.now+1*hour
|
334
334
|
master.update_attributes price: 94
|
335
|
-
master.current_version.price.
|
335
|
+
expect(master.current_version.price).to eq(94)
|
336
336
|
Sequel::Plugins::Bitemporal.as_we_knew_it(Time.now-1*hour) do
|
337
|
-
master.current_version(true).price.
|
337
|
+
expect(master.current_version(true).price).to eq(98)
|
338
338
|
end
|
339
339
|
end
|
340
340
|
it "correctly reset time if failure when going back in time" do
|
341
341
|
before = Sequel::Plugins::Bitemporal.now
|
342
|
-
|
342
|
+
expect do
|
343
343
|
Sequel::Plugins::Bitemporal.at(Time.now+1*hour) do
|
344
344
|
raise StandardError, "error during back in time"
|
345
345
|
end
|
346
|
-
end.
|
347
|
-
Sequel::Plugins::Bitemporal.now.
|
348
|
-
|
346
|
+
end.to raise_error StandardError
|
347
|
+
expect(Sequel::Plugins::Bitemporal.now).to eq(before)
|
348
|
+
expect do
|
349
349
|
Sequel::Plugins::Bitemporal.as_we_knew_it(Time.now-1*hour) do
|
350
350
|
raise StandardError, "error during back in time"
|
351
351
|
end
|
352
|
-
end.
|
353
|
-
Sequel::Plugins::Bitemporal.now.
|
352
|
+
end.to raise_error StandardError
|
353
|
+
expect(Sequel::Plugins::Bitemporal.now).to eq(before)
|
354
354
|
end
|
355
355
|
it "allows eager loading with conditions on current or future versions" do
|
356
356
|
master = @master_class.new
|
@@ -359,16 +359,16 @@ if DbHelpers.pg?
|
|
359
359
|
master.update_attributes name: "Single Standard", price: 99
|
360
360
|
master.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
361
361
|
res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 99}).all.first
|
362
|
-
res.
|
363
|
-
res.current_or_future_versions.
|
364
|
-
res.current_or_future_versions.first.price.
|
362
|
+
expect(res).to be
|
363
|
+
expect(res.current_or_future_versions.size).to eq(1)
|
364
|
+
expect(res.current_or_future_versions.first.price).to eq(99)
|
365
365
|
res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 94}).all.first
|
366
|
-
res.
|
367
|
-
res.current_or_future_versions.
|
368
|
-
res.current_or_future_versions.first.price.
|
366
|
+
expect(res).to be
|
367
|
+
expect(res.current_or_future_versions.size).to eq(1)
|
368
|
+
expect(res.current_or_future_versions.first.price).to eq(94)
|
369
369
|
Timecop.freeze Time.now+1*hour
|
370
370
|
master.destroy
|
371
|
-
@master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all.
|
371
|
+
expect(@master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all).to be_empty
|
372
372
|
end
|
373
373
|
it "allows loading masters with current or future versions" do
|
374
374
|
master_destroyed = @master_class.new
|
@@ -378,7 +378,7 @@ if DbHelpers.pg?
|
|
378
378
|
master_with_current.update_attributes name: "Single Standard", price: 94
|
379
379
|
master_with_future = @master_class.new
|
380
380
|
master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Time.now+2*hour
|
381
|
-
@master_class.with_current_or_future_versions.all.
|
381
|
+
expect(@master_class.with_current_or_future_versions.all.size).to eq(2)
|
382
382
|
end
|
383
383
|
end
|
384
384
|
describe "Sequel::Plugins::Bitemporal", "with audit" do
|
@@ -395,8 +395,8 @@ if DbHelpers.pg?
|
|
395
395
|
let(:author){ double :author, audit_kind: "user" }
|
396
396
|
it "generates a new audit on creation" do
|
397
397
|
master = @master_class.new
|
398
|
-
master.
|
399
|
-
@audit_class.
|
398
|
+
expect(master).to receive(:updated_by).and_return author
|
399
|
+
expect(@audit_class).to receive(:audit).with(
|
400
400
|
master,
|
401
401
|
{},
|
402
402
|
hash_including({name: "Single Standard", price: 98}),
|
@@ -407,10 +407,10 @@ if DbHelpers.pg?
|
|
407
407
|
end
|
408
408
|
it "generates a new audit on full update" do
|
409
409
|
master = @master_class.new
|
410
|
-
master.
|
411
|
-
@audit_class.
|
410
|
+
expect(master).to receive(:updated_by).twice.and_return author
|
411
|
+
allow(@audit_class).to receive(:audit)
|
412
412
|
master.update_attributes name: "Single Standard", price: 98
|
413
|
-
@audit_class.
|
413
|
+
expect(@audit_class).to receive(:audit).with(
|
414
414
|
master,
|
415
415
|
hash_including({name: "Single Standard", price: 98}),
|
416
416
|
hash_including({name: "King size", price: 98}),
|
@@ -421,10 +421,10 @@ if DbHelpers.pg?
|
|
421
421
|
end
|
422
422
|
it "generates a new audit on partial update" do
|
423
423
|
master = @master_class.new
|
424
|
-
master.
|
425
|
-
@audit_class.
|
424
|
+
expect(master).to receive(:updated_by).twice.and_return author
|
425
|
+
allow(@audit_class).to receive(:audit)
|
426
426
|
master.update_attributes name: "Single Standard", price: 98
|
427
|
-
@audit_class.
|
427
|
+
expect(@audit_class).to receive(:audit).with(
|
428
428
|
master,
|
429
429
|
hash_including({name: "Single Standard", price: 98}),
|
430
430
|
hash_including({name: "King size", price: 98}),
|
@@ -454,8 +454,8 @@ if DbHelpers.pg?
|
|
454
454
|
let(:author){ double :author, audit_kind: "user" }
|
455
455
|
it "generates a new audit on creation" do
|
456
456
|
master = @master_class.new
|
457
|
-
master.
|
458
|
-
@audit_class.
|
457
|
+
expect(master).to receive(:author).and_return author
|
458
|
+
expect(@audit_class).to receive(:audit).with(
|
459
459
|
master,
|
460
460
|
{},
|
461
461
|
hash_including({name: "Single Standard", price: 98}),
|
@@ -466,10 +466,10 @@ if DbHelpers.pg?
|
|
466
466
|
end
|
467
467
|
it "generates a new audit on full update" do
|
468
468
|
master = @master_class.new
|
469
|
-
master.
|
470
|
-
@audit_class.
|
469
|
+
expect(master).to receive(:author).twice.and_return author
|
470
|
+
allow(@audit_class).to receive(:audit)
|
471
471
|
master.update_attributes name: "Single Standard", price: 98
|
472
|
-
@audit_class.
|
472
|
+
expect(@audit_class).to receive(:audit).with(
|
473
473
|
master,
|
474
474
|
hash_including({name: "Single Standard", price: 98}),
|
475
475
|
hash_including({name: "King size", price: 98}),
|
@@ -480,10 +480,10 @@ if DbHelpers.pg?
|
|
480
480
|
end
|
481
481
|
it "generates a new audit on partial update" do
|
482
482
|
master = @master_class.new
|
483
|
-
master.
|
484
|
-
@audit_class.
|
483
|
+
expect(master).to receive(:author).twice.and_return author
|
484
|
+
allow(@audit_class).to receive(:audit)
|
485
485
|
master.update_attributes name: "Single Standard", price: 98
|
486
|
-
@audit_class.
|
486
|
+
expect(@audit_class).to receive(:audit).with(
|
487
487
|
master,
|
488
488
|
hash_including({name: "Single Standard", price: 98}),
|
489
489
|
hash_including({name: "King size", price: 98}),
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
RSpec::Matchers.define :have_versions do |versions_str|
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
table = have_versions_parse_table versions_str
|
3
|
+
last_index = nil
|
4
|
+
last_version = nil
|
5
5
|
match do |master|
|
6
6
|
versions = master.versions_dataset.order(:id).all
|
7
|
-
columns =
|
8
|
-
versions.size ==
|
9
|
-
|
10
|
-
|
7
|
+
columns = table.first.keys.collect(&:to_sym)
|
8
|
+
versions.size == table.size && table.each.with_index.all? do |version, index|
|
9
|
+
last_index = index
|
10
|
+
last_version = version
|
11
11
|
master_version = versions[index]
|
12
12
|
columns.all? do |column|
|
13
13
|
if column==:current
|
@@ -29,12 +29,12 @@ RSpec::Matchers.define :have_versions do |versions_str|
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
failure_message do |master|
|
33
33
|
versions = master.versions_dataset.order(:id).all
|
34
|
-
if versions.size !=
|
35
|
-
"Expected #{master.class} to have #{
|
34
|
+
if versions.size != table.size
|
35
|
+
"Expected #{master.class} to have #{table.size} versions but found #{versions.size}"
|
36
36
|
else
|
37
|
-
"Expected row #{
|
37
|
+
"Expected row #{last_index+1} to match #{last_version.inspect} but found #{versions[last_index].inspect}"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_bitemporal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph HALTER
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sequel
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '3.
|
20
|
+
version: '3.41'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '5.0'
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '3.
|
30
|
+
version: '3.41'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '5.0'
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
40
|
+
version: 3.2.0
|
41
41
|
type: :development
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 3.2.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: timecop
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.4.5
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Bitemporal versioning for sequel.
|
@@ -133,3 +133,4 @@ test_files:
|
|
133
133
|
- spec/spec_helper.rb
|
134
134
|
- spec/support/bitemporal_matchers.rb
|
135
135
|
- spec/support/db.rb
|
136
|
+
has_rdoc:
|