paper_trail 7.0.1 → 7.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e92a25394990bd883a845f051763e117abd5d35
4
- data.tar.gz: bde729a85a1052106a116e930f3afafdde5ca319
3
+ metadata.gz: e949aeba5c6caa0c2dd12fac0e624106793788f5
4
+ data.tar.gz: f12931432b3ddec15f99fecd87fe1cbdab54cdbf
5
5
  SHA512:
6
- metadata.gz: 7f2d6eba98c56942424310f2a3cc0c855c264eecc17fa0377dbb4bdad0ed0e15d66190e1043671af4c2f35c9605f0707565bdada142c1a5f8ce6b3eac203c8e3
7
- data.tar.gz: 99b7dd59468398c88e7c15f4e8b4fa6a2ba274a1aa8794a2caa8351d54cf6abdc51908449d26e71382b0505f08bcd0cdfbaa8fa2a030f9a76a391e84daafc8db
6
+ metadata.gz: 058a480c470909dfafaceb561857146a1bd53b0eae9b72411f818a45ee6f32394bcf57c1cfda46640b677ea6a0dd8235eda6ff517693f03b6fa3b441830dfa60
7
+ data.tar.gz: b4b941c3218ed3d45450970088b42af0ddcae58af02a17a44eb578c0e11a18a6495d115459d4a87953e87e6359853e39fda3b5c9257c16bfd441447fe6842209
@@ -147,7 +147,7 @@ Don't forget to commit changes to `schema.rb`.
147
147
  - Add a new "Unreleased" section
148
148
  1. In the readme, update references to version number, including
149
149
  - documentation links table
150
- - compatability table
150
+ - compatability table (major versions only)
151
151
  1. Commit
152
152
  1. git tag -a -m "v5.0.0" "v5.0.0" # or whatever number
153
153
  1. git push --tags origin 5-stable # or whatever branch
data/CHANGELOG.md CHANGED
@@ -17,6 +17,22 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
17
17
 
18
18
  - None
19
19
 
20
+ ## 7.0.2 (2017-04-26)
21
+
22
+ ### Breaking Changes
23
+
24
+ - None
25
+
26
+ ### Added
27
+
28
+ - [#932](https://github.com/airblade/paper_trail/pull/932) -
29
+ `PaperTrail.whodunnit` now accepts a block.
30
+
31
+ ### Fixed
32
+
33
+ - [#956](https://github.com/airblade/paper_trail/pull/956) -
34
+ Fix ActiveRecord >= 5.1 version check
35
+
20
36
  ## 7.0.1 (2017-04-10)
21
37
 
22
38
  ### Breaking Changes
data/README.md CHANGED
@@ -11,7 +11,7 @@ has been destroyed.
11
11
  | Version | Documentation |
12
12
  | -------------- | ------------- |
13
13
  | Unreleased | https://github.com/airblade/paper_trail/blob/master/README.md |
14
- | 7.0.1 | https://github.com/airblade/paper_trail/blob/v7.0.0/README.md |
14
+ | 7.0.2 | https://github.com/airblade/paper_trail/blob/v7.0.2/README.md |
15
15
  | 6.0.2 | https://github.com/airblade/paper_trail/blob/v6.0.2/README.md |
16
16
  | 5.2.3 | https://github.com/airblade/paper_trail/blob/v5.2.3/README.md |
17
17
  | 4.2.0 | https://github.com/airblade/paper_trail/blob/v4.2.0/README.md |
@@ -708,6 +708,14 @@ widget.update_attributes :name => 'Wibble'
708
708
  widget.versions.last.whodunnit # Andy Stewart
709
709
  ```
710
710
 
711
+ `whodunnit` also accepts a block, a convenient way to temporarily set the value.
712
+
713
+ ```ruby
714
+ PaperTrail.whodunnit("Dorian Marié") do
715
+ widget.update_attributes :name => 'Wibble'
716
+ end
717
+ ```
718
+
711
719
  If your controller has a `current_user` method, PaperTrail provides a
712
720
  `before_action` that will assign `current_user.id` to `PaperTrail.whodunnit`.
713
721
  You can add this `before_action` to your `ApplicationController`.
@@ -890,9 +898,6 @@ issues, in order of descending importance.
890
898
  1. PaperTrail only reifies the first level of associations.
891
899
  1. [#542](https://github.com/airblade/paper_trail/issues/542) -
892
900
  Not compatible with [transactional tests][34], aka. transactional fixtures.
893
- 1. [#841](https://github.com/airblade/paper_trail/issues/841) -
894
- Without a workaround, reified records cannot be persisted if their associated
895
- records have been deleted.
896
901
  1. Requires database timestamp columns with fractional second precision.
897
902
  - Sqlite and postgres timestamps have fractional second precision by default.
898
903
  [MySQL timestamps do not][35]. Furthermore, MySQL 5.5 and earlier do not
@@ -1,7 +1,8 @@
1
1
  module PaperTrail
2
2
  # Represents the "paper trail" for a single record.
3
3
  class RecordTrail
4
- RAILS_GTE_5_1 = ::ActiveRecord::VERSION::MAJOR >= 5 && ::ActiveRecord::VERSION::MINOR >= 1
4
+ RAILS_GTE_5_1 = ::ActiveRecord.respond_to?(:gem_version) &&
5
+ ::ActiveRecord.gem_version >= ::Gem::Version.new("5.1.0.beta1")
5
6
 
6
7
  def initialize(record)
7
8
  @record = record
@@ -7,7 +7,7 @@ module PaperTrail
7
7
  module VERSION
8
8
  MAJOR = 7
9
9
  MINOR = 0
10
- TINY = 1
10
+ TINY = 2
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
data/lib/paper_trail.rb CHANGED
@@ -87,10 +87,33 @@ module PaperTrail
87
87
  paper_trail_store[:whodunnit] = value
88
88
  end
89
89
 
90
- # Returns who is reponsible for any changes that occur.
90
+ # If nothing passed, returns who is reponsible for any changes that occur.
91
+ #
92
+ # PaperTrail.whodunnit = "someone"
93
+ # PaperTrail.whodunnit # => "someone"
94
+ #
95
+ # If value and block passed, set this value as whodunnit for the duration of the block
96
+ #
97
+ # PaperTrail.whodunnit("me") do
98
+ # puts PaperTrail.whodunnit # => "me"
99
+ # end
100
+ #
91
101
  # @api public
92
- def whodunnit
93
- paper_trail_store[:whodunnit]
102
+ def whodunnit(value = nil)
103
+ if value
104
+ raise ArgumentError, "no block given" unless block_given?
105
+
106
+ previous_whodunnit = paper_trail_store[:whodunnit]
107
+ paper_trail_store[:whodunnit] = value
108
+
109
+ begin
110
+ yield
111
+ ensure
112
+ paper_trail_store[:whodunnit] = previous_whodunnit
113
+ end
114
+ else
115
+ paper_trail_store[:whodunnit]
116
+ end
94
117
  end
95
118
 
96
119
  # Sets any information from the controller that you want PaperTrail to
@@ -75,10 +75,31 @@ RSpec.describe PaperTrail do
75
75
  end
76
76
 
77
77
  describe ".whodunnit" do
78
- before(:all) { described_class.whodunnit = "foobar" }
78
+ context "when set globally" do
79
+ before(:all) { described_class.whodunnit = "foobar" }
79
80
 
80
- it "is nil by default" do
81
- expect(described_class.whodunnit).to be_nil
81
+ it "is set to `nil` by default" do
82
+ expect(described_class.whodunnit).to be_nil
83
+ end
84
+ end
85
+
86
+ context "with block passed" do
87
+ it "sets whodunnit only for the block passed" do
88
+ described_class.whodunnit("foo") do
89
+ expect(described_class.whodunnit).to eq("foo")
90
+ end
91
+
92
+ expect(described_class.whodunnit).to be_nil
93
+ end
94
+
95
+ it "sets whodunnit only for the current thread" do
96
+ described_class.whodunnit("foo") do
97
+ expect(described_class.whodunnit).to eq("foo")
98
+ Thread.new { expect(described_class.whodunnit).to be_nil }.join
99
+ end
100
+
101
+ expect(described_class.whodunnit).to be_nil
102
+ end
82
103
  end
83
104
  end
84
105
 
@@ -829,7 +829,7 @@ class AssociationsTest < ActiveSupport::TestCase
829
829
  @widget.destroy
830
830
  end
831
831
 
832
- context "when reified" do
832
+ context "when reified with belongs_to: true" do
833
833
  setup { @wotsit2 = @wotsit.versions.last.reify(belongs_to: true) }
834
834
 
835
835
  should "see the associated as it was at the time" do
@@ -839,6 +839,22 @@ class AssociationsTest < ActiveSupport::TestCase
839
839
  should "not persist changes to the live association" do
840
840
  assert_nil @wotsit.reload.widget
841
841
  end
842
+
843
+ should "be able to persist the reified record" do
844
+ assert_nothing_raised { @wotsit2.save! }
845
+ end
846
+ end
847
+
848
+ context "when reified with belongs_to: false" do
849
+ setup do
850
+ @wotsit2 = @wotsit.versions.last.reify(belongs_to: false)
851
+ end
852
+
853
+ should "save should not re-create the widget record" do
854
+ # Save succeeds because Wotsit does not validate presence of widget
855
+ @wotsit2.save!
856
+ assert_nil ::Widget.find_by(id: @widget.id)
857
+ end
842
858
  end
843
859
 
844
860
  context "and then the model is updated" do
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: 7.0.1
4
+ version: 7.0.2
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: 2017-04-10 00:00:00.000000000 Z
12
+ date: 2017-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -487,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
487
487
  version: 1.3.6
488
488
  requirements: []
489
489
  rubyforge_project:
490
- rubygems_version: 2.6.10
490
+ rubygems_version: 2.2.5
491
491
  signing_key:
492
492
  specification_version: 4
493
493
  summary: Track changes to your models.