sequel_bitemporal 0.4.11 → 0.4.12
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.
- data/lib/sequel/plugins/bitemporal.rb +7 -5
- data/sequel_bitemporal.gemspec +1 -1
- data/spec/bitemporal_date_spec.rb +62 -0
- metadata +4 -4
@@ -26,7 +26,7 @@ module Sequel
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.now
|
29
|
-
Thread.current[THREAD_NOW_KEY] ||
|
29
|
+
Thread.current[THREAD_NOW_KEY] || point_in_time
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.configure(master, opts = {})
|
@@ -177,11 +177,12 @@ module Sequel
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def destroy
|
180
|
-
|
180
|
+
point_in_time = ::Sequel::Plugins::Bitemporal.point_in_time
|
181
|
+
versions_dataset.where(expired_at: nil).where("valid_to>valid_from").update expired_at: point_in_time
|
181
182
|
end
|
182
183
|
|
183
184
|
def destroy_version(version, expand_previous_version)
|
184
|
-
point_in_time =
|
185
|
+
point_in_time = ::Sequel::Plugins::Bitemporal.point_in_time
|
185
186
|
return false if version.valid_to.to_time<=point_in_time
|
186
187
|
model.db.transaction do
|
187
188
|
success = true
|
@@ -211,9 +212,10 @@ module Sequel
|
|
211
212
|
|
212
213
|
def prepare_pending_version
|
213
214
|
return unless pending_version
|
214
|
-
|
215
|
+
now = ::Sequel::Plugins::Bitemporal.now
|
216
|
+
point_in_time = ::Sequel::Plugins::Bitemporal.point_in_time
|
215
217
|
pending_version.created_at = point_in_time
|
216
|
-
pending_version.valid_from ||=
|
218
|
+
pending_version.valid_from ||= now
|
217
219
|
end
|
218
220
|
|
219
221
|
def expire_previous_versions
|
data/sequel_bitemporal.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "sequel_bitemporal"
|
6
|
-
s.version = "0.4.
|
6
|
+
s.version = "0.4.12"
|
7
7
|
s.authors = ["Joseph HALTER", "Jonathan TRON"]
|
8
8
|
s.email = ["joseph.halter@thetalentbox.com", "jonathan.tron@thetalentbox.com"]
|
9
9
|
s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
|
@@ -467,6 +467,68 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
467
467
|
master.update_attributes price: 94, partial_update: true
|
468
468
|
master.reload.disabled.should be_true
|
469
469
|
end
|
470
|
+
it "uses current version for partial_update even if valid_from is specified" do
|
471
|
+
master = @master_class.new
|
472
|
+
master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
|
473
|
+
master.update_attributes name: "Single Standard", price: 94
|
474
|
+
master.should have_versions %Q{
|
475
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
476
|
+
| Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
|
477
|
+
| Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
|
478
|
+
}
|
479
|
+
master.update_attributes name: "King Size", partial_update: true, valid_from: Date.today-2
|
480
|
+
master.should have_versions %Q{
|
481
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
482
|
+
| Single Standard | 98 | 2009-11-28 | 2009-11-28 | 2009-11-26 | 2009-11-28 | |
|
483
|
+
| Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
|
484
|
+
| King Size | 94 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
|
485
|
+
}
|
486
|
+
end
|
487
|
+
it "as_we_knew_it also allows creating and deleting at that time" do
|
488
|
+
master = @master_class.new
|
489
|
+
master.update_attributes name: "Single Standard", price: 98
|
490
|
+
Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+1) do
|
491
|
+
master.update_attributes name: "King Size", partial_update: true
|
492
|
+
end
|
493
|
+
master.should have_versions %Q{
|
494
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
495
|
+
| Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
|
496
|
+
| Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
|
497
|
+
| King Size | 98 | 2009-11-29 | | 2009-11-29 | MAX DATE | |
|
498
|
+
}
|
499
|
+
Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
|
500
|
+
master.current_version(true).destroy
|
501
|
+
end
|
502
|
+
master.should have_versions %Q{
|
503
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
504
|
+
| Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | true |
|
505
|
+
| Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
|
506
|
+
| King Size | 98 | 2009-11-29 | 2009-11-30 | 2009-11-29 | MAX DATE | |
|
507
|
+
| King Size | 98 | 2009-11-30 | | 2009-11-29 | 2009-11-30 | |
|
508
|
+
}
|
509
|
+
end
|
510
|
+
it "combines as_we_knew_it and at to set valid_from" do
|
511
|
+
master = @master_class.new
|
512
|
+
master.update_attributes name: "Single Standard", price: 98, valid_from: Date.today-2, valid_to: Date.today
|
513
|
+
master.update_attributes name: "Single Standard", price: 94
|
514
|
+
master.should have_versions %Q{
|
515
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
516
|
+
| Single Standard | 98 | 2009-11-28 | | 2009-11-26 | 2009-11-28 | |
|
517
|
+
| Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
|
518
|
+
}
|
519
|
+
Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+1) do
|
520
|
+
Sequel::Plugins::Bitemporal.at(Date.today-1) do
|
521
|
+
master.update_attributes name: "King Size", partial_update: true
|
522
|
+
end
|
523
|
+
end
|
524
|
+
master.should have_versions %Q{
|
525
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
526
|
+
| Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-26 | 2009-11-28 | |
|
527
|
+
| Single Standard | 94 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
|
528
|
+
| Single Standard | 98 | 2009-11-29 | | 2009-11-26 | 2009-11-27 | |
|
529
|
+
| King Size | 98 | 2009-11-29 | | 2009-11-27 | 2009-11-28 | |
|
530
|
+
}
|
531
|
+
end
|
470
532
|
end
|
471
533
|
|
472
534
|
describe "Sequel::Plugins::Bitemporal", "with audit" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_bitemporal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash: -
|
130
|
+
hash: -574087538557051277
|
131
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash: -
|
139
|
+
hash: -574087538557051277
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
142
|
rubygems_version: 1.8.24
|