sequel_bitemporal 0.8.1 → 0.8.2

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.
@@ -11,36 +11,36 @@ if DbHelpers.pg?
11
11
  Timecop.return
12
12
  end
13
13
  it "checks version class is given" do
14
- lambda{
14
+ expect{
15
15
  @version_class.plugin :bitemporal
16
- }.should raise_error Sequel::Error, "please specify version class to use for bitemporal plugin"
16
+ }.to raise_error Sequel::Error, "please specify version class to use for bitemporal plugin"
17
17
  end
18
18
  it "checks required columns are present" do
19
- lambda{
19
+ expect{
20
20
  @version_class.plugin :bitemporal, version_class: @master_class
21
- }.should raise_error Sequel::Error, "bitemporal plugin requires the following missing columns on version class: master_id, valid_from, valid_to, created_at, expired_at"
21
+ }.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"
22
22
  end
23
23
  it "propagates errors from version to master" do
24
24
  master = @master_class.new
25
- master.should be_valid
25
+ expect(master).to be_valid
26
26
  master.attributes = {name: "Single Standard"}
27
- master.should_not be_valid
28
- master.errors.should == {price: ["is required"]}
27
+ expect(master).not_to be_valid
28
+ expect(master.errors).to eq({price: ["is required"]})
29
29
  end
30
30
  it "#update_attributes returns false instead of raising errors" do
31
31
  master = @master_class.new
32
- master.update_attributes(name: "Single Standard").should be_false
33
- master.should be_new
34
- master.errors.should == {price: ["is required"]}
35
- master.update_attributes(price: 98).should be_true
32
+ expect(master.update_attributes(name: "Single Standard")).to be_falsey
33
+ expect(master).to be_new
34
+ expect(master.errors).to eq({price: ["is required"]})
35
+ expect(master.update_attributes(price: 98)).to be_truthy
36
36
  end
37
37
  it "allows creating a master and its first version in one step" do
38
38
  master = @master_class.new
39
39
  result = master.update_attributes name: "Single Standard", price: 98
