sequel_bitemporal 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cee3a928e6040c66f2b5c628ca7f37bcf4451f2
4
- data.tar.gz: bfaa006ec3fb917fc0552157a7a761514431f4ce
3
+ metadata.gz: dc6bb9ceee4fe755f012319a851647fe9037b91e
4
+ data.tar.gz: 2131ffd83c0ff24ff6bd870080d6b6763d672430
5
5
  SHA512:
6
- metadata.gz: ade148671ec5c5e3d6dde67c423583b2e9d7903d97f6876f841300ada4ce32cb231ffa50de7156bb27f5e46975e62f834c382e0f552ba172728980ed8179e305
7
- data.tar.gz: ad5093d86f437e43c11eeb96da9a417e8c9d76c828a6f24a964828726979214e6e53c53b5c8309e971b3842eef00d9dc8ec5af3c18e1d937bc4edc08c4c60312
6
+ metadata.gz: 6bc79a515a21dac544a6e32c8ff3e08326d848a4936a173910b7f3cb98dbd9be439e5dbd8807269b0bd3b52eaa4d8c7f528f64a697a9ce11c4f50053a46dffed
7
+ data.tar.gz: acf77c4b2b1865561d5dd93b2f87c4e39910a5a7a1dc26e5e0984c9df0f65770f78492dea145225323f485619203225ee5f58626689f99820b3c10d8c7f08967
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.2
@@ -397,6 +397,25 @@ module Sequel
397
397
  end
398
398
  end
399
399
 
400
+ def next_version
401
+ @next_version ||= begin
402
+ return if new?
403
+ t = ::Sequel::Plugins::Bitemporal.point_in_time
404
+ n = ::Sequel::Plugins::Bitemporal.now
405
+ if use_ranges = self.class.use_ranges
406
+ range_conditions = self.class.existence_range_contains t
407
+ end
408
+ versions_dataset.where do
409
+ if use_ranges
410
+ range_conditions
411
+ else
412
+ (created_at <= t) &
413
+ Sequel.|({expired_at=>nil}, expired_at > t)
414
+ end & (valid_from > n)
415
+ end.order(Sequel.asc(:valid_to), Sequel.desc(:created_at)).first
416
+ end
417
+ end
418
+
400
419
  def restore(attrs={})
401
420
  return false unless deleted?
402
421
  last_version_attributes = if last_version
@@ -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.8.3"
6
+ s.version = "0.8.4"
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"
@@ -565,7 +565,7 @@ describe "Sequel::Plugins::Bitemporal" do
565
565
  expect(master.price).to eq(98)
566
566
  end
567
567
  it "avoids delegation of columns which are both in master and version" do
568
- closure = @version_class
568
+ closure = Class.new @version_class
569
569
  DB.create_table! :rooms_with_name do
570
570
  primary_key :id
571
571
  String :name
@@ -691,6 +691,31 @@ describe "Sequel::Plugins::Bitemporal" do
691
691
  expect(subject.last_version).to eq(subject.versions.last)
692
692
  end
693
693
  end
694
+ context "#next_version" do
695
+ subject{ @master_class.new }
696
+ it "is nil unless persisted" do
697
+ expect(subject.next_version).to be_nil
698
+ end
699
+ it "is nil with current version and no future version" do
700
+ subject.update_attributes name: "Single Standard", price: 94
701
+ expect(subject.next_version).to be_nil
702
+ end
703
+ it "is next version with both current version and future version" do
704
+ subject.update_attributes name: "Single Standard", price: 94
705
+ subject.update_attributes price: 95, valid_from: Date.today+1
706
+ expect( subject.current_version ).not_to be_nil
707
+ expect( subject.current_version.price ).to eq 94
708
+ expect( subject.next_version ).not_to be_nil
709
+ expect( subject.next_version.price ).to eq 95
710
+ end
711
+ it "is next version with future versions but no current version" do
712
+ subject.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
713
+ subject.update_attributes name: "Single Standard", price: 92, valid_from: Date.today+1
714
+ expect( subject.current_version ).to be_nil
715
+ expect( subject.next_version ).not_to be_nil
716
+ expect( subject.next_version.price ).to eq 92
717
+ end
718
+ end
694
719
  context "#restore" do
695
720
  subject{ @master_class.new }
696
721
  it "make last version current" do
@@ -705,6 +730,14 @@ describe "Sequel::Plugins::Bitemporal" do
705
730
  expect(subject.current_version.price).to eq(94)
706
731
  end
707
732
  end
733
+ it "master.current_version.master is master" do
734
+ master = @master_class.new
735
+ master.update_attributes name: "Single Standard", price: 98
736
+ expect( master.current_version.master.object_id ).to eq master.object_id
737
+ # impossible for sequel to resolve because of the eager_graph:
738
+ master = @master_class.with_current_version.all.first
739
+ expect( master.current_version.master.object_id ).not_to eq master.object_id
740
+ end
708
741
  end
709
742
 
710
743
  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.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph HALTER
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-18 00:00:00.000000000 Z
12
+ date: 2015-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel