paper_trail 5.1.1 → 5.2.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.
@@ -26,9 +26,9 @@ class ThreadSafetyTest < ActionController::TestCase
26
26
  enabled = nil
27
27
 
28
28
  slow_thread = Thread.new do
29
- Widget.new.without_versioning do
29
+ Widget.new.paper_trail.without_versioning do
30
30
  sleep(0.01)
31
- enabled = Widget.paper_trail_enabled_for_model?
31
+ enabled = Widget.paper_trail.enabled?
32
32
  sleep(0.01)
33
33
  end
34
34
  enabled
@@ -36,11 +36,11 @@ class ThreadSafetyTest < ActionController::TestCase
36
36
 
37
37
  fast_thread = Thread.new do
38
38
  sleep(0.005)
39
- Widget.paper_trail_enabled_for_model?
39
+ Widget.paper_trail.enabled?
40
40
  end
41
41
 
42
42
  assert_not_equal slow_thread.value, fast_thread.value
43
- assert Widget.paper_trail_enabled_for_model?
43
+ assert Widget.paper_trail.enabled?
44
44
  assert PaperTrail.enabled_for_model?(Widget)
45
45
  end
46
46
  end
@@ -53,7 +53,7 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
53
53
  should "restrict the versions destroyed to those that were created on the date provided" do
54
54
  assert_equal 10, PaperTrail::Version.count
55
55
  assert_equal 4, @animal.versions.size
56
- assert_equal 3, @animal.versions_between(@date, @date + 1.day).size
56
+ assert_equal 3, @animal.paper_trail.versions_between(@date, @date + 1.day).size
57
57
  PaperTrail.clean_versions!(date: @date)
58
58
  assert_equal 8, PaperTrail::Version.count
59
59
  assert_equal 2, @animal.versions.reload.size
@@ -242,7 +242,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
242
242
  end
243
243
 
244
244
  should "be live" do
245
- assert @widget.live?
245
+ assert @widget.paper_trail.live?
246
246
  end
247
247
 
248
248
  context "which is then created" do
@@ -262,7 +262,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
262
262
  end
263
263
 
264
264
  should "be live" do
265
- assert @widget.live?
265
+ assert @widget.paper_trail.live?
266
266
  end
267
267
 
268
268
  should "use the widget `updated_at` as the version's `created_at`" do
@@ -317,7 +317,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
317
317
  end
318
318
 
319
319
  should "have versions that are not live" do
320
- assert @widget.versions.map(&:reify).compact.all? { |w| !w.live? }
320
+ assert @widget.versions.map(&:reify).compact.all? { |w|
321
+ !w.paper_trail.live?
322
+ }
321
323
  end
322
324
 
323
325
  should "have stored changes" do
@@ -566,11 +568,11 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
566
568
 
567
569
  context "with its paper trail turned off" do
568
570
  setup do
569
- Widget.paper_trail_off!
571
+ Widget.paper_trail.disable
570
572
  @count = @widget.versions.length
571
573
  end
572
574
 
573
- teardown { Widget.paper_trail_on! }
575
+ teardown { Widget.paper_trail.enable }
574
576
 
575
577
  context "when updated" do
576
578
  setup { @widget.update_attributes name: "Beeblebrox" }
@@ -582,13 +584,13 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
582
584
 
583
585
  context 'when destroyed "without versioning"' do
584
586
  should "leave paper trail off after call" do
585
- @widget.without_versioning :destroy
586
- assert !Widget.paper_trail_enabled_for_model?
587
+ @widget.paper_trail.without_versioning :destroy
588
+ assert_equal false, Widget.paper_trail.enabled?
587
589
  end
588
590
  end
589
591
 
590
592
  context "and then its paper trail turned on" do
591
- setup { Widget.paper_trail_on! }
593
+ setup { Widget.paper_trail.enable }
592
594
 
593
595
  context "when updated" do
594
596
  setup { @widget.update_attributes name: "Ford" }
@@ -600,11 +602,11 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
600
602
 
601
603
  context 'when updated "without versioning"' do
602
604
  setup do
603
- @widget.without_versioning do
605
+ @widget.paper_trail.without_versioning do
604
606
  @widget.update_attributes name: "Ford"
605
607
  end
606
608
  # The model instance should yield itself for convenience purposes
607
- @widget.without_versioning { |w| w.update_attributes name: "Nixon" }
609
+ @widget.paper_trail.without_versioning { |w| w.update_attributes name: "Nixon" }
608
610
  end
609
611
 
610
612
  should "not create new version" do
@@ -612,19 +614,19 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
612
614
  end
