sequel_bitemporal 0.4.19 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ module Sequel
46
46
  @versions_alias = "#{base_alias}_versions".to_sym
47
47
  @current_version_alias = "#{base_alias}_current_version".to_sym
48
48
  @audit_class = opts[:audit_class]
49
- @audit_updated_by_method = opts[:audit_updated_by_method] || :updated_by_id
49
+ @audit_updated_by_method = opts.fetch(:audit_updated_by_method){ :updated_by }
50
50
  @propagate_per_column = opts.fetch(:propagate_per_column, false)
51
51
  end
52
52
  master.one_to_many :versions, class: version, key: :master_id, graph_alias_base: master.versions_alias
@@ -272,13 +272,13 @@ module Sequel
272
272
  end
273
273
  if attrs.any?
274
274
  propagated = save_propagated future_version, attrs
275
- if !propagated.new? && audited?
275
+ if !propagated.new? && audited? && updated_by
276
276
  self.class.audit_class.audit(
277
277
  self,
278
278
  future_version.values,
279
279
  propagated.values,
280
280
  propagated.valid_from,
281
- send(self.class.audit_updated_by_method)
281
+ updated_by
282
282
  )
283
283
  end
284
284
  previous_values = future_version.values.dup
@@ -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.4.19"
6
+ s.version = "0.5.0"
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"
@@ -574,41 +574,42 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
574
574
  after do
575
575
  Timecop.return
576
576
  end
577
+ let(:author){ mock :author, audit_kind: "user" }
577
578
  it "generates a new audit on creation" do
578
579
  master = @master_class.new
579
- master.should_receive(:updated_by_id).and_return(updated_by_id = stub)
580
+ master.should_receive(:updated_by).and_return author
580
581
  @audit_class.should_receive(:audit).with(
581
582
  master,
582
583
  {},
583
584
  hash_including({name: "Single Standard", price: 98}),
584
585
  Date.today,
585
- updated_by_id
586
+ author
586
587
  )
587
588
  master.update_attributes name: "Single Standard", price: 98
588
589
  end
589
590
  it "generates a new audit on full update" do
590
591
  master = @master_class.new
591
- master.should_receive(:updated_by_id).twice.and_return(updated_by_id = stub)
592
+ master.should_receive(:updated_by).twice.and_return author
592
593
  master.update_attributes name: "Single Standard", price: 98
593
594
  @audit_class.should_receive(:audit).with(
594
595
  master,
595
596
  hash_including({name: "Single Standard", price: 98}),
596
597
  hash_including({name: "King size", price: 98}),
597
598
  Date.today,
598
- updated_by_id
599
+ author
599
600
  )
600
601
  master.update_attributes name: "King size", price: 98
601
602
  end
602
603
  it "generates a new audit on partial update" do
603
604
  master = @master_class.new
604
- master.should_receive(:updated_by_id).twice.and_return(updated_by_id = stub)
605
+ master.should_receive(:updated_by).twice.and_return author
605
606
  master.update_attributes name: "Single Standard", price: 98
606
607
  @audit_class.should_receive(:audit).with(
607
608
  master,
608
609
  hash_including({name: "Single Standard", price: 98}),
609
610
  hash_including({name: "King size", price: 98}),
610
611
  Date.today,
611
- updated_by_id
612
+ author
612
613
  )
613
614
  master.update_attributes partial_update: true, name: "King size", price: 98
614
615
  end
@@ -617,7 +618,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
617
618
  begin
618
619
  @master_class.instance_variable_set :@propagate_per_column, true
619
620
  master = @master_class.new
620
- master.should_receive(:updated_by_id).exactly(9).times.and_return(updated_by_id = stub)
621
+ master.should_receive(:updated_by).exactly(8).times.and_return author
621
622
 
622
623
  master.update_attributes name: "Single Standard", price: 12, length: nil, width: 1
623
624
  initial_today = Date.today
@@ -636,14 +637,14 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
636
637
  hash_including({name: "Single Standard", price: 12, length: nil, width: 1}),
637
638
  hash_including({name: "Single Standard", price: 12, length: 3, width: 4}),
638
639
  initial_today+2,
