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.
@@ -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, conditions: ["created_at<=:now AND (expired_at IS NULL OR expired_at>:now) AND valid_from<=:now AND valid_to>:now", now: Time.now]
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
@@ -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.0"
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"
@@ -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 (COULD BE IMPROVED!)" do
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
- # Timecop.freeze Date.today+1
148
- # version.update_attributes valid_to: "2009-12-05"
149
- # version.master.check_versions %Q{
150
- # | name | price | created_at | expired_at | valid_from | valid_to | current |
151
- # | Single Standard | 98.00 | 2009-11-28 | 2009-11-29 | 2009-11-28 | | |
152
- # | Single Standard | 98.00 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
153
- # | Single Standard | 94.00 | 2009-11-29 | 2009-11-30 | 2009-11-29 | | |
154
- # | Single Standard | 94.00 | 2009-11-30 | | 2009-11-29 | 2009-12-05 | true |
155
- # }
156
- # Timecop.freeze Date.today+1
157
- # version.update_attributes valid_from: "2009-12-02", valid_to: nil, price: 95
158
- # version.master.check_versions %Q{
159
- # | name | price | created_at | expired_at | valid_from | valid_to | current |
160
- # | Single Standard | 98.00 | 2009-11-28 | 2009-11-29 | 2009-11-28 | | |
161
- # | Single Standard | 98.00 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
162
- # | Single Standard | 94.00 | 2009-11-29 | 2009-11-30 | 2009-11-29 | | |
163
- # | Single Standard | 94.00 | 2009-11-30 | 2009-12-01 | 2009-11-29 | 2009-12-05 | |
164
- # | Single Standard | 94.00 | 2009-12-01 | | 2009-11-29 | 2009-12-02 | true |
165
- # | Single Standard | 95.00 | 2009-12-01 | | 2009-11-02 | | |
166
- # }
167
- # Timecop.freeze Date.today+1
168
- # version.master.check_versions %Q{
169
- # | name | price | created_at | expired_at | valid_from | valid_to | current |
170
- # | Single Standard | 98.00 | 2009-11-28 | 2009-11-29 | 2009-11-28 | | |
171
- # | Single Standard | 98.00 | 2009-11-29 | | 2009-11-28 | 2009-11-29 | |
172
- # | Single Standard | 94.00 | 2009-11-29 | 2009-11-30 | 2009-11-29 | | |
173
- # | Single Standard | 94.00 | 2009-11-30 | 2009-12-01 | 2009-11-29 | 2009-12-05 | |
174
- # | Single Standard | 94.00 | 2009-12-01 | | 2009-11-29 | 2009-12-02 | |
175
- # | Single Standard | 95.00 | 2009-12-01 | | 2009-11-02 | | true |
176
- # }
177
- # missing scenarios:
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.0
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: &2162303500 !ruby/object:Gem::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: *2162303500
24
+ version_requirements: *2153760860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2162303060 !ruby/object:Gem::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: *2162303060
35
+ version_requirements: *2153760420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: timecop
38
- requirement: &2162330280 !ruby/object:Gem::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: *2162330280
46
+ version_requirements: *2153760000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sequel
49
- requirement: &2162329860 !ruby/object:Gem::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: *2162329860
57
+ version_requirements: *2156552020
58
58
  description: Bitemporal versioning for sequel, fully tested.
59
59
  email:
60
60
  - joseph.halter@thetalentbox.com