613
615
 
614
616
  should "enable paper trail after call" do
615
- assert Widget.paper_trail_enabled_for_model?
617
+ assert Widget.paper_trail.enabled?
616
618
  end
617
619
  end
618
620
 
619
621
  context "when receiving a method name as an argument" do
620
- setup { @widget.without_versioning(:touch_with_version) }
622
+ setup { @widget.paper_trail.without_versioning(:touch_with_version) }
621
623
 
622
624
  should "not create new version" do
623
625
  assert_equal @count, @widget.versions.length
624
626
  end
625
627
 
626
628
  should "enable paper trail after call" do
627
- assert Widget.paper_trail_enabled_for_model?
629
+ assert Widget.paper_trail.enabled?
628
630
  end
629
631
  end
630
632
  end
@@ -645,9 +647,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
645
647
 
646
648
  should "track who made the change" do
647
649
  assert_equal "Alice", @version.whodunnit
648
- assert_nil @version.paper_trail_originator
650
+ assert_nil @version.paper_trail_originator
649
651
  assert_equal "Alice", @version.terminator
650
- assert_equal "Alice", @widget.paper_trail_originator
652
+ assert_equal "Alice", @widget.paper_trail.originator
651
653
  end
652
654
 
653
655
  context "when a record is updated" do
@@ -658,10 +660,10 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
658
660
  end
659
661
 
660
662
  should "track who made the change" do
661
- assert_equal "Bob", @version.whodunnit
663
+ assert_equal "Bob", @version.whodunnit
662
664
  assert_equal "Alice", @version.paper_trail_originator
663
- assert_equal "Bob", @version.terminator
664
- assert_equal "Bob", @widget.paper_trail_originator
665
+ assert_equal "Bob", @version.terminator
666
+ assert_equal "Bob", @widget.paper_trail.originator
665
667
  end
666
668
 
667
669
  context "when a record is destroyed" do
@@ -673,9 +675,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
673
675
 
674
676
  should "track who made the change" do
675
677
  assert_equal "Charlie", @version.whodunnit
676
- assert_equal "Bob", @version.paper_trail_originator
678
+ assert_equal "Bob", @version.paper_trail_originator
677
679
  assert_equal "Charlie", @version.terminator
678
- assert_equal "Charlie", @widget.paper_trail_originator
680
+ assert_equal "Charlie", @widget.paper_trail.originator
679
681
  end
680
682
  end
681
683
  end
@@ -735,7 +737,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
735
737
  should "should return the correct originator" do
736
738
  PaperTrail.whodunnit = "Ben"
737
739
  @foo.update_attribute(:name, "Geoffrey")
738
- assert_equal PaperTrail.whodunnit, @foo.paper_trail_originator
740
+ assert_equal PaperTrail.whodunnit, @foo.paper_trail.originator
739
741
  end
740
742
 
741
743
  context "when destroyed" do
@@ -768,40 +770,43 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
768
770
  end
769
771
 
770
772
  should "return nil for version_at before it was created" do
771
- assert_nil @widget.version_at(@created - 1)
773
+ assert_nil @widget.paper_trail.version_at(@created - 1)
772
774
  end
773
775
 
774
776
  should "return how it looked when created for version_at its creation" do
775
- assert_equal "Widget", @widget.version_at(@created).name
777
+ assert_equal "Widget", @widget.paper_trail.version_at(@created).name
776
778
  end
777
779
 
778
780
  should "return how it looked before its first update" do
779
- assert_equal "Widget", @widget.version_at(@first_update - 1).name
781
+ assert_equal "Widget", @widget.paper_trail.version_at(@first_update - 1).name
780
782
  end
781
783
 
782
784
  should "return how it looked after its first update" do
783
- assert_equal "Fidget", @widget.version_at(@first_update).name
785
+ assert_equal "Fidget", @widget.paper_trail.version_at(@first_update).name
784
786
  end
785
787
 
786
788
  should "return how it looked before its second update" do
787
- assert_equal "Fidget", @widget.version_at(@second_update - 1).name
789
+ assert_equal "Fidget", @widget.paper_trail.version_at(@second_update - 1).name
788
790
  end
789
791
 
790
792
  should "return how it looked after its second update" do
791
- assert_equal "Digit", @widget.version_at(@second_update).name
793
+ assert_equal "Digit", @widget.paper_trail.version_at(@second_update).name
792
794
  end
793
795
 
794
796
  should "return the current object for version_at after latest update" do
795
- assert_equal "Digit", @widget.version_at(1.day.from_now).name
797
+ assert_equal "Digit", @widget.paper_trail.version_at(1.day.from_now).name
796
798
  end