639
- updated_by_id
640
+ author
640
641
  )
641
642
  @audit_class.should_receive(:audit).with(
642
643
  master,
643
644
  hash_including({name: "Single Standard", price: 12, length: 1, width: 1}),
644
645
  hash_including({name: "Single Standard", price: 12, length: 1, width: 4}),
645
646
  initial_today+3,
646
- updated_by_id
647
+ author
647
648
  )
648
649
  Timecop.freeze initial_today+3 do
649
650
  Sequel::Plugins::Bitemporal.at initial_today+2 do
@@ -655,14 +656,15 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
655
656
  end
656
657
  end
657
658
  end
658
- describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the updated id" do
659
+ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the author" do
659
660
  include DbHelpers
660
661
  before :all do
661
662
  @audit_class = Class.new do
662
663
  def self.audit(*args); end
663
664
  end
664
- db_setup audit_class: @audit_class, audit_updated_by_method: :author_id
665
+ db_setup audit_class: @audit_class, audit_updated_by_method: :author
665
666
  end
667
+ let(:author){ mock :author, audit_kind: "user" }
666
668
  before do
667
669
  Timecop.freeze 2009, 11, 28
668
670
  end
@@ -671,39 +673,39 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the u
671
673
  end
672
674
  it "generates a new audit on creation" do
673
675
  master = @master_class.new
674
- master.should_receive(:author_id).and_return(updated_by_id = stub)
676
+ master.should_receive(:author).and_return author
675
677
  @audit_class.should_receive(:audit).with(
676
678
  master,
677
679
  {},
678
680
  hash_including({name: "Single Standard", price: 98}),
679
681
  Date.today,
680
- updated_by_id
682
+ author
681
683
  )
682
684
  master.update_attributes name: "Single Standard", price: 98
683
685
  end
684
686
  it "generates a new audit on full update" do
685
687
  master = @master_class.new
686
- master.should_receive(:author_id).twice.and_return(updated_by_id = stub)
688
+ master.should_receive(:author).twice.and_return author
687
689
  master.update_attributes name: "Single Standard", price: 98
688
690
  @audit_class.should_receive(:audit).with(
689
691
  master,
690
692
  hash_including({name: "Single Standard", price: 98}),
691
693
  hash_including({name: "King size", price: 98}),
692
694
  Date.today,
693
- updated_by_id
695
+ author
694
696
  )
695
697
  master.update_attributes name: "King size", price: 98
696
698
  end
697
699
  it "generates a new audit on partial update" do
698
700
  master = @master_class.new
699
- master.should_receive(:author_id).twice.and_return(updated_by_id = stub)
701
+ master.should_receive(:author).twice.and_return author
700
702
  master.update_attributes name: "Single Standard", price: 98
701
703
  @audit_class.should_receive(:audit).with(
702
704
  master,
703
705
  hash_including({name: "Single Standard", price: 98}),
704
706
  hash_including({name: "King size", price: 98}),
705
707
  Date.today,
706
- updated_by_id
708
+ author
707
709
  )
708
710
  master.update_attributes partial_update: true, name: "King size", price: 98
709
711
  end
@@ -365,21 +365,22 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
365
365
  after do
366
366
  Timecop.return
367
367
  end
368
+ let(:author){ mock :author, audit_kind: "user" }
368
369
  it "generates a new audit on creation" do
369
370
  master = @master_class.new
370
- master.should_receive(:updated_by_id).and_return(updated_by_id = stub)
371
+ master.should_receive(:updated_by).and_return author
371
372
  @audit_class.should_receive(:audit).with(
372
373
  master,
373
374
  {},
374
375
  hash_including({name: "Single Standard", price: 98}),
375
376
  Time.now,
376
- updated_by_id
377
+ author
377
378
  )
378
379
  master.update_attributes name: "Single Standard", price: 98
379
380
  end
380
381
  it "generates a new audit on full update" do
381
382
  master = @master_class.new
382
- master.should_receive(:updated_by_id).twice.and_return(updated_by_id = stub)
383
+ master.should_receive(:updated_by).twice.and_return author
383
384
  @audit_class.stub(:audit)