40
- result.should be_true
41
- result.should == master
42
- master.should_not be_new
43
- master.should have_versions %Q{
40
+ expect(result).to be_truthy
41
+ expect(result).to eq(master)
42
+ expect(master).not_to be_new
43
+ expect(master).to have_versions %Q{
44
44
  | name | price | created_at | expired_at | valid_from | valid_to | current |
45
45
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
46
46
  }
@@ -48,7 +48,7 @@ if DbHelpers.pg?
48
48
  it "allows creating a new version in the past" do
49
49
  master = @master_class.new
50
50
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-1
51
- master.should have_versions %Q{
51
+ expect(master).to have_versions %Q{
52
52
  | name | price | created_at | expired_at | valid_from | valid_to | current |
53
53
  | Single Standard | 98 | 2009-11-28 | | 2009-11-27 | MAX DATE | true |
54
54
  }
@@ -56,7 +56,7 @@ if DbHelpers.pg?
56
56
  it "allows creating a new version in the future" do
57
57
  master = @master_class.new
58
58
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today+1
59
- master.should have_versions %Q{
59
+ expect(master).to have_versions %Q{
60
60
  | name | price | created_at | expired_at | valid_from | valid_to | current |
61
61
  | Single Standard | 98 | 2009-11-28 | | 2009-11-29 | MAX DATE | |
62
62
  }
@@ -65,7 +65,7 @@ if DbHelpers.pg?
65
65
  master = @master_class.new
66
66
  master.update_attributes name: "Single Standard", price: 98
67
67
  master.update_attributes name: "Single Standard", price: 94
68
- master.should have_versions %Q{
68
+ expect(master).to have_versions %Q{
69
69
  | name | price | created_at | expired_at | valid_from | valid_to | current |
70
70
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
71
71
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -76,7 +76,7 @@ if DbHelpers.pg?
76
76
  master.update_attributes name: "Single Standard", price: 98
77
77
  master.update_attributes price: 94
78
78
  master.update_attributes name: "King Size"
79
- master.should have_versions %Q{
79
+ expect(master).to have_versions %Q{
80
80
  | name | price | created_at | expired_at | valid_from | valid_to | current |
81
81
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
82
82
  | Single Standard | 94 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -88,7 +88,7 @@ if DbHelpers.pg?
88
88
  master.update_attributes name: "Single Standard", price: 98
89
89
  Timecop.freeze Date.today+1
90
90
  master.update_attributes price: 94
91
- master.should have_versions %Q{
91
+ expect(master).to have_versions %Q{
92
92
  | name | price | created_at | expired_at | valid_from | valid_to | current |
93
93
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
94
94
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -99,9 +99,9 @@ if DbHelpers.pg?
99
99
  master = @master_class.new
100
100
  master.update_attributes name: "Single Standard", price: 98, valid_to: Date.today+1
101
101
  Timecop.freeze Date.today+1
102
- master.update_attributes(price: 94).should be_false
102
+ expect(master.update_attributes(price: 94)).to be_falsey
103
103
  master.update_attributes name: "Single Standard", price: 94
104
- master.should have_versions %Q{
104
+ expect(master).to have_versions %Q{
105
105
  | name | price | created_at | expired_at | valid_from | valid_to | current |
106
106
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-29 | |
107
107
  | Single Standard | 94 | 2009-11-29 | | 2009-11-29 | MAX DATE | true |
@@ -112,7 +112,7 @@ if DbHelpers.pg?
112
112
  master.update_attributes name: "Single Standard", price: 98
113
113
  Timecop.freeze Date.today+1
114
114
  master.update_attributes valid_to: Date.today+10
115
- master.should have_versions %Q{
115
+ expect(master).to have_versions %Q{
116
116
  | name | price | created_at | expired_at | valid_from | valid_to | current |
117
117
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
118
118
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -127,12 +127,12 @@ if DbHelpers.pg?
127
127
  master = @master_class.new
128
128
  master.update_attributes name: "Single Standard", price: 98, valid_to: Date.today+2
129
129
  Timecop.freeze Date.today+1
130
- master.should have_versions %Q{
130
+ expect(master).to have_versions %Q{
131
131
  | name | price | created_at | expired_at | valid_from | valid_to | current |
132
132
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-30 | true |
133
133
  }
134
134
  master.update_attributes valid_to: nil
135
- master.should have_versions %Q{
135
+ expect(master).to have_versions %Q{
136
136
  | name | price | created_at | expired_at | valid_from | valid_to | current |
137
137
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
138
138
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -148,7 +148,7 @@ if DbHelpers.pg?
148
148
  master.update_attributes name: "Single Standard", price: 98
149
149
  master.update_attributes price: 98
150
150
  master.update_attributes name: "Single Standard", price: 98
151
- master.should have_versions %Q{
151
+ expect(master).to have_versions %Q{
152
152
  | name | price | created_at | expired_at | valid_from | valid_to | current |
153
153
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
154
154
  }
@@ -159,7 +159,7 @@ if DbHelpers.pg?
159
159
  Timecop.freeze Date.today+1
160
160
  master.update_attributes price: 98, valid_from: Date.today-2
161
161
  master.update_attributes price: 98, valid_from: Date.today+1
162
- master.should have_versions %Q{
162
+ expect(master).to have_versions %Q{
163
163
  | name | price | created_at | expired_at | valid_from | valid_to | current |
164
164
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
165
165
  | Single Standard | 98 | 2009-11-29 | | 2009-11-27 | 2009-11-28 | |
@@ -176,7 +176,7 @@ if DbHelpers.pg?
176
176
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
177
177
  Timecop.freeze Date.today+1
178
178
  master.update_attributes name: "King Size", valid_to: nil
179
- master.should have_versions %Q{
179
+ expect(master).to have_versions %Q{
180
180
  | name | price | created_at | expired_at | valid_from | valid_to | current |
181
181
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
182
182
  | Single Standard | 94 | 2009-11-28 | | 2009-11-30 | 2009-12-02 | |
@@ -192,7 +192,7 @@ if DbHelpers.pg?
192
192
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
193
193
  Timecop.freeze Date.today+1
194
194
  master.update_attributes name: "King Size", valid_to: Date.today+4
195
- master.should have_versions %Q{
195
+ expect(master).to have_versions %Q{
196
196
  | name | price | created_at | expired_at | valid_from | valid_to | current |
197
197
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
198
198
  | Single Standard | 94 | 2009-11-28 | 2009-11-29 | 2009-11-30 | 2009-12-02 | |
@@ -209,7 +209,7 @@ if DbHelpers.pg?
209
209
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
210
210
  Timecop.freeze Date.today+1
211
211
  master.update_attributes name: "King Size", valid_to: Time.utc(9999)
212
- master.should have_versions %Q{
212
+ expect(master).to have_versions %Q{
213
213
  | name | price | created_at | expired_at | valid_from | valid_to | current |
214
214
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
215
215
  | Single Standard | 94 | 2009-11-28 | 2009-11-29 | 2009-11-30 | 2009-12-02 | |
@@ -224,8 +224,8 @@ if DbHelpers.pg?
224
224
  master.update_attributes name: "Single Standard", price: 98
225
225
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
226
226
  Timecop.freeze Date.today+1
227
- master.current_version.destroy.should be_true
228
- master.should have_versions %Q{
227
+ expect(master.current_version.destroy).to be_truthy
228
+ expect(master).to have_versions %Q{
229
229
  | name | price | created_at | expired_at | valid_from | valid_to | current |
230
230
  | Single Standard | 92 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
231
231
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -240,8 +240,8 @@ if DbHelpers.pg?
240
240
  master.update_attributes name: "Single Standard", price: 98
241
241
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
242
242
  Timecop.freeze Date.today+1
243
- master.current_version.destroy(expand_previous_version: true).should be_true
244
- master.should have_versions %Q{
243
+ expect(master.current_version.destroy(expand_previous_version: true)).to be_truthy
244
+ expect(master).to have_versions %Q{
245
245
  | name | price | created_at | expired_at | valid_from | valid_to | current |
246
246
  | Single Standard | 92 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
247
247
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -256,8 +256,8 @@ if DbHelpers.pg?
256
256
  master.update_attributes name: "Single Standard", price: 98
257
257
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
258
258
  Timecop.freeze Date.today+1
259
- master.versions.last.destroy.should be_true
260
- master.should have_versions %Q{
259
+ expect(master.versions.last.destroy).to be_truthy
260
+ expect(master).to have_versions %Q{
261
261
  | name | price | created_at | expired_at | valid_from | valid_to | current |
262
262
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
263
263
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
@@ -270,8 +270,8 @@ if DbHelpers.pg?
270
270
  master.update_attributes name: "Single Standard", price: 98
271
271
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
272
272
  Timecop.freeze Date.today+1
273
- master.versions.last.destroy(expand_previous_version: false).should be_true
274
- master.should have_versions %Q{
273
+ expect(master.versions.last.destroy(expand_previous_version: false)).to be_truthy
274
+ expect(master).to have_versions %Q{
275
275
  | name | price | created_at | expired_at | valid_from | valid_to | current |
276
276
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
277
277
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-30 | true |
@@ -283,8 +283,8 @@ if DbHelpers.pg?
283
283
  master.update_attributes name: "Single Standard", price: 98
284
284
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
285
285
  Timecop.freeze Date.today+1
286
- master.destroy.should be_true
287
- master.should have_versions %Q{
286
+ expect(master.destroy).to be_truthy
287
+ expect(master).to have_versions %Q{
288
288
  | name | price | created_at | expired_at | valid_from | valid_to | current |
289
289
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
290
290
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
@@ -298,7 +298,7 @@ if DbHelpers.pg?
298
298
  master2 = @master_class.find id: master.id
299
299
  master.update_attributes name: "Single Standard", price: 94
300
300
  master2.update_attributes name: "Single Standard", price: 95
301
- master.should have_versions %Q{
301
+ expect(master).to have_versions %Q{
302
302
  | name | price | created_at | expired_at | valid_from | valid_to | current |
303
303
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
304
304
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -313,7 +313,7 @@ if DbHelpers.pg?
313
313
  master2 = @master_class.find id: master.id
314
314
  master.update_attributes price: 94
315
315
  master2.update_attributes name: "King Size"
316
- master.should have_versions %Q{
316
+ expect(master).to have_versions %Q{
317
317
  | name | price | created_at | expired_at | valid_from | valid_to | current |
318
318
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
319
319
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -324,11 +324,11 @@ if DbHelpers.pg?
324
324
  it "can expire invalid versions" do
325
325
  master = @master_class.new.update_attributes name: "Single Standard", price: 98
326
326
  master.current_version.price = nil
327
- master.current_version.should_not be_valid
327
+ expect(master.current_version).not_to be_valid
328
328
  master.current_version.save validate: false
329
329
  Timecop.freeze Date.today+1
330
330
  master.update_attributes price: 94
331
- master.should have_versions %Q{
331
+ expect(master).to have_versions %Q{
332
332
  | name | price | created_at | expired_at | valid_from | valid_to | current |
333
333
  | Single Standard | | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
334
334
  | Single Standard | | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -344,17 +344,17 @@ if DbHelpers.pg?
344
344
  initial_today = Date.today
345
345
  Timecop.freeze initial_today+1 do
346
346
  master.update_attributes valid_from: initial_today+4, name: "King Size", price: 15, length: 2, width: 2
347
- master.propagated_during_last_save.should have(0).item
347
+ expect(master.propagated_during_last_save.size).to eq(0)
348
348
  end
349
349
  Timecop.freeze initial_today+2 do
350
350
  master.update_attributes valid_from: initial_today+3, length: 1, width: 1
351
- master.propagated_during_last_save.should have(0).item
351
+ expect(master.propagated_during_last_save.size).to eq(0)
352
352
  end
353
353
  Timecop.freeze initial_today+3 do
354
354
  master.update_attributes valid_from: initial_today+2, length: 3, width: 4
355
- master.propagated_during_last_save.should have(1).item
355
+ expect(master.propagated_during_last_save.size).to eq(1)
356
356
  end
357
- master.should have_versions %Q{
357
+ expect(master).to have_versions %Q{
358
358
  | name | price | length | width | created_at | expired_at | valid_from | valid_to | current |
359
359
  | Single Standard | 12 | | 1 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
360
360
  | Single Standard | 12 | | 1 | 2009-11-29 | 2009-11-30 | 2009-11-28 | 2009-12-02 | |
@@ -373,10 +373,10 @@ if DbHelpers.pg?
373
373
  master = @master_class.new
374
374
  master.update_attributes name: "Single Standard", price: 98
375
375
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
376
- @master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.should be
376
+ expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be
377
377
  Timecop.freeze Date.today+1
378
378
  master.destroy
379
- @master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.should be_nil
379
+ expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be_nil
380
380
  end
381
381
  it "allows loading masters with a current version" do
382
382
  master_destroyed = @master_class.new
@@ -386,27 +386,27 @@ if DbHelpers.pg?
386
386
  master_with_current.update_attributes name: "Single Standard", price: 94
387
387
  master_with_future = @master_class.new
388
388
  master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
389
- @master_class.with_current_version.all.should have(1).item
389
+ expect(@master_class.with_current_version.all.size).to eq(1)
390
390
  end
391
391
  it "gets pending or current version attributes" do
392
392
  master = @master_class.new
393
- master.attributes.should == {}
394
- master.pending_version.should be_nil
395
- master.current_version.should be_nil
396
- master.name.should be_nil
393
+ expect(master.attributes).to eq({})
394
+ expect(master.pending_version).to be_nil
395
+ expect(master.current_version).to be_nil
396
+ expect(master.name).to be_nil
397
397
 
398
- master.pending_or_current_version.name.should be_nil
398
+ expect(master.pending_or_current_version.name).to be_nil
399
399
  master.update_attributes name: "Single Standard", price: 98
400
- master.attributes[:name].should == "Single Standard"
401
- master.pending_version.should be_nil
402
- master.pending_or_current_version.name.should == "Single Standard"
403
- master.name.should == "Single Standard"
400
+ expect(master.attributes[:name]).to eq("Single Standard")
401
+ expect(master.pending_version).to be_nil
402
+ expect(master.pending_or_current_version.name).to eq("Single Standard")
403
+ expect(master.name).to eq("Single Standard")
404
404
 
405
405
  master.attributes = {name: "King Size"}
406
- master.attributes[:name].should == "King Size"
407
- master.pending_version.should be
408
- master.pending_or_current_version.name.should == "King Size"
409
- master.name.should == "King Size"
406
+ expect(master.attributes[:name]).to eq("King Size")
407
+ expect(master.pending_version).to be
408
+ expect(master.pending_or_current_version.name).to eq("King Size")
409
+ expect(master.name).to eq("King Size")
410
410
  end
411
411
  it "allows to go back in time" do
412
412
  master = @master_class.new
@@ -417,7 +417,7 @@ if DbHelpers.pg?
417
417
  Timecop.freeze Date.today+1
418
418
  master.update_attributes price: 94
419
419
  master.update_attributes price: 96, valid_from: Date.today+2
420
- master.should have_versions %Q{
420
+ expect(master).to have_versions %Q{
421
421
  | name | price | created_at | expired_at | valid_from | valid_to | current |
422
422
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-29 | |
423
423
  | Single Standard | 95 | 2009-11-28 | 2009-11-29 | 2009-11-29 | 2009-11-30 | |
@@ -426,44 +426,44 @@ if DbHelpers.pg?
426
426
  | Single Standard | 94 | 2009-11-29 | | 2009-11-29 | 2009-11-30 | true |
427
427
  | Single Standard | 96 | 2009-11-29 | | 2009-12-01 | MAX DATE | |
428
428
  }
429
- master.current_version.price.should == 94
429
+ expect(master.current_version.price).to eq(94)
430
430
  Sequel::Plugins::Bitemporal.at(Date.today-1) do
431
- master.current_version(true).price.should == 98
431
+ expect(master.current_version(true).price).to eq(98)
432
432
  end
433
433
  Sequel::Plugins::Bitemporal.at(Date.today+1) do
434
- master.current_version(true).price.should == 93
434
+ expect(master.current_version(true).price).to eq(93)
435
435
  end
436
436
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
437
- master.current_version(true).price.should == 96
437
+ expect(master.current_version(true).price).to eq(96)
438
438
  end
439
439
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today-1) do
440
- master.current_version(true).price.should == 95
441
- master.current_version.should be_current
440
+ expect(master.current_version(true).price).to eq(95)
441
+ expect(master.current_version).to be_current
442
442
  Sequel::Plugins::Bitemporal.at(Date.today-1) do
443
- master.current_version(true).price.should == 98
443
+ expect(master.current_version(true).price).to eq(98)
444
444
  end
445
445
  Sequel::Plugins::Bitemporal.at(Date.today+1) do
446
- master.current_version(true).price.should == 93
446
+ expect(master.current_version(true).price).to eq(93)
447
447
  end
448
448
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
449
- master.current_version(true).price.should == 91
449
+ expect(master.current_version(true).price).to eq(91)
450
450
  end
451
451
  end
452
452
  end
453
453
  it "correctly reset time if failure when going back in time" do
454
454
  before = Sequel::Plugins::Bitemporal.now
455
- lambda do
455
+ expect do
456
456
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
457
457
  raise StandardError, "error during back in time"
458
458
  end
459
- end.should raise_error StandardError
460
- Sequel::Plugins::Bitemporal.now.should == before
461
- lambda do
459
+ end.to raise_error StandardError
460
+ expect(Sequel::Plugins::Bitemporal.now).to eq(before)
461
+ expect do
462
462
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
463
463
  raise StandardError, "error during back in time"
464
464
  end
465
- end.should raise_error StandardError
466
- Sequel::Plugins::Bitemporal.now.should == before
465
+ end.to raise_error StandardError
466
+ expect(Sequel::Plugins::Bitemporal.now).to eq(before)
467
467
  end
468
468
  it "allows eager loading with conditions on current or future versions" do
469
469
  master = @master_class.new
@@ -472,16 +472,16 @@ if DbHelpers.pg?
472
472
  master.update_attributes name: "Single Standard", price: 99
473
473
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
474
474
  res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 99}).all.first
475
- res.should be
476
- res.current_or_future_versions.should have(1).item
477
- res.current_or_future_versions.first.price.should == 99
475
+ expect(res).to be
476
+ expect(res.current_or_future_versions.size).to eq(1)
477
+ expect(res.current_or_future_versions.first.price).to eq(99)
478
478
  res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 94}).all.first
479
- res.should be
480
- res.current_or_future_versions.should have(1).item
481
- res.current_or_future_versions.first.price.should == 94
479
+ expect(res).to be
480
+ expect(res.current_or_future_versions.size).to eq(1)
481
+ expect(res.current_or_future_versions.first.price).to eq(94)
482
482
  Timecop.freeze Date.today+1
483
483
  master.destroy
484
- @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all.should be_empty
484
+ expect(@master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all).to be_empty
485
485
  end
486
486
  it "allows loading masters with current or future versions" do
487
487
  master_destroyed = @master_class.new
@@ -491,15 +491,15 @@ if DbHelpers.pg?
491
491
  master_with_current.update_attributes name: "Single Standard", price: 94
492
492
  master_with_future = @master_class.new
493
493
  master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
494
- @master_class.with_current_or_future_versions.all.should have(2).item
494
+ expect(@master_class.with_current_or_future_versions.all.size).to eq(2)
495
495
  end
496
496
  it "delegates attributes from master to pending_or_current_version" do
497
497
  master = @master_class.new
498
- master.name.should be_nil
498
+ expect(master.name).to be_nil
499
499
  master.update_attributes name: "Single Standard", price: 98
500
- master.name.should == "Single Standard"
500
+ expect(master.name).to eq("Single Standard")
501
501
  master.attributes = {name: "King Size"}
502
- master.name.should == "King Size"
502
+ expect(master.name).to eq("King Size")
503
503
  end
504
504
  it "avoids delegation with option delegate: false" do
505
505
  closure = @version_class
@@ -528,19 +528,19 @@ if DbHelpers.pg?
528
528
  master = @master_class.new.update_attributes name: "Single Standard", price: 98
529
529
  master.disabled = true
530
530
  master.update_attributes price: 94
531
- master.reload.disabled.should be_true
531
+ expect(master.reload.disabled).to be_truthy
532
532
  end
533
533
  it "uses current version for partial_update even if valid_from is specified" do
534
534
  master = @master_class.new
535
535
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
536
536
  master.update_attributes name: "Single Standard", price: 94
537
- master.should have_versions %Q{
537
+ expect(master).to have_versions %Q{
538
538
  | name | price | created_at | expired_at | valid_from | valid_to | current |
539
539
  | Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
540
540
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
541
541
  }
542
542
  master.update_attributes name: "King Size", valid_from: Date.today-2
543
- master.should have_versions %Q{
543
+ expect(master).to have_versions %Q{
544
544
  | name | price | created_at | expired_at | valid_from | valid_to | current |
545
545
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-26 | 2009-11-28 | |
546
546
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -553,7 +553,7 @@ if DbHelpers.pg?
553
553
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+1) do
554
554
  master.update_attributes name: "King Size"
555
555
  end
556
- master.should have_versions %Q{
556
+ expect(master).to have_versions %Q{
557
557
  | name | price | created_at | expired_at | valid_from | valid_to | current |
558
558
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
559
559
  | King Size | 98 | 2009-11-29 | | 2009-11-28 | MAX DATE | |
@@ -561,7 +561,7 @@ if DbHelpers.pg?
561
561
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
562
562
  master.current_version(true).destroy
563
563
  end
564
- master.should have_versions %Q{
564
+ expect(master).to have_versions %Q{
565
565
  | name | price | created_at | expired_at | valid_from | valid_to | current |
566
566
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
567
567
  | King Size | 98 | 2009-11-29 | 2009-11-30 | 2009-11-28 | MAX DATE | |
@@ -572,7 +572,7 @@ if DbHelpers.pg?
572
572
  master = @master_class.new
573
573
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
574
574
  master.update_attributes name: "Single Standard", price: 94
575
- master.should have_versions %Q{
575
+ expect(master).to have_versions %Q{
576
576
  | name | price | created_at | expired_at | valid_from | valid_to | current |
577
577
  | Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
578
578
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -582,7 +582,7 @@ if DbHelpers.pg?
582
582
  master.update_attributes name: "King Size"
583
583
  end
584
584
  end
585
- master.should have_versions %Q{
585
+ expect(master).to have_versions %Q{
586
586
  | name | price | created_at | expired_at | valid_from | valid_to | current |
587
587
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-26 | 2009-11-28 | |
588
588
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -593,32 +593,32 @@ if DbHelpers.pg?
593
593
  context "#deleted?" do
594
594
  subject{ @master_class.new }
595
595
  it "is false unless persisted" do
596
- subject.should_not be_deleted
596
+ expect(subject).not_to be_deleted
597
597
  end
598
598
  it "is false when persisted with a current version" do
599
- subject.update_attributes(name: "Single Standard", price: 94).should_not be_deleted
599
+ expect(subject.update_attributes(name: "Single Standard", price: 94)).not_to be_deleted
600
600
  end
601
601
  it "is true when persisted without a current version" do
602
- subject.update_attributes(name: "Single Standard", price: 94, valid_from: Date.today+1).should be_deleted
602
+ expect(subject.update_attributes(name: "Single Standard", price: 94, valid_from: Date.today+1)).to be_deleted
603
603
  end
604
604
  end
605
605
  context "#last_version" do
606
606
  subject{ @master_class.new }
607
607
  it "is nil unless persisted" do
608
- subject.last_version.should be_nil
608
+ expect(subject.last_version).to be_nil
609
609
  end
610
610
  it "is current version when persisted with a current version" do
611
611
  subject.update_attributes name: "Single Standard", price: 94
612
- subject.last_version.should == subject.current_version
612
+ expect(subject.last_version).to eq(subject.current_version)
613
613
  end
614
614
  it "is nil with future version but no current version" do
615
615
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+1
616
- subject.last_version.should be_nil
616
+ expect(subject.last_version).to be_nil
617
617
  end
618
618
  it "is last version with previous version but no current version" do
619
619
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
620
- subject.current_version.should be_nil
621
- subject.last_version.should == subject.versions.last
620
+ expect(subject.current_version).to be_nil
621
+ expect(subject.last_version).to eq(subject.versions.last)
622
622
  end
623
623
  end
624
624
  context "#restore" do
@@ -626,13 +626,13 @@ if DbHelpers.pg?
626
626
  it "make last version current" do
627
627
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
628
628
  subject.restore
629
- subject.current_version.should == subject.last_version
629
+ expect(subject.current_version).to eq(subject.last_version)
630
630
  end
631
631
  it "can add additional attributes to apply" do
632
632
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
633
633
  subject.restore name: "New Standard"
634
- subject.current_version.name.should == "New Standard"
635
- subject.current_version.price.should == 94
634
+ expect(subject.current_version.name).to eq("New Standard")
635
+ expect(subject.current_version.price).to eq(94)
636
636
  end
637
637
  end
638
638
  end
@@ -653,8 +653,8 @@ if DbHelpers.pg?
653
653
  let(:author){ double :author, audit_kind: "user" }
654
654
  it "generates a new audit on creation" do
655
655
  master = @master_class.new
656
- master.should_receive(:updated_by).and_return author
657
- @audit_class.should_receive(:audit).with(
656
+ expect(master).to receive(:updated_by).and_return author
657
+ expect(@audit_class).to receive(:audit).with(
658
658
  master,
659
659
  {},
660
660
  hash_including({name: "Single Standard", price: 98}),
@@ -665,9 +665,9 @@ if DbHelpers.pg?
665
665
  end
666
666
  it "generates a new audit on full update" do
667
667
  master = @master_class.new
668
- master.should_receive(:updated_by).twice.and_return author
668
+ expect(master).to receive(:updated_by).twice.and_return author
669
669
  master.update_attributes name: "Single Standard", price: 98
670
- @audit_class.should_receive(:audit).with(
670
+ expect(@audit_class).to receive(:audit).with(
671
671
  master,
672
672
  hash_including({name: "Single Standard", price: 98}),
673
673
  hash_including({name: "King size", price: 98}),
@@ -678,9 +678,9 @@ if DbHelpers.pg?
678
678
  end
679
679
  it "generates a new audit on partial update" do
680
680
  master = @master_class.new
681
- master.should_receive(:updated_by).twice.and_return author
681
+ expect(master).to receive(:updated_by).twice.and_return author
682
682
  master.update_attributes name: "Single Standard", price: 98
683
- @audit_class.should_receive(:audit).with(
683
+ expect(@audit_class).to receive(:audit).with(
684
684
  master,
685
685
  hash_including({name: "Single Standard", price: 98}),
686
686
  hash_including({name: "King size", price: 98}),
@@ -694,30 +694,30 @@ if DbHelpers.pg?
694
694
  begin
695
695
  @master_class.instance_variable_set :@propagate_per_column, true
696
696
  master = @master_class.new
697
- master.should_receive(:updated_by).exactly(8).times.and_return author
697
+ expect(master).to receive(:updated_by).exactly(8).times.and_return author
698
698
 
699
699
  master.update_attributes name: "Single Standard", price: 12, length: nil, width: 1
700
700
  initial_today = Date.today
701
701
  Timecop.freeze initial_today+1 do
702
702
  Sequel::Plugins::Bitemporal.at initial_today+4 do
703
703
  master.update_attributes valid_from: initial_today+4, name: "King Size", price: 15, length: 2, width: 2
704
- master.propagated_during_last_save.should have(0).item
704
+ expect(master.propagated_during_last_save.size).to eq(0)
705
705
  end
706
706
  end
707
707
  Timecop.freeze initial_today+2 do
708
708
  Sequel::Plugins::Bitemporal.at initial_today+3 do
709
709
  master.update_attributes valid_from: initial_today+3, length: 1, width: 1
710
- master.propagated_during_last_save.should have(0).item
710
+ expect(master.propagated_during_last_save.size).to eq(0)
711
711
  end
712
712
  end
713
- @audit_class.should_receive(:audit).with(
713
+ expect(@audit_class).to receive(:audit).with(
714
714
  master,
715
715
  hash_including({name: "Single Standard", price: 12, length: nil, width: 1}),
716
716
  hash_including({name: "Single Standard", price: 12, length: 3, width: 4}),
717
717
  initial_today+2,
718
718
  author
719
719
  )
720
- @audit_class.should_receive(:audit).with(
720
+ expect(@audit_class).to receive(:audit).with(
721
721
  master,
722
722
  hash_including({name: "Single Standard", price: 12, length: 1, width: 1}),
723
723
  hash_including({name: "Single Standard", price: 12, length: 1, width: 4}),
@@ -727,7 +727,7 @@ if DbHelpers.pg?
727
727
  Timecop.freeze initial_today+3 do
728
728
  Sequel::Plugins::Bitemporal.at initial_today+2 do
729
729
  master.update_attributes valid_from: initial_today+2, length: 3, width: 4
730
- master.propagated_during_last_save.should have(1).item
730
+ expect(master.propagated_during_last_save.size).to eq(1)
731
731
  end
732
732
  end
733
733
  ensure
@@ -751,8 +751,8 @@ if DbHelpers.pg?
751
751
  end
752
752
  it "generates a new audit on creation" do
753
753
  master = @master_class.new
754
- master.should_receive(:author).and_return author
755
- @audit_class.should_receive(:audit).with(
754
+ expect(master).to receive(:author).and_return author
755
+ expect(@audit_class).to receive(:audit).with(
756
756
  master,
757
757
  {},
758
758
  hash_including({name: "Single Standard", price: 98}),
@@ -763,9 +763,9 @@ if DbHelpers.pg?
763
763
  end
764
764
  it "generates a new audit on full update" do
765
765
  master = @master_class.new
766
- master.should_receive(:author).twice.and_return author
766
+ expect(master).to receive(:author).twice.and_return author
767
767
  master.update_attributes name: "Single Standard", price: 98
768
- @audit_class.should_receive(:audit).with(
768
+ expect(@audit_class).to receive(:audit).with(
769
769
  master,
770
770
  hash_including({name: "Single Standard", price: 98}),
771
771
  hash_including({name: "King size", price: 98}),
@@ -776,9 +776,9 @@ if DbHelpers.pg?
776
776
  end
777
777
  it "generates a new audit on partial update" do
778
778
  master = @master_class.new
779
- master.should_receive(:author).twice.and_return author
779
+ expect(master).to receive(:author).twice.and_return author
780
780
  master.update_attributes name: "Single Standard", price: 98
781
- @audit_class.should_receive(:audit).with(
781
+ expect(@audit_class).to receive(:audit).with(
782
782
  master,
783
783
  hash_including({name: "Single Standard", price: 98}),
784
784
  hash_including({name: "King size", price: 98}),