sequel_bitemporal 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -158,9 +158,11 @@ module Sequel
158
158
  @current_version_values = current_version.values
159
159
  end
160
160
  attributes.delete :id
161
- @pending_version ||= model.version_class.new
162
- pending_version.set attributes
163
- pending_version.master_id = id unless new?
161
+ if attributes_hold_changes? attributes
162
+ @pending_version ||= model.version_class.new
163
+ pending_version.set attributes
164
+ pending_version.master_id = id unless new?
165
+ end
164
166
  end
165
167
 
166
168
  def update_attributes(attributes={})
@@ -329,6 +331,26 @@ module Sequel
329
331
  propagated.save validate: false
330
332
  propagated
331
333
  end
334
+
335
+ def attributes_hold_changes?(attributes)
336
+ if new? || !current_version
337
+ attributes.any?
338
+ else
339
+ attributes.detect do |key, new_value|
340
+ case key
341
+ when :master_id, :created_at, :expired_at
342
+ false
343
+ when :valid_from
344
+ new_value && new_value<current_version.valid_from
345
+ when :valid_to
346
+ new_value || new_value!=current_version.valid_to
347
+ else
348
+ current_version.send(key)!=new_value
349
+ end
350
+ end
351
+ end
352
+ end
353
+
332
354
  end
333
355
  end
334
356
  end
@@ -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.5.1"
6
+ s.version = "0.5.2"
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"
@@ -144,7 +144,31 @@ describe "Sequel::Plugins::Bitemporal" do
144
144
  # | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | 2009-11-30 | |
145
145
  # | Single Standard | 98 | 2009-11-29 | | 2009-11-28 | MAX DATE | true |
146
146
  end
147
- xit "doesn't do anything if unchanged" do
147
+ it "don't create any new version without change" do
148
+ master = @master_class.new
149
+ master.update_attributes name: "Single Standard", price: 98
150
+ master.update_attributes price: 98, partial_update: true
151
+ master.update_attributes name: "Single Standard", price: 98
152
+ master.should have_versions %Q{
153
+ | name | price | created_at | expired_at | valid_from | valid_to | current |
154
+ | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
155
+ }
156
+ end
157
+ it "change in validity still creates a new version (SEE COMMENTS FOR IMPROVEMENTS)" do
158
+ master = @master_class.new
159
+ master.update_attributes name: "Single Standard", price: 98
160
+ Timecop.freeze Date.today+1
161
+ master.update_attributes price: 98, partial_update: true, valid_from: Date.today-2
162
+ master.update_attributes price: 98, partial_update: true, valid_from: Date.today+1
163
+ master.should have_versions %Q{
164
+ | name | price | created_at | expired_at | valid_from | valid_to | current |
165
+ | Single Standard | 98 | 2009-11-28 | | 2009-11-28 | MAX DATE | true |
166
+ | Single Standard | 98 | 2009-11-29 | | 2009-11-27 | 2009-11-28 | |
167
+ }
168
+ # would be even better if it could be:
169
+ # | name | price | created_at | expired_at | valid_from | valid_to | current |
170
+ # | Single Standard | 98 | 2009-11-28 | 2009-11-29 | 2009-11-28 | MAX DATE | |
171
+ # | Single Standard | 98 | 2009-11-29 | | 2009-11-27 | MAX DATE | true |
148
172
  end
149
173
  it "overrides no future versions" do
150
174
  master = @master_class.new
@@ -598,7 +622,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
598
622
  Date.today,
599
623
  author
600
624
  )
601
- master.update_attributes name: "King size", price: 98
625
+ master.update_attributes name: "King size", price: 98
602
626
  end
603
627
  it "generates a new audit on partial update" do
604
628
  master = @master_class.new
@@ -611,7 +635,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
611
635
  Date.today,
612
636
  author
613
637
  )
614
- master.update_attributes partial_update: true, name: "King size", price: 98
638
+ master.update_attributes partial_update: true, name: "King size", price: 98
615
639
  end
616
640
  it "generate a new audit for each future version update when propagating changes" do
617
641
  propagate_per_column = @master_class.propagate_per_column
@@ -694,7 +718,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
694
718
  Date.today,
695
719
  author
696
720
  )
