sequel_bitemporal 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sequel/plugins/bitemporal.rb +4 -2
- data/sequel_bitemporal.gemspec +1 -1
- data/spec/bitemporal_spec.rb +36 -38
- metadata +9 -9
@@ -8,7 +8,9 @@ module Sequel
|
|
8
8
|
missing = required - version.columns
|
9
9
|
raise Error, "bitemporal plugin requires the following missing column#{"s" if missing.size>1} on version class: #{missing.join(", ")}" unless missing.empty?
|
10
10
|
master.one_to_many :versions, class: version, key: :master_id
|
11
|
-
master.one_to_one :current_version, class: version, key: :master_id
|
11
|
+
master.one_to_one :current_version, class: version, key: :master_id do |ds|
|
12
|
+
ds.where "created_at<=:now AND (expired_at IS NULL OR expired_at>:now) AND valid_from<=:now AND valid_to>:now", now: Time.now
|
13
|
+
end
|
12
14
|
version.many_to_one :master, class: master, key: :master_id
|
13
15
|
version.class_eval do
|
14
16
|
def current?(now = Time.now)
|
@@ -48,7 +50,7 @@ module Sequel
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def update_attributes(attributes={})
|
51
|
-
if attributes.delete(:partial_update) && current_version
|
53
|
+
if !new? && attributes.delete(:partial_update) && current_version
|
52
54
|
current_attributes = current_version.values.dup
|
53
55
|
current_attributes.delete :id
|
54
56
|
attributes = current_attributes.merge attributes
|
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.1.
|
6
|
+
s.version = "0.1.1"
|
7
7
|
s.authors = ["Joseph HALTER"]
|
8
8
|
s.email = ["joseph.halter@thetalentbox.com"]
|
9
9
|
s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
|
data/spec/bitemporal_spec.rb
CHANGED
@@ -132,7 +132,7 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
132
132
|
| Single Standard | 94 | 2009-11-29 | | 2009-11-29 | | true |
|
133
133
|
}
|
134
134
|
end
|
135
|
-
it "allows shortening validity (
|
135
|
+
it "allows shortening validity (SEE COMMENTS FOR IMPROVEMENTS)" do
|
136
136
|
master = @master_class.new
|
137
137
|
master.update_attributes name: "Single Standard", price: 98
|
138
138
|
Timecop.freeze Date.today+1
|
@@ -143,41 +143,39 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
143
143
|
| Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
|
144
144
|
| Single Standard | 98 | 2009-11-29 | | 2009-11-29 | 2009-12-09 | true |
|
145
145
|
}
|
146
|
+
# would be even better if it could be:
|
147
|
+
# | name | price | created_at | expired_at | valid_from | valid_to | current |
|
148
|
+
# | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
|
149
|
+
# | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-12-09 | true |
|
146
150
|
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
#
|
163
|
-
# |
|
164
|
-
# | Single Standard |
|
165
|
-
# | Single Standard |
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
# - same date update
|
179
|
-
# - save unchanged
|
180
|
-
# - delete scheduled version
|
181
|
-
# - delete all versions
|
182
|
-
# - simultaneous updates
|
183
|
-
end
|
151
|
+
it "allows extending validity (SEE COMMENTS FOR IMPROVEMENTS)" do
|
152
|
+
master = @master_class.new
|
153
|
+
master.update_attributes name: "Single Standard", price: 98, valid_to: Date.today+2
|
154
|
+
Timecop.freeze Date.today+1
|
155
|
+
master.should have_versions %Q{
|
156
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
157
|
+
| Single Standard | 98 | 2009-11-28 | | 2009-11-28 | 2009-11-30 | true |
|
158
|
+
}
|
159
|
+
master.update_attributes valid_to: nil, partial_update: true
|
160
|
+
master.should have_versions %Q{
|
161
|
+
| name | price | created_at | expired_at | valid_from | valid_to | current |
|
162
|
+
| Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
|
163
|
+
| Single Standard | 98 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
|
164
|
+
| Single Standard | 98 | 2009-11-29 | | 2009-11-29 | | true |
|
165
|
+
}
|
166
|
+
# would be even better if it could be:
|
167
|
+
# | name | price | created_at | expired_at | valid_from | valid_to | current |
|
168
|
+
# | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
|
169
|
+
# | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | | true |
|
170
|
+
end
|
171
|
+
xit "doesn't do anything if unchanged" do
|
172
|
+
end
|
173
|
+
xit "allows deleting current version" do
|
174
|
+
end
|
175
|
+
xit "allows deleting a future version" do
|
176
|
+
end
|
177
|
+
xit "allows deleting all versions" do
|
178
|
+
end
|
179
|
+
xit "allows simultaneous updates" do
|
180
|
+
end
|
181
|
+
end
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-01 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153760860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153760860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153760420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153760420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: timecop
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153760000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153760000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sequel
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156552020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156552020
|
58
58
|
description: Bitemporal versioning for sequel, fully tested.
|
59
59
|
email:
|
60
60
|
- joseph.halter@thetalentbox.com
|