797
799
 
798
800
  context "passing in a string representation of a timestamp" do
799
801
  should "still return a widget when appropriate" do
800
802
  # need to add 1 second onto the timestamps before casting to a string,
801
803
  # since casting a Time to a string drops the microseconds
802
- assert_equal "Widget", @widget.version_at((@created + 1.second).to_s).name
803
- assert_equal "Fidget", @widget.version_at((@first_update + 1.second).to_s).name
804
- assert_equal "Digit", @widget.version_at((@second_update + 1.second).to_s).name
804
+ assert_equal "Widget",
805
+ @widget.paper_trail.version_at((@created + 1.second).to_s).name
806
+ assert_equal "Fidget",
807
+ @widget.paper_trail.version_at((@first_update + 1.second).to_s).name
808
+ assert_equal "Digit",
809
+ @widget.paper_trail.version_at((@second_update + 1.second).to_s).name
805
810
  end
806
811
  end
807
812
  end
@@ -819,13 +824,13 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
819
824
 
820
825
  should "return versions in the time period" do
821
826
  assert_equal ["Fidget"],
822
- @widget.versions_between(20.days.ago, 10.days.ago).map(&:name)
827
+ @widget.paper_trail.versions_between(20.days.ago, 10.days.ago).map(&:name)
823
828
  assert_equal %w(Widget Fidget),
824
- @widget.versions_between(45.days.ago, 10.days.ago).map(&:name)
829
+ @widget.paper_trail.versions_between(45.days.ago, 10.days.ago).map(&:name)
825
830
  assert_equal %w(Fidget Digit Digit),
826
- @widget.versions_between(16.days.ago, 1.minute.ago).map(&:name)
831
+ @widget.paper_trail.versions_between(16.days.ago, 1.minute.ago).map(&:name)
827
832
  assert_equal [],
828
- @widget.versions_between(60.days.ago, 45.days.ago).map(&:name)
833
+ @widget.paper_trail.versions_between(60.days.ago, 45.days.ago).map(&:name)
829
834
  end
830
835
  end
831
836
 
@@ -948,7 +953,8 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
948
953
  end
949
954
 
950
955
  should "return its previous self" do
951
- assert_equal @widget.versions[-2].reify, @widget.previous_version
956
+ assert_equal @widget.versions[-2].reify,
957
+ @widget.paper_trail.previous_version
952
958
  end
953
959
  end
954
960
 
@@ -956,11 +962,11 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
956
962
  setup { @widget = Widget.new }
957
963
 
958
964
  should "not have a previous version" do
959
- assert_nil @widget.previous_version
965
+ assert_nil @widget.paper_trail.previous_version
960
966
  end
961
967
 
962
968
  should "not have a next version" do
963
- assert_nil @widget.next_version
969
+ assert_nil @widget.paper_trail.next_version
964
970
  end
965
971
 
966
972
  context "with versions" do
@@ -970,11 +976,12 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
970
976
  end
971
977
 
972
978
  should "have a previous version" do
973
- assert_equal @widget.versions.last.reify.name, @widget.previous_version.name
979
+ assert_equal @widget.versions.last.reify.name,
980
+ @widget.paper_trail.previous_version.name
974
981
  end
975
982
 
976
983
  should "not have a next version" do
977
- assert_nil @widget.next_version
984
+ assert_nil @widget.paper_trail.next_version
978
985
  end
979
986
  end
980
987
  end
@@ -988,13 +995,15 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
988
995
  end
989
996
 
990
997
  should "have a previous version" do
991
- assert_nil @second_widget.previous_version # `create` events return `nil` for `reify`
992
- assert_equal @widget.versions[-2].reify.name, @last_widget.previous_version.name
998
+ # `create` events return `nil` for `reify`
999
+ assert_nil @second_widget.paper_trail.previous_version
1000
+ assert_equal @widget.versions[-2].reify.name,
1001
+ @last_widget.paper_trail.previous_version.name
993
1002
  end
994
1003
 
995
1004
  should "have a next version" do
996
- assert_equal @widget.versions[2].reify.name, @second_widget.next_version.name
997
- assert_equal @last_widget.next_version.name, @widget.name
1005
+ assert_equal @widget.versions[2].reify.name, @second_widget.paper_trail.next_version.name
1006
+ assert_equal @last_widget.paper_trail.next_version.name, @widget.name
998
1007
  end
999
1008
  end
1000
1009
 
@@ -1270,13 +1279,14 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1270
1279
  end
1271
1280
 
1272
1281
  should "respond to `next_version` as normal" do