384
385
  master.update_attributes name: "Single Standard", price: 98
385
386
  @audit_class.should_receive(:audit).with(
@@ -387,13 +388,13 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
387
388
  hash_including({name: "Single Standard", price: 98}),
388
389
  hash_including({name: "King size", price: 98}),
389
390
  Time.now,
390
- updated_by_id
391
+ author
391
392
  )
392
393
  master.update_attributes name: "King size", price: 98
393
394
  end
394
395
  it "generates a new audit on partial update" do
395
396
  master = @master_class.new
396
- master.should_receive(:updated_by_id).twice.and_return(updated_by_id = stub)
397
+ master.should_receive(:updated_by).twice.and_return author
397
398
  @audit_class.stub(:audit)
398
399
  master.update_attributes name: "Single Standard", price: 98
399
400
  @audit_class.should_receive(:audit).with(
@@ -401,17 +402,17 @@ describe "Sequel::Plugins::Bitemporal", "with audit" do
401
402
  hash_including({name: "Single Standard", price: 98}),
402
403
  hash_including({name: "King size", price: 98}),
403
404
  Time.now,
404
- updated_by_id
405
+ author
405
406
  )
406
407
  master.update_attributes partial_update: true, name: "King size", price: 98
407
408
  end
408
409
  end
409
410
 
410
- describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the updated id" do
411
+ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the author" do
411
412
  include DbHelpers
412
413
  before :all do
413
414
  @audit_class = Class.new
414
- db_setup use_time: true, audit_class: @audit_class, audit_updated_by_method: :author_id
415
+ db_setup use_time: true, audit_class: @audit_class, audit_updated_by_method: :author
415
416
  end
416
417
  before do
417
418
  Timecop.freeze 2009, 11, 28, 10
@@ -419,21 +420,22 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the u
419
420
  after do
420
421
  Timecop.return
421
422
  end
423
+ let(:author){ mock :author, audit_kind: "user" }
422
424
  it "generates a new audit on creation" do
423
425
  master = @master_class.new
424
- master.should_receive(:author_id).and_return(updated_by_id = stub)
426
+ master.should_receive(:author).and_return author
425
427
  @audit_class.should_receive(:audit).with(
426
428
  master,
427
429
  {},
428
430
  hash_including({name: "Single Standard", price: 98}),
429
431
  Time.now,
430
- updated_by_id
432
+ author
431
433
  )
432
434
  master.update_attributes name: "Single Standard", price: 98
433
435
  end
434
436
  it "generates a new audit on full update" do
435
437
  master = @master_class.new
436
- master.should_receive(:author_id).twice.and_return(updated_by_id = stub)
438
+ master.should_receive(:author).twice.and_return author
437
439
  @audit_class.stub(:audit)
438
440
  master.update_attributes name: "Single Standard", price: 98
439
441
  @audit_class.should_receive(:audit).with(
@@ -441,13 +443,13 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the u
441
443
  hash_including({name: "Single Standard", price: 98}),
442
444
  hash_including({name: "King size", price: 98}),
443
445
  Time.now,
444
- updated_by_id
446
+ author
445
447
  )
446
448
  master.update_attributes name: "King size", price: 98
447
449
  end
448
450
  it "generates a new audit on partial update" do
449
451
  master = @master_class.new
450
- master.should_receive(:author_id).twice.and_return(updated_by_id = stub)
452
+ master.should_receive(:author).twice.and_return author
451
453
  @audit_class.stub(:audit)
452
454
  master.update_attributes name: "Single Standard", price: 98
453
455
  @audit_class.should_receive(:audit).with(
@@ -455,7 +457,7 @@ describe "Sequel::Plugins::Bitemporal", "with audit, specifying how to get the u
455
457
  hash_including({name: "Single Standard", price: 98}),
456
458
  hash_including({name: "King size", price: 98}),
457
459
  Time.now,
458
- updated_by_id
460
+ author
459
461
  )
460
462
  master.update_attributes partial_update: true, name: "King size", price: 98
461
463
  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.4.19
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 604884252736843056
130
+ hash: 4238333192851217509
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 604884252736843056
139
+ hash: 4238333192851217509
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.24