sequel_bitemporal 0.4.12 → 0.4.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,7 @@ module Sequel
26
26
  end
27
27
 
28
28
  def self.now
29
- Thread.current[THREAD_NOW_KEY] || point_in_time
29
+ Thread.current[THREAD_NOW_KEY] || Time.now
30
30
  end
31
31
 
32
32
  def self.configure(master, opts = {})
@@ -182,11 +182,12 @@ module Sequel
182
182
  end
183
183
 
184
184
  def destroy_version(version, expand_previous_version)
185
+ now = ::Sequel::Plugins::Bitemporal.now
185
186
  point_in_time = ::Sequel::Plugins::Bitemporal.point_in_time
186
- return false if version.valid_to.to_time<=point_in_time
187
+ return false if version.valid_to.to_time<=now
187
188
  model.db.transaction do
188
189
  success = true
189
- version_was_valid = point_in_time>=version.valid_from.to_time
190
+ version_was_valid = now>=version.valid_from.to_time
190
191
  if expand_previous_version
191
192
  previous = versions_dataset.where({
192
193
  expired_at: nil,
@@ -194,14 +195,14 @@ module Sequel
194
195
  }).where("valid_to>valid_from").first
195
196
  if previous
196
197
  if version_was_valid
197
- success &&= save_fossil previous, created_at: point_in_time, valid_from: point_in_time, valid_to: version.valid_to
198
+ success &&= save_fossil previous, created_at: point_in_time, valid_from: now, valid_to: version.valid_to
198
199
  else
199
200
  success &&= save_fossil previous, created_at: point_in_time, valid_to: version.valid_to
200
201
  success &&= previous.update expired_at: point_in_time
201
202
  end
202
203
  end
203
204
  end
204
- success &&= save_fossil version, created_at: point_in_time, valid_to: point_in_time if version_was_valid
205
+ success &&= save_fossil version, created_at: point_in_time, valid_to: now if version_was_valid
205
206
  success &&= version.update expired_at: point_in_time
206
207
  raise Sequel::Rollback unless success
207
208
  success
@@ -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.12"
6
+ s.version = "0.4.13"
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"
@@ -493,8 +493,7 @@ describe "Sequel::Plugins::Bitemporal" do
493
493
  master.should have_versions %Q{
494
494
  | name | price | created_at | expired_at | valid_from | valid_to | current |
495
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 | |
496
+ | King Size | 98 | 2009-11-29 | | 2009-11-28 | MAX DATE | |
498
497
  }
499
498
  Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today+2) do
500
499
  master.current_version(true).destroy
@@ -502,9 +501,8 @@ describe "Sequel::Plugins::Bitemporal" do
502
501
  master.should have_versions %Q{
503
502
  | name | price | created_at | expired_at | valid_from | valid_to | current |
504
503
  | 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 | |
504
+ | King Size | 98 | 2009-11-29 | 2009-11-30 | 2009-11-28 | MAX DATE | |
505
+ | King Size | 98 | 2009-11-30 | | 2009-11-28 | 2009-11-28 | |
508
506
  }
509
507
  end
510
508
  it "combines as_we_knew_it and at to set valid_from" 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.12
4
+ version: 0.4.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -574087538557051277
130
+ hash: 2261132615164155074
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: -574087538557051277
139
+ hash: 2261132615164155074
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.24