1273
- assert_equal @doc.paper_trail_versions.last.reify.next_version.name, @doc.name
1282
+ reified = @doc.paper_trail_versions.last.reify
1283
+ assert_equal reified.paper_trail.next_version.name, @doc.name
1274
1284
  end
1275
1285
 
1276
1286
  should "respond to `previous_version` as normal" do
1277
1287
  @doc.update_attributes name: "Doc 2"
1278
1288
  assert_equal 3, @doc.paper_trail_versions.length
1279
- assert_equal "Doc 1", @doc.previous_version.name
1289
+ assert_equal "Doc 1", @doc.paper_trail.previous_version.name
1280
1290
  end
1281
1291
  end
1282
1292
 
@@ -1350,7 +1360,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1350
1360
  end
1351
1361
 
1352
1362
  should "still respond to touch_with_version" do
1353
- @fluxor.touch_with_version
1363
+ @fluxor.paper_trail.touch_with_version
1354
1364
  assert_equal 1, @fluxor.versions.length
1355
1365
  end
1356
1366
  end
@@ -1405,7 +1415,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1405
1415
  end
1406
1416
 
1407
1417
  should "return its previous self" do
1408
- assert_equal @widget.versions[-2].reify, @widget.previous_version
1418
+ assert_equal @widget.versions[-2].reify, @widget.paper_trail.previous_version
1409
1419
  end
1410
1420
  end
1411
1421
 
@@ -25,7 +25,7 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
25
25
  end
26
26
 
27
27
  should "be `nil` in its previous version" do
28
- assert_nil @widget.previous_version
28
+ assert_nil @widget.paper_trail.previous_version
29
29
  end
30
30
 
31
31
  context "which is then updated" do
@@ -36,14 +36,15 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
36
36
  end
37
37
 
38
38
  should "not be `nil` in its previous version" do
39
- assert_not_nil @widget.previous_version
39
+ assert_not_nil @widget.paper_trail.previous_version
40
40
  end
41
41
 
42
42
  should "the previous version should contain right attributes" do
43
43
  # For some reason this test seems to be broken in JRuby 1.9 mode in the
44
44
  # test env even though it works in the console. WTF?
45
45
  unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION)
46
- assert_attributes_equal @widget.previous_version.attributes, @initial_attributes
46
+ previous_attributes = @widget.paper_trail.previous_version.attributes
47
+ assert_attributes_equal previous_attributes, @initial_attributes
47
48
  end
48
49
  end
49
50
  end
@@ -11,7 +11,7 @@ class SerializerTest < ActiveSupport::TestCase
11
11
  @fluxor = Fluxor.create name: "Some text."
12
12
 
13
13
  # this is exactly what PaperTrail serializes
14
- @original_fluxor_attributes = @fluxor.send(:attributes_before_change)
14
+ @original_fluxor_attributes = @fluxor.paper_trail.attributes_before_change
15
15
 
16
16
  @fluxor.update_attributes name: "Some more text."
17
17
  end
@@ -41,7 +41,7 @@ class SerializerTest < ActiveSupport::TestCase
41
41
  @fluxor = Fluxor.create name: "Some text."
42
42
 
43
43
  # this is exactly what PaperTrail serializes
44
- @original_fluxor_attributes = @fluxor.send(:attributes_before_change)
44
+ @original_fluxor_attributes = @fluxor.paper_trail.attributes_before_change
45
45
 
46
46
  @fluxor.update_attributes name: "Some more text."
47
47
  end
@@ -85,7 +85,8 @@ class SerializerTest < ActiveSupport::TestCase
85
85
 
86
86
  # this is exactly what PaperTrail serializes
87
87
  @original_fluxor_attributes = @fluxor.
88
- send(:attributes_before_change).
88
+ paper_trail.
89
+ attributes_before_change.
89
90
  reject { |_k, v| v.nil? }
90
91
 
91
92
  @fluxor.update_attributes name: "Some more text."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-31 00:00:00.000000000 Z
12
+ date: 2016-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -344,7 +344,9 @@ files:
344
344
  - lib/paper_trail/frameworks/rspec/helpers.rb
345
345
  - lib/paper_trail/frameworks/sinatra.rb
346
346
  - lib/paper_trail/has_paper_trail.rb
347
+ - lib/paper_trail/model_config.rb
347
348
  - lib/paper_trail/record_history.rb
349
+ - lib/paper_trail/record_trail.rb
348
350
  - lib/paper_trail/reifier.rb
349
351
  - lib/paper_trail/serializers/json.rb
350
352
  - lib/paper_trail/serializers/yaml.rb