697
- master.update_attributes name: "King size", price: 98
721
+ master.update_attributes name: "King size", price: 98
698
722
  end
699
723
  it "generates a new audit on partial update" do
700
724
  master = @master_class.new
@@ -707,7 +731,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
707
731
  Date.today,
708
732
  author
709
733
  )
710
- master.update_attributes partial_update: true, name: "King size", price: 98
734
+ master.update_attributes partial_update: true, name: "King size", price: 98
711
735
  end
712
736
  end
713
737
 
@@ -144,7 +144,31 @@ describe "Sequel::Plugins::Bitemporal" do
144
144
  # | Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | 2009-11-28 12:00:00 +0000 | |
145
145
  # | Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | MAX TIME | true |
146
146
  end
147
- xit "doesn't do anything if unchanged" do
147
+ it "don't create any new version without change " do
148
+ master = @master_class.new
149
+ master.update_attributes name: "Single Standard", price: 98
150
+ master.update_attributes price: 98, partial_update: true
151
+ master.update_attributes name: "Single Standard", price: 98
152
+ master.should have_versions %Q{
153
+ | name | price | created_at | expired_at | valid_from | valid_to | current |
154
+ | Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000| MAX TIME | true |
155
+ }
156
+ end
157
+ it "change in validity still creates a new version (SEE COMMENTS FOR IMPROVEMENTS)" do
158
+ master = @master_class.new
159
+ master.update_attributes name: "Single Standard", price: 98
160
+ Timecop.freeze Time.now+hour
161
+ master.update_attributes price: 98, partial_update: true, valid_from: Time.now-2*hour
162
+ master.update_attributes price: 98, partial_update: true, valid_from: Time.now+1*hour
163
+ master.should have_versions %Q{
164
+ | name | price | created_at | expired_at | valid_from | valid_to | current |
165
+ | Single Standard | 98 | 2009-11-28 10:00:00 +0000 | | 2009-11-28 10:00:00 +0000 | MAX TIME | true |
166
+ | Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 09:00:00 +0000 | 2009-11-28 10:00:00 +0000 | |
167
+ }
168
+ # would be even better if it could be:
169
+ # | name | price | created_at | expired_at | valid_from | valid_to | current |
170
+ # | Single Standard | 98 | 2009-11-28 10:00:00 +0000 | 2009-11-28 11:00:00 +0000 | 2009-11-28 10:00:00 +0000 | MAX TIME | |
171
+ # | Single Standard | 98 | 2009-11-28 11:00:00 +0000 | | 2009-11-28 09:00:00 +0000 | MAX TIME | true |
148
172
  end
149
173
  it "overrides no future versions" do
150
174
  master = @master_class.new
@@ -390,7 +414,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
390
414
  Time.now,
391
415
  author
392
416
  )
393
- master.update_attributes name: "King size", price: 98
417
+ master.update_attributes name: "King size", price: 98
394
418
  end
395
419
  it "generates a new audit on partial update" do
396
420
  master = @master_class.new
@@ -404,7 +428,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
404
428
  Time.now,
405
429
  author
406
430
  )
407
- master.update_attributes partial_update: true, name: "King size", price: 98
431
+ master.update_attributes partial_update: true, name: "King size", price: 98
408
432
  end
409
433
  end
410
434
 
@@ -445,7 +469,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the a
445
469
  Time.now,
446
470
  author
447
471
  )
448
- master.update_attributes name: "King size", price: 98
472
+ master.update_attributes name: "King size", price: 98
449
473
  end
450
474
  it "generates a new audit on partial update" do
451
475
  master = @master_class.new
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.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-21 00:00:00.000000000 Z
13
+ date: 2013-01-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sequel
@@ -125,18 +125,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  - - ! '>='
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
- segments:
129
- - 0
130
- hash: 1918973659452831064
131
128
  required_rubygems_version: !ruby/object:Gem::Requirement
132
129
  none: false
133
130
  requirements:
134
131
  - - ! '>='
135
132
  - !ruby/object:Gem::Version
136
133
  version: '0'
137
- segments:
138
- - 0
139
- hash: 1918973659452831064
140
134
  requirements: []
141
135
  rubyforge_project:
142
136
  rubygems_version: 1.8.24