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,44 +11,44 @@ describe "Sequel::Plugins::Bitemporal" do
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 "defines current_versions_dataset" do
24
24
  @master_class.new.
25
25
  update_attributes(name: "Single Standard", price: 98).
26
26
  update_attributes(name: "King Size")
27
27
  versions = @master_class.current_versions_dataset.all
28
- versions.should have(1).version
29
- versions[0].name.should == "King Size"
28
+ expect(versions.size).to eq(1)
29
+ expect(versions[0].name).to eq("King Size")
30
30
  end
31
31
  it "propagates errors from version to master" do
32
32
  master = @master_class.new
33
- master.should be_valid
33
+ expect(master).to be_valid
34
34
  master.attributes = {name: "Single Standard"}
35
- master.should_not be_valid
36
- master.errors.should == {price: ["is required"]}
35
+ expect(master).not_to be_valid
36
+ expect(master.errors).to eq({price: ["is required"]})
37
37
  end
38
38
  it "#update_attributes returns false instead of raising errors" do
39
39
  master = @master_class.new
40
- master.update_attributes(name: "Single Standard").should be_false
41
- master.should be_new
42
- master.errors.should == {price: ["is required"]}
43
- master.update_attributes(price: 98).should be_true
40
+ expect(master.update_attributes(name: "Single Standard")).to be_falsey
41
+ expect(master).to be_new
42
+ expect(master.errors).to eq({price: ["is required"]})
43
+ expect(master.update_attributes(price: 98)).to be_truthy
44
44
  end
45
45
  it "allows creating a master and its first version in one step" do
46
46
  master = @master_class.new
47
47
  result = master.update_attributes name: "Single Standard", price: 98
48
- result.should be_true
49
- result.should == master
50
- master.should_not be_new
51
- master.should have_versions %Q{
48
+ expect(result).to be_truthy
49
+ expect(result).to eq(master)
50
+ expect(master).not_to be_new
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-28 | MAX DATE | true |
54
54
  }
@@ -56,7 +56,7 @@ describe "Sequel::Plugins::Bitemporal" do
56
56
  it "allows creating a new version in the past" 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-27 | MAX DATE | true |
62
62
  }
@@ -64,7 +64,7 @@ describe "Sequel::Plugins::Bitemporal" do
64
64
  it "allows creating a new version in the future" do
65
65
  master = @master_class.new
66
66
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today+1
67
- master.should have_versions %Q{
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 | | 2009-11-29 | MAX DATE | |
70
70
  }
@@ -73,7 +73,7 @@ describe "Sequel::Plugins::Bitemporal" do
73
73
  master = @master_class.new
74
74
  master.update_attributes name: "Single Standard", price: 98
75
75
  master.update_attributes name: "Single Standard", price: 94
76
- master.should have_versions %Q{
76
+ expect(master).to have_versions %Q{
77
77
  | name | price | created_at | expired_at | valid_from | valid_to | current |
78
78
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
79
79
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -84,7 +84,7 @@ describe "Sequel::Plugins::Bitemporal" do
84
84
  master.update_attributes name: "Single Standard", price: 98
85
85
  master.update_attributes price: 94
86
86
  master.update_attributes name: "King Size"
87
- master.should have_versions %Q{
87
+ expect(master).to have_versions %Q{
88
88
  | name | price | created_at | expired_at | valid_from | valid_to | current |
89
89
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
90
90
  | Single Standard | 94 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -96,7 +96,7 @@ describe "Sequel::Plugins::Bitemporal" do
96
96
  master.update_attributes name: "Single Standard", price: 98
97
97
  Timecop.freeze Date.today+1
98
98
  master.update_attributes price: 94
99
- master.should have_versions %Q{
99
+ expect(master).to have_versions %Q{
100
100
  | name | price | created_at | expired_at | valid_from | valid_to | current |
101
101
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
102
102
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -107,9 +107,9 @@ describe "Sequel::Plugins::Bitemporal" do
107
107
  master = @master_class.new
108
108
  master.update_attributes name: "Single Standard", price: 98, valid_to: Date.today+1
109
109
  Timecop.freeze Date.today+1
110
- master.update_attributes(price: 94).should be_false
110
+ expect(master.update_attributes(price: 94)).to be_falsey
111
111
  master.update_attributes name: "Single Standard", price: 94
112
- master.should have_versions %Q{
112
+ expect(master).to have_versions %Q{
113
113
  | name | price | created_at | expired_at | valid_from | valid_to | current |
114
114
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-29 | |
115
115
  | Single Standard | 94 | 2009-11-29 | | 2009-11-29 | MAX DATE | true |
@@ -120,7 +120,7 @@ describe "Sequel::Plugins::Bitemporal" do
120
120
  master.update_attributes name: "Single Standard", price: 98
121
121
  Timecop.freeze Date.today+1
122
122
  master.update_attributes valid_to: Date.today+10
123
- master.should have_versions %Q{
123
+ expect(master).to have_versions %Q{
124
124
  | name | price | created_at | expired_at | valid_from | valid_to | current |
125
125
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
126
126
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -135,12 +135,12 @@ describe "Sequel::Plugins::Bitemporal" do
135
135
  master = @master_class.new
136
136
  master.update_attributes name: "Single Standard", price: 98, valid_to: Date.today+2
137
137
  Timecop.freeze Date.today+1
138
- master.should have_versions %Q{
138
+ expect(master).to have_versions %Q{
139
139
  | name | price | created_at | expired_at | valid_from | valid_to | current |
140
140
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-30 | true |
141
141
  }
142
142
  master.update_attributes valid_to: nil
143
- master.should have_versions %Q{
143
+ expect(master).to have_versions %Q{
144
144
  | name | price | created_at | expired_at | valid_from | valid_to | current |
145
145
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
146
146
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -156,7 +156,7 @@ describe "Sequel::Plugins::Bitemporal" do
156
156
  master.update_attributes name: "Single Standard", price: 98
157
157
  master.update_attributes price: 98
158
158
  master.update_attributes name: "Single Standard", price: 98
159
- master.should have_versions %Q{
159
+ expect(master).to have_versions %Q{
160
160
  | name | price | created_at | expired_at | valid_from | valid_to | current |
161
161
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
162
162
  }
@@ -167,7 +167,7 @@ describe "Sequel::Plugins::Bitemporal" do
167
167
  Timecop.freeze Date.today+1
168
168
  master.update_attributes price: 98, valid_from: Date.today-2
169
169
  master.update_attributes price: 98, valid_from: Date.today+1
170
- master.should have_versions %Q{
170
+ expect(master).to have_versions %Q{
171
171
  | name | price | created_at | expired_at | valid_from | valid_to | current |
172
172
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
173
173
  | Single Standard | 98 | 2009-11-29 | | 2009-11-27 | 2009-11-28 | |
@@ -184,7 +184,7 @@ describe "Sequel::Plugins::Bitemporal" do
184
184
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
185
185
  Timecop.freeze Date.today+1
186
186
  master.update_attributes name: "King Size", valid_to: nil
187
- master.should have_versions %Q{
187
+ expect(master).to have_versions %Q{
188
188
  | name | price | created_at | expired_at | valid_from | valid_to | current |
189
189
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
190
190
  | Single Standard | 94 | 2009-11-28 | | 2009-11-30 | 2009-12-02 | |
@@ -200,7 +200,7 @@ describe "Sequel::Plugins::Bitemporal" do
200
200
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
201
201
  Timecop.freeze Date.today+1
202
202
  master.update_attributes name: "King Size", valid_to: Date.today+4
203
- master.should have_versions %Q{
203
+ expect(master).to have_versions %Q{
204
204
  | name | price | created_at | expired_at | valid_from | valid_to | current |
205
205
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
206
206
  | Single Standard | 94 | 2009-11-28 | 2009-11-29 | 2009-11-30 | 2009-12-02 | |
@@ -217,7 +217,7 @@ describe "Sequel::Plugins::Bitemporal" do
217
217
  master.update_attributes name: "Single Standard", price: 95, valid_from: Date.today+4, valid_to: Date.today+6
218
218
  Timecop.freeze Date.today+1
219
219
  master.update_attributes name: "King Size", valid_to: Time.utc(9999)
220
- master.should have_versions %Q{
220
+ expect(master).to have_versions %Q{
221
221
  | name | price | created_at | expired_at | valid_from | valid_to | current |
222
222
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
223
223
  | Single Standard | 94 | 2009-11-28 | 2009-11-29 | 2009-11-30 | 2009-12-02 | |
@@ -232,8 +232,8 @@ describe "Sequel::Plugins::Bitemporal" do
232
232
  master.update_attributes name: "Single Standard", price: 98
233
233
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
234
234
  Timecop.freeze Date.today+1
235
- master.current_version.destroy.should be_true
236
- master.should have_versions %Q{
235
+ expect(master.current_version.destroy).to be_truthy
236
+ expect(master).to have_versions %Q{
237
237
  | name | price | created_at | expired_at | valid_from | valid_to | current |
238
238
  | Single Standard | 92 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
239
239
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -241,7 +241,7 @@ describe "Sequel::Plugins::Bitemporal" do
241
241
  | Single Standard | 94 | 2009-11-28 | | 2009-11-30 | MAX DATE | |
242
242
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
243
243
  }
244
- master.should be_deleted
244
+ expect(master).to be_deleted
245
245
  end
246
246
  it "allows deleting current version to restore the previous one" do
247
247
  master = @master_class.new
@@ -249,8 +249,8 @@ describe "Sequel::Plugins::Bitemporal" do
249
249
  master.update_attributes name: "Single Standard", price: 98
250
250
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
251
251
  Timecop.freeze Date.today+1
252
- master.current_version.destroy(expand_previous_version: true).should be_true
253
- master.should have_versions %Q{
252
+ expect(master.current_version.destroy(expand_previous_version: true)).to be_truthy
253
+ expect(master).to have_versions %Q{
254
254
  | name | price | created_at | expired_at | valid_from | valid_to | current |
255
255
  | Single Standard | 92 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
256
256
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
@@ -265,8 +265,8 @@ describe "Sequel::Plugins::Bitemporal" do
265
265
  master.update_attributes name: "Single Standard", price: 98
266
266
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
267
267
  Timecop.freeze Date.today+1
268
- master.versions.last.destroy.should be_true
269
- master.should have_versions %Q{
268
+ expect(master.versions.last.destroy).to be_truthy
269
+ expect(master).to have_versions %Q{
270
270
  | name | price | created_at | expired_at | valid_from | valid_to | current |
271
271
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
272
272
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
@@ -279,8 +279,8 @@ describe "Sequel::Plugins::Bitemporal" do
279
279
  master.update_attributes name: "Single Standard", price: 98
280
280
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
281
281
  Timecop.freeze Date.today+1
282
- master.versions.last.destroy(expand_previous_version: false).should be_true
283
- master.should have_versions %Q{
282
+ expect(master.versions.last.destroy(expand_previous_version: false)).to be_truthy
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 | 2009-11-28 | 2009-11-28 | MAX DATE | |
286
286
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-30 | true |
@@ -292,8 +292,8 @@ describe "Sequel::Plugins::Bitemporal" do
292
292
  master.update_attributes name: "Single Standard", price: 98
293
293
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
294
294
  Timecop.freeze Date.today+1
295
- master.destroy.should be_true
296
- master.should have_versions %Q{
295
+ expect(master.destroy).to be_truthy
296
+ expect(master).to have_versions %Q{
297
297
  | name | price | created_at | expired_at | valid_from | valid_to | current |
298
298
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-28 | MAX DATE | |
299
299
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
@@ -307,7 +307,7 @@ describe "Sequel::Plugins::Bitemporal" do
307
307
  master2 = @master_class.find id: master.id
308
308
  master.update_attributes name: "Single Standard", price: 94
309
309
  master2.update_attributes name: "Single Standard", price: 95
310
- master.should have_versions %Q{
310
+ expect(master).to have_versions %Q{
311
311
  | name | price | created_at | expired_at | valid_from | valid_to | current |
312
312
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
313
313
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -322,7 +322,7 @@ describe "Sequel::Plugins::Bitemporal" do
322
322
  master2 = @master_class.find id: master.id
323
323
  master.update_attributes price: 94
324
324
  master2.update_attributes name: "King Size"
325
- master.should have_versions %Q{
325
+ expect(master).to have_versions %Q{
326
326
  | name | price | created_at | expired_at | valid_from | valid_to | current |
327
327
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
328
328
  | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -333,11 +333,11 @@ describe "Sequel::Plugins::Bitemporal" do
333
333
  it "can expire invalid versions" do
334
334
  master = @master_class.new.update_attributes name: "Single Standard", price: 98
335
335
  master.current_version.price = nil
336
- master.current_version.should_not be_valid
336
+ expect(master.current_version).not_to be_valid
337
337
  master.current_version.save validate: false
338
338
  Timecop.freeze Date.today+1
339
339
  master.update_attributes price: 94
340
- master.should have_versions %Q{
340
+ expect(master).to have_versions %Q{
341
341
  | name | price | created_at | expired_at | valid_from | valid_to | current |
342
342
  | Single Standard | | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
343
343
  | Single Standard | | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
@@ -353,17 +353,17 @@ describe "Sequel::Plugins::Bitemporal" do
353
353
  initial_today = Date.today
354
354
  Timecop.freeze initial_today+1 do
355
355
  master.update_attributes valid_from: initial_today+4, name: "King Size", price: 15, length: 2, width: 2
356
- master.propagated_during_last_save.should have(0).item
356
+ expect(master.propagated_during_last_save.size).to eq(0)
357
357
  end
358
358
  Timecop.freeze initial_today+2 do
359
359
  master.update_attributes valid_from: initial_today+3, length: 1, width: 1
360
- master.propagated_during_last_save.should have(0).item
360
+ expect(master.propagated_during_last_save.size).to eq(0)
361
361
  end
362
362
  Timecop.freeze initial_today+3 do
363
363
  master.update_attributes valid_from: initial_today+2, length: 3, width: 4
364
- master.propagated_during_last_save.should have(1).item
364
+ expect(master.propagated_during_last_save.size).to eq(1)
365
365
  end
366
- master.should have_versions %Q{
366
+ expect(master).to have_versions %Q{
367
367
  | name | price | length | width | created_at | expired_at | valid_from | valid_to | current |
368
368
  | Single Standard | 12 | | 1 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
369
369
  | Single Standard | 12 | | 1 | 2009-11-29 | 2009-11-30 | 2009-11-28 | 2009-12-02 | |
@@ -378,14 +378,26 @@ describe "Sequel::Plugins::Bitemporal" do
378
378
  @master_class.instance_variable_set :@propagate_per_column, propagate_per_column
379
379
  end
380
380
  end
381
- it "allows eager loading with conditions on current version" do
381
+ it "allows eager graphing with conditions on current version" do
382
382
  master = @master_class.new
383
383
  master.update_attributes name: "Single Standard", price: 98
384
384
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
385
- @master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.should be
385
+ expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be
386
386
  Timecop.freeze Date.today+1
387
387
  master.destroy
388
- @master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first.should be_nil
388
+ expect(@master_class.eager_graph(:current_version).where("rooms_current_version.id IS NOT NULL").first).to be_nil
389
+ end
390
+ it "allows eager loading via a separate query" do
391
+ master = @master_class.new
392
+ master.update_attributes name: "Single Standard", price: 98
393
+ master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
394
+ result = @master_class.eager(:current_version).all.first
395
+ expect(result.associations[:current_version]).not_to be_nil
396
+ expect(result.current_version.price).to eq(98)
397
+ ::Sequel::Plugins::Bitemporal.as_we_knew_it Date.today-1 do
398
+ result = @master_class.eager(:current_version).all.first
399
+ expect(result.associations[:current_version]).to be_nil
400
+ end
389
401
  end
390
402
  it "allows loading masters with a current version" do
391
403
  master_destroyed = @master_class.new
@@ -395,27 +407,27 @@ describe "Sequel::Plugins::Bitemporal" do
395
407
  master_with_current.update_attributes name: "Single Standard", price: 94
396
408
  master_with_future = @master_class.new
397
409
  master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
398
- @master_class.with_current_version.all.should have(1).item
410
+ expect(@master_class.with_current_version.all.size).to eq(1)
399
411
  end
400
412
  it "gets pending or current version attributes" do
401
413
  master = @master_class.new
402
- master.attributes.should == {}
403
- master.pending_version.should be_nil
404
- master.current_version.should be_nil
405
- master.name.should be_nil
414
+ expect(master.attributes).to eq({})
415
+ expect(master.pending_version).to be_nil
416
+ expect(master.current_version).to be_nil
417
+ expect(master.name).to be_nil
406
418
 
407
- master.pending_or_current_version.name.should be_nil
419
+ expect(master.pending_or_current_version.name).to be_nil
408
420
  master.update_attributes name: "Single Standard", price: 98
409
- master.attributes[:name].should == "Single Standard"
410
- master.pending_version.should be_nil
411
- master.pending_or_current_version.name.should == "Single Standard"
412
- master.name.should == "Single Standard"
421
+ expect(master.attributes[:name]).to eq("Single Standard")
422
+ expect(master.pending_version).to be_nil
423
+ expect(master.pending_or_current_version.name).to eq("Single Standard")
424
+ expect(master.name).to eq("Single Standard")
413
425
 
414
426
  master.attributes = {name: "King Size"}
415
- master.attributes[:name].should == "King Size"
416
- master.pending_version.should be
417
- master.pending_or_current_version.name.should == "King Size"
418
- master.name.should == "King Size"
427
+ expect(master.attributes[:name]).to eq("King Size")
428
+ expect(master.pending_version).to be
429
+ expect(master.pending_or_current_version.name).to eq("King Size")
430
+ expect(master.name).to eq("King Size")
419
431
  end
420
432
  it "allows creating a new version before all other versions in case of propagation per column" do
421
433
  propagate_per_column = @master_class.propagate_per_column
@@ -425,9 +437,9 @@ describe "Sequel::Plugins::Bitemporal" do
425
437
  master.update_attributes name: "Single Standard", price: 98
426
438
  Timecop.freeze Date.today - 100 do
427
439
  master.update_attributes name: "Single Standard", price: 95
428
- master.propagated_during_last_save.should have(0).item
440
+ expect(master.propagated_during_last_save.size).to eq(0)
429
441
  end
430
- master.should have_versions %Q{
442
+ expect(master).to have_versions %Q{
431
443
  | name | price | created_at | expired_at | valid_from | valid_to | current |
432
444
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
433
445
  | Single Standard | 95 | 2009-08-20 | | 2009-08-20 | 2009-11-28 | |
@@ -445,7 +457,7 @@ describe "Sequel::Plugins::Bitemporal" do
445
457
  Timecop.freeze Date.today+1
446
458
  master.update_attributes price: 94
447
459
  master.update_attributes price: 96, valid_from: Date.today+2
448
- master.should have_versions %Q{
460
+ expect(master).to have_versions %Q{
449
461
  | name | price | created_at | expired_at | valid_from | valid_to | current |
450
462
  | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-29 | |
451
463
  | Single Standard | 95 | 2009-11-28 | 2009-11-29 | 2009-11-29 | 2009-11-30 | |
@@ -454,44 +466,44 @@ describe "Sequel::Plugins::Bitemporal" do
454
466
  | Single Standard | 94 | 2009-11-29 | | 2009-11-29 | 2009-11-30 | true |
455
467
  | Single Standard | 96 | 2009-11-29 | | 2009-12-01 | MAX DATE | |
456
468
  }
457
- master.current_version.price.should == 94
469
+ expect(master.current_version.price).to eq(94)
458
470
  Sequel::Plugins::Bitemporal.at(Date.today-1) do
459
- master.current_version(true).price.should == 98
471
+ expect(master.current_version(true).price).to eq(98)
460
472
  end
461
473
  Sequel::Plugins::Bitemporal.at(Date.today+1) do
462
- master.current_version(true).price.should == 93
474
+ expect(master.current_version(true).price).to eq(93)
463
475
  end
464
476
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
465
- master.current_version(true).price.should == 96
477
+ expect(master.current_version(true).price).to eq(96)
466
478
  end
467
479
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today-1) do
468
- master.current_version(true).price.should == 95
469
- master.current_version.should be_current
480
+ expect(master.current_version(true).price).to eq(95)
481
+ expect(master.current_version).to be_current
470
482
  Sequel::Plugins::Bitemporal.at(Date.today-1) do
471
- master.current_version(true).price.should == 98
483
+ expect(master.current_version(true).price).to eq(98)
472
484
  end
473
485
  Sequel::Plugins::Bitemporal.at(Date.today+1) do
474
- master.current_version(true).price.should == 93
486
+ expect(master.current_version(true).price).to eq(93)
475
487
  end
476
488
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
477
- master.current_version(true).price.should == 91
489
+ expect(master.current_version(true).price).to eq(91)
478
490
  end
479
491
  end
480
492
  end
481
493
  it "correctly reset time if failure when going back in time" do
482
494
  before = Sequel::Plugins::Bitemporal.now
483
- lambda do
495
+ expect do
484
496
  Sequel::Plugins::Bitemporal.at(Date.today+2) do
485
497
  raise StandardError, "error during back in time"
486
498
  end
487
- end.should raise_error StandardError
488
- Sequel::Plugins::Bitemporal.now.should == before
489
- lambda do
499
+ end.to raise_error StandardError
500
+ expect(Sequel::Plugins::Bitemporal.now).to eq(before)
501
+ expect do
490
502
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
491
503
  raise StandardError, "error during back in time"
492
504
  end
493
- end.should raise_error StandardError
494
- Sequel::Plugins::Bitemporal.now.should == before
505
+ end.to raise_error StandardError
506
+ expect(Sequel::Plugins::Bitemporal.now).to eq(before)
495
507
  end
496
508
  it "allows eager loading with conditions on current or future versions" do
497
509
  master = @master_class.new
@@ -500,16 +512,16 @@ describe "Sequel::Plugins::Bitemporal" do
500
512
  master.update_attributes name: "Single Standard", price: 99
501
513
  master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
502
514
  res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 99}).all.first
503
- res.should be
504
- res.current_or_future_versions.should have(1).item
505
- res.current_or_future_versions.first.price.should == 99
515
+ expect(res).to be
516
+ expect(res.current_or_future_versions.size).to eq(1)
517
+ expect(res.current_or_future_versions.first.price).to eq(99)
506
518
  res = @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil) & {price: 94}).all.first
507
- res.should be
508
- res.current_or_future_versions.should have(1).item
509
- res.current_or_future_versions.first.price.should == 94
519
+ expect(res).to be
520
+ expect(res.current_or_future_versions.size).to eq(1)
521
+ expect(res.current_or_future_versions.first.price).to eq(94)
510
522
  Timecop.freeze Date.today+1
511
523
  master.destroy
512
- @master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all.should be_empty
524
+ expect(@master_class.eager_graph(:current_or_future_versions).where(Sequel.negate(current_or_future_versions__id: nil)).all).to be_empty
513
525
  end
514
526
  it "allows loading masters with current or future versions" do
515
527
  master_destroyed = @master_class.new
@@ -519,16 +531,16 @@ describe "Sequel::Plugins::Bitemporal" do
519
531
  master_with_current.update_attributes name: "Single Standard", price: 94
520
532
  master_with_future = @master_class.new
521
533
  master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
522
- @master_class.with_current_or_future_versions.all.should have(2).item
534
+ expect(@master_class.with_current_or_future_versions.all.size).to eq(2)
523
535
  end
524
536
  it "delegates attributes from master to pending_or_current_version" do
525
537
  master = @master_class.new
526
- master.name.should be_nil
538
+ expect(master.name).to be_nil
527
539
  master.update_attributes name: "Single Standard", price: 98
528
- master.name.should == "Single Standard"
540
+ expect(master.name).to eq("Single Standard")
529
541
  master.attributes = {name: "King Size"}
530
- master.name.should == "King Size"
531
- master.price.should == 98
542
+ expect(master.name).to eq("King Size")
543
+ expect(master.price).to eq(98)
532
544
  end
533
545
  it "avoids delegation with option delegate: false" do
534
546
  closure = @version_class
@@ -550,7 +562,7 @@ describe "Sequel::Plugins::Bitemporal" do
550
562
  master = without_delegation_class.new
551
563
  master.attributes = {name: "Single Standard", price: 98}
552
564
  expect{ master.name }.to raise_error NoMethodError
553
- master.price.should == 98
565
+ expect(master.price).to eq(98)
554
566
  end
555
567
  it "avoids delegation of columns which are both in master and version" do
556
568
  closure = @version_class
@@ -564,8 +576,8 @@ describe "Sequel::Plugins::Bitemporal" do
564
576
  end
565
577
  master = without_delegation_class.new name: "Master Hotel"
566
578
  master.attributes = {name: "Single Standard", price: 98}
567
- master.name.should == "Master Hotel"
568
- master.price.should == 98
579
+ expect(master.name).to eq("Master Hotel")
580
+ expect(master.price).to eq(98)
569
581
  DB.drop_table :rooms_with_name
570
582
  end
571
583
  it "get current_version association name from class name" do
@@ -586,19 +598,19 @@ describe "Sequel::Plugins::Bitemporal" do
586
598
  master = @master_class.new.update_attributes name: "Single Standard", price: 98
587
599
  master.disabled = true
588
600
  master.update_attributes price: 94
589
- master.reload.disabled.should be_true
601
+ expect(master.reload.disabled).to be_truthy
590
602
  end
591
603
  it "uses current version for partial_update even if valid_from is specified" do
592
604
  master = @master_class.new
593
605
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
594
606
  master.update_attributes name: "Single Standard", price: 94
595
- master.should have_versions %Q{
607
+ expect(master).to have_versions %Q{
596
608
  | name | price | created_at | expired_at | valid_from | valid_to | current |
597
609
  | Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
598
610
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
599
611
  }
600
612
  master.update_attributes name: "King Size", valid_from: Date.today-2
601
- master.should have_versions %Q{
613
+ expect(master).to have_versions %Q{
602
614
  | name | price | created_at | expired_at | valid_from | valid_to | current |
603
615
  | Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-26 | 2009-11-28 | |
604
616
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -611,7 +623,7 @@ describe "Sequel::Plugins::Bitemporal" do
611
623
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+1) do
612
624
  master.update_attributes name: "King Size"
613
625
  end
614
- master.should have_versions %Q{
626
+ expect(master).to have_versions %Q{
615
627
  | name | price | created_at | expired_at | valid_from | valid_to | current |
616
628
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
617
629
  | King Size | 98 | 2009-11-29 | | 2009-11-28 | MAX DATE | |
@@ -619,7 +631,7 @@ describe "Sequel::Plugins::Bitemporal" do
619
631
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
620
632
  master.current_version(true).destroy
621
633
  end
622
- master.should have_versions %Q{
634
+ expect(master).to have_versions %Q{
623
635
  | name | price | created_at | expired_at | valid_from | valid_to | current |
624
636
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
625
637
  | King Size | 98 | 2009-11-29 | 2009-11-30 | 2009-11-28 | MAX DATE | |
@@ -630,7 +642,7 @@ describe "Sequel::Plugins::Bitemporal" do
630
642
  master = @master_class.new
631
643
  master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
632
644
  master.update_attributes name: "Single Standard", price: 94
633
- master.should have_versions %Q{
645
+ expect(master).to have_versions %Q{
634
646
  | name | price | created_at | expired_at | valid_from | valid_to | current |
635
647
  | Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
636
648
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -640,7 +652,7 @@ describe "Sequel::Plugins::Bitemporal" do
640
652
  master.update_attributes name: "King Size"
641
653
  end
642
654
  end
643
- master.should have_versions %Q{
655
+ expect(master).to have_versions %Q{
644
656
  | name | price | created_at | expired_at | valid_from | valid_to | current |
645
657
  | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-26 | 2009-11-28 | |
646
658
  | Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
@@ -651,32 +663,32 @@ describe "Sequel::Plugins::Bitemporal" do
651
663
  context "#deleted?" do
652
664
  subject{ @master_class.new }
653
665
  it "is false unless persisted" do
654
- subject.should_not be_deleted
666
+ expect(subject).not_to be_deleted
655
667
  end
656
668
  it "is false when persisted with a current version" do
657
- subject.update_attributes(name: "Single Standard", price: 94).should_not be_deleted
669
+ expect(subject.update_attributes(name: "Single Standard", price: 94)).not_to be_deleted
658
670
  end
659
671
  it "is true when persisted without a current version" do
660
- subject.update_attributes(name: "Single Standard", price: 94, valid_from: Date.today+1).should be_deleted
672
+ expect(subject.update_attributes(name: "Single Standard", price: 94, valid_from: Date.today+1)).to be_deleted
661
673
  end
662
674
  end
663
675
  context "#last_version" do
664
676
  subject{ @master_class.new }
665
677
  it "is nil unless persisted" do
666
- subject.last_version.should be_nil
678
+ expect(subject.last_version).to be_nil
667
679
  end
668
680
  it "is current version when persisted with a current version" do
669
681
  subject.update_attributes name: "Single Standard", price: 94
670
- subject.last_version.should == subject.current_version
682
+ expect(subject.last_version).to eq(subject.current_version)
671
683
  end
672
684
  it "is nil with future version but no current version" do
673
685
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+1
674
- subject.last_version.should be_nil
686
+ expect(subject.last_version).to be_nil
675
687
  end
676
688
  it "is last version with previous version but no current version" do
677
689
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
678
- subject.current_version.should be_nil
679
- subject.last_version.should == subject.versions.last
690
+ expect(subject.current_version).to be_nil
691
+ expect(subject.last_version).to eq(subject.versions.last)
680
692
  end
681
693
  end
682
694
  context "#restore" do
@@ -684,13 +696,13 @@ describe "Sequel::Plugins::Bitemporal" do
684
696
  it "make last version current" do
685
697
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
686
698
  subject.restore
687
- subject.current_version.should == subject.last_version
699
+ expect(subject.current_version).to eq(subject.last_version)
688
700
  end
689
701
  it "can add additional attributes to apply" do
690
702
  subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today-2, valid_to: Date.today-1
691
703
  subject.restore name: "New Standard"
692
- subject.current_version.name.should == "New Standard"
693
- subject.current_version.price.should == 94
704
+ expect(subject.current_version.name).to eq("New Standard")
705
+ expect(subject.current_version.price).to eq(94)
694
706
  end
695
707
  end
696
708
  end
@@ -711,8 +723,8 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
711
723
  let(:author){ double :author, audit_kind: "user" }
712
724
  it "generates a new audit on creation" do
713
725
  master = @master_class.new
714
- master.should_receive(:updated_by).and_return author
715
- @audit_class.should_receive(:audit).with(
726
+ expect(master).to receive(:updated_by).and_return author
727
+ expect(@audit_class).to receive(:audit).with(
716
728
  master,
717
729
  {},
718
730
  hash_including({name: "Single Standard", price: 98}),
@@ -723,9 +735,9 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
723
735
  end
724
736
  it "generates a new audit on full update" do
725
737
  master = @master_class.new
726
- master.should_receive(:updated_by).twice.and_return author
738
+ expect(master).to receive(:updated_by).twice.and_return author
727
739
  master.update_attributes name: "Single Standard", price: 98
728
- @audit_class.should_receive(:audit).with(
740
+ expect(@audit_class).to receive(:audit).with(
729
741
  master,
730
742
  hash_including({name: "Single Standard", price: 98}),
731
743
  hash_including({name: "King size", price: 98}),
@@ -736,9 +748,9 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
736
748
  end
737
749
  it "generates a new audit on partial update" do
738
750
  master = @master_class.new
739
- master.should_receive(:updated_by).twice.and_return author
751
+ expect(master).to receive(:updated_by).twice.and_return author
740
752
  master.update_attributes name: "Single Standard", price: 98
741
- @audit_class.should_receive(:audit).with(
753
+ expect(@audit_class).to receive(:audit).with(
742
754
  master,
743
755
  hash_including({name: "Single Standard", price: 98}),
744
756
  hash_including({name: "King size", price: 98}),
@@ -752,30 +764,30 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
752
764
  begin
753
765
  @master_class.instance_variable_set :@propagate_per_column, true
754
766
  master = @master_class.new
755
- master.should_receive(:updated_by).exactly(8).times.and_return author
767
+ expect(master).to receive(:updated_by).exactly(8).times.and_return author
756
768
 
757
769
  master.update_attributes name: "Single Standard", price: 12, length: nil, width: 1
758
770
  initial_today = Date.today
759
771
  Timecop.freeze initial_today+1 do
760
772
  Sequel::Plugins::Bitemporal.at initial_today+4 do
761
773
  master.update_attributes valid_from: initial_today+4, name: "King Size", price: 15, length: 2, width: 2
762
- master.propagated_during_last_save.should have(0).item
774
+ expect(master.propagated_during_last_save.size).to eq(0)
763
775
  end
764
776
  end
765
777
  Timecop.freeze initial_today+2 do
766
778
  Sequel::Plugins::Bitemporal.at initial_today+3 do
767
779
  master.update_attributes valid_from: initial_today+3, length: 1, width: 1
768
- master.propagated_during_last_save.should have(0).item
780
+ expect(master.propagated_during_last_save.size).to eq(0)
769
781
  end
770
782
  end
771
- @audit_class.should_receive(:audit).with(
783
+ expect(@audit_class).to receive(:audit).with(
772
784
  master,
773
785
  hash_including({name: "Single Standard", price: 12, length: nil, width: 1}),
774
786
  hash_including({name: "Single Standard", price: 12, length: 3, width: 4}),
775
787
  initial_today+2,
776
788
  author
777
789
  )
778
- @audit_class.should_receive(:audit).with(
790
+ expect(@audit_class).to receive(:audit).with(
779
791
  master,
780
792
  hash_including({name: "Single Standard", price: 12, length: 1, width: 1}),
781
793
  hash_including({name: "Single Standard", price: 12, length: 1, width: 4}),
@@ -785,7 +797,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
785
797
  Timecop.freeze initial_today+3 do
786
798
  Sequel::Plugins::Bitemporal.at initial_today+2 do
787
799
  master.update_attributes valid_from: initial_today+2, length: 3, width: 4
788
- master.propagated_during_last_save.should have(1).item
800
+ expect(master.propagated_during_last_save.size).to eq(1)
789
801
  end
790
802
  end
791
803
  ensure
@@ -809,8 +821,8 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
809
821
  end
810
822
  it "generates a new audit on creation" do
811
823
  master = @master_class.new
812
- master.should_receive(:author).and_return author
813
- @audit_class.should_receive(:audit).with(
824
+ expect(master).to receive(:author).and_return author
825
+ expect(@audit_class).to receive(:audit).with(
814
826
  master,
815
827
  {},
816
828
  hash_including({name: "Single Standard", price: 98}),
@@ -821,9 +833,9 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
821
833
  end
822
834
  it "generates a new audit on update" do
823
835
  master = @master_class.new
824
- master.should_receive(:author).twice.and_return author
836
+ expect(master).to receive(:author).twice.and_return author
825
837
  master.update_attributes name: "Single Standard", price: 98
826
- @audit_class.should_receive(:audit).with(
838
+ expect(@audit_class).to receive(:audit).with(
827
839
  master,
828
840
  hash_including({name: "Single Standard", price: 98}),
829
841
  hash_including({name: "King size", price: 98}),