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
@@ -11,32 +11,32 @@ describe "Sequel::Plugins::Bitemporal", :skip_jdbc_sqlite do
|
|
11
11
|
end
|
12
12
|
subject{ @master_class.new.update_attributes name: {test: 1}, price: 18 }
|
13
13
|
it "serializes as expected" do
|
14
|
-
subject.name.
|
14
|
+
expect(subject.name).to eq({"test" => 1})
|
15
15
|
end
|
16
16
|
it "doesn't create a new version when value hasn't changed" do
|
17
17
|
name = subject.name.dup
|
18
18
|
name["test"] = 1
|
19
19
|
subject.attributes = {name: name}
|
20
|
-
|
20
|
+
expect{ subject.save }.not_to change(@version_class, :count)
|
21
21
|
end
|
22
22
|
it "doesn't create a new version when value is the same" do
|
23
23
|
subject.attributes = {name: {"test" => 1}}
|
24
|
-
|
24
|
+
expect{ subject.save }.not_to change(@version_class, :count)
|
25
25
|
end
|
26
26
|
it "does create a new version when value has changed" do
|
27
27
|
name = subject.name.dup
|
28
28
|
name["test"] = 0
|
29
29
|
subject.attributes = {name: name}
|
30
|
-
|
30
|
+
expect{ subject.save }.to change(@version_class, :count).by 1
|
31
31
|
end
|
32
32
|
it "does create a new version when value is not the same" do
|
33
33
|
subject.attributes = {name: {"test" => 0}}
|
34
|
-
|
34
|
+
expect{ subject.save }.to change(@version_class, :count).by 1
|
35
35
|
end
|
36
36
|
it "does allow to restore" do
|
37
37
|
subject.current_version.destroy
|
38
38
|
subject.reload
|
39
|
-
|
40
|
-
subject.name.
|
39
|
+
expect{ subject.restore }.to change(@version_class, :count).by 1
|
40
|
+
expect(subject.name).to eq({"test" => 1})
|
41
41
|
end
|
42
42
|
end
|
@@ -12,34 +12,34 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
|
|
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 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
|
|
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}),
|
@@ -449,8 +449,8 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
|
|
449
449
|
let(:author){ double :author, audit_kind: "user" }
|
450
450
|
it "generates a new audit on creation" do
|
451
451
|
master = @master_class.new
|
452
|
-
master.
|
453
|
-
@audit_class.
|
452
|
+
expect(master).to receive(:author).and_return author
|
453
|
+
expect(@audit_class).to receive(:audit).with(
|
454
454
|
master,
|
455
455
|
{},
|
456
456
|
hash_including({name: "Single Standard", price: 98}),
|
@@ -461,10 +461,10 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
|
|
461
461
|
end
|
462
462
|
it "generates a new audit on update" do
|
463
463
|
master = @master_class.new
|
464
|
-
master.
|
465
|
-
@audit_class.
|
464
|
+
expect(master).to receive(:author).twice.and_return author
|
465
|
+
allow(@audit_class).to receive(:audit)
|
466
466
|
master.update_attributes name: "Single Standard", price: 98
|
467
|
-
@audit_class.
|
467
|
+
expect(@audit_class).to receive(:audit).with(
|
468
468
|
master,
|
469
469
|
hash_including({name: "Single Standard", price: 98}),
|
470
470
|
hash_including({name: "King size", price: 98}),
|