temporal_tables 0.6.6 → 0.6.7

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
  SHA256:
3
- metadata.gz: 751b39e906ea31cee28a7146afa577cc5788bbeb164bd4f9f0e5e04dc1a0d024
4
- data.tar.gz: 697070c46cd1c4997f98a995044623784eb5cbe46d969f7d5a3a2622c23b4f3e
3
+ metadata.gz: ff585572728100114c403af9f97e723d0c1d1760e73c46e7127d86849941cf0d
4
+ data.tar.gz: c3f7f8d672c1d549c378be20996ed8594f51c53bf215c820d864fa936e4f572e
5
5
  SHA512:
6
- metadata.gz: 973f379f3a886ed938d5bbd169401b752c22a8ce0ba3dead9a9dad480e63dcad563e2515ca593ae119a7280cd7cd53c0be55972c8d4114875fe5e09ae85d5c1d
7
- data.tar.gz: a0a3483633ee91925e195e4e706d4d201f0af9f844fc92d0837e7282f17fc5a071a8058fdf33bd34bd8b870162f1819fb5852c5b0903f47934357a3e44868d42
6
+ metadata.gz: 39d574fec08e359020dc88b2b7ef9d03ac6206da04517643d0686dbf02e1ecf6834d03742afadffd564bd7573076863bd82b3259059f0697b25594f9261f4f69
7
+ data.tar.gz: 5493b7f16dd8cb2db633529037711ffb78224c5c42ab6e836f43901dacea20ade306e0103e09cc66f9349350e87da336032098cd7abb38430de18b5eb408a71e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.6)
4
+ temporal_tables (0.6.7)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -40,12 +40,7 @@ module TemporalTables
40
40
 
41
41
  at_clauses = []
42
42
  if historical?
43
- at_clauses << where_clause_factory.build(
44
- arel_table[:eff_to].gteq(at_value).and(
45
- arel_table[:eff_from].lteq(at_value)
46
- ),
47
- []
48
- )
43
+ at_clauses << where_clause_factory.build(build_temporal_constraint(at_value), [])
49
44
  end
50
45
 
51
46
  [s, *at_clauses.compact].sum
@@ -139,8 +134,19 @@ module TemporalTables
139
134
  end
140
135
  end
141
136
 
137
+ # This is required for eager_load to work in Rails 5.0.x
138
+ module JoinDependencyExtensions
139
+ def build_constraint(klass, table, key, foreign_table, foreign_key)
140
+ constraint = super
141
+ if at_value = Thread.current[:at_time]
142
+ constraint = constraint.and(klass.build_temporal_constraint(at_value))
143
+ end
144
+ constraint
145
+ end
146
+ end
142
147
  end
143
148
 
144
149
  ActiveRecord::Relation.send :prepend, TemporalTables::RelationExtensions
145
150
  ActiveRecord::Associations::Association.send :prepend, TemporalTables::AssociationExtensions
146
151
  ActiveRecord::Associations::Preloader::Association.send :prepend, TemporalTables::PreloaderExtensions
152
+ ActiveRecord::Associations::JoinDependency::JoinAssociation.send :prepend, TemporalTables::JoinDependencyExtensions
@@ -68,6 +68,12 @@ module TemporalTables
68
68
  def descends_from_active_record?
69
69
  superclass.descends_from_active_record?
70
70
  end
71
+
72
+ def build_temporal_constraint(at_value)
73
+ arel_table[:eff_to].gteq(at_value).and(
74
+ arel_table[:eff_from].lteq(at_value)
75
+ )
76
+ end
71
77
  end
72
78
 
73
79
  def orig_class
@@ -1,3 +1,3 @@
1
1
  module TemporalTables
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
@@ -5,7 +5,6 @@ require "temporal_tables/whodunnit"
5
5
  require "temporal_tables/temporal_class"
6
6
  require "temporal_tables/history_hook"
7
7
  require "temporal_tables/relation_extensions"
8
- require "temporal_tables/scope_extensions"
9
8
  require "temporal_tables/version"
10
9
 
11
10
  module TemporalTables
@@ -92,5 +92,21 @@ describe Person do
92
92
  expect(historical_emily.is_a?(PersonHistory)).to eq(true)
93
93
  end
94
94
  end
95
+
96
+ describe "when checking current state" do
97
+ it "should have correct information" do
98
+ # ie. we shouldn't break regular ActiveRecord behaviour
99
+ expect(Person.count).to eq(1)
100
+ expect(Wart.count).to eq(1)
101
+
102
+ emily = Person.first
103
+ expect(emily.warts.count).to eq(1)
104
+ expect(emily.warts.first.hairiness).to eq(3)
105
+
106
+ emily = Person.where(id: emily.id).eager_load(:warts).first
107
+ expect(emily.warts.count).to eq(1)
108
+ expect(emily.warts.first.hairiness).to eq(3)
109
+ end
110
+ end
95
111
  end
96
112
  end
data/spec/spec_helper.rb CHANGED
@@ -11,7 +11,7 @@ end
11
11
  DatabaseCleaner.strategy = :deletion
12
12
 
13
13
  RSpec.configure do |config|
14
- config.before(:all) do
14
+ config.before(:each) do
15
15
  DatabaseCleaner.clean
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporal_tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Kroeker
@@ -101,7 +101,6 @@ files:
101
101
  - lib/temporal_tables/connection_adapters/postgresql_adapter.rb
102
102
  - lib/temporal_tables/history_hook.rb
103
103
  - lib/temporal_tables/relation_extensions.rb
104
- - lib/temporal_tables/scope_extensions.rb
105
104
  - lib/temporal_tables/temporal_adapter.rb
106
105
  - lib/temporal_tables/temporal_class.rb
107
106
  - lib/temporal_tables/version.rb
@@ -1,13 +0,0 @@
1
- module TemporalTables
2
- module NamedExtensionsWithHistory
3
- def scope(name, body, &block)
4
- if history
5
- history_body = -> { history.instance_exec &body }
6
- history.scope_without_history name, history_body, &block
7
- end
8
- super name, body, &block
9
- end
10
- end
11
- end
12
-
13
- ActiveRecord::Scoping::Named::ClassMethods.send :prepend, TemporalTables::NamedExtensionsWithHistory