paper_trail 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +3 -3
- data/lib/paper_trail/has_paper_trail.rb +9 -1
- data/lib/paper_trail/version_number.rb +1 -1
- data/spec/models/gadget_spec.rb +68 -0
- data/test/dummy/app/models/gadget.rb +3 -0
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +7 -0
- data/test/unit/model_test.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 342a6b8d2c4c6685107d14ae36f6711d7fe09d78
|
4
|
+
data.tar.gz: f7d83394a6bb503a898509b26e9adf0f712c1dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d240d05e510adf0a4e178a27cda8e490b99750384a15af935daa6019f02f8ce944c7894fdea76fb970a07dde7bdbbf62de8c314a24f5684f961d8da949fe3b64
|
7
|
+
data.tar.gz: 078716e13039aebf41ea3c10e78180e78d1879ab30095a39298678bb88e6e5659a760f67449cbffee22492419943988df53eac04417fd8da8259804a08fe4732
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
## 3.0.6
|
2
|
+
|
3
|
+
- [#414](https://github.com/airblade/paper_trail/issues/414) - Fix functionality `ignore` argument to `has_paper_trail`
|
4
|
+
in `ActiveRecord` 4.
|
5
|
+
|
1
6
|
## 3.0.5
|
2
7
|
|
3
8
|
- [#401](https://github.com/airblade/paper_trail/issues/401) / [#406](https://github.com/airblade/paper_trail/issues/406)
|
4
9
|
`PaperTrail::Version` class is not loaded via a `Rails::Engine`, even when the gem is used with in Rails. This feature has
|
5
10
|
will be re-introduced in version `3.1.0`.
|
11
|
+
- [#398](https://github.com/airblade/paper_trail/pull/398) - Only require the `RSpec` helper if `RSpec::Core` is required.
|
6
12
|
|
7
13
|
## 3.0.3
|
8
|
-
*This version was yanked from RubyGems and has been replaced by version `3.0.5`, which is identical but does not eager load
|
14
|
+
*This version was yanked from RubyGems and has been replaced by version `3.0.5`, which is almost identical, but does not eager load
|
9
15
|
in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is used on Rails since it was causing issues for some users.*
|
10
16
|
|
11
17
|
- [#386](https://github.com/airblade/paper_trail/issues/386) - Fix eager loading of `versions` association with custom class name
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# PaperTrail [![Build Status](https://
|
1
|
+
# PaperTrail [![Build Status](https://travis-ci.org/airblade/paper_trail.svg?branch=3.0-stable)](https://travis-ci.org/airblade/paper_trail) [![Dependency Status](https://img.shields.io/gemnasium/airblade/paper_trail.svg)](https://gemnasium.com/airblade/paper_trail)
|
2
2
|
|
3
3
|
PaperTrail lets you track changes to your models' data. It's good for auditing or versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it's been destroyed.
|
4
4
|
|
@@ -42,7 +42,7 @@ The Rails 2.3 code is on the [`rails2`](https://github.com/airblade/paper_trail/
|
|
42
42
|
|
43
43
|
1. Add PaperTrail to your `Gemfile`.
|
44
44
|
|
45
|
-
`gem 'paper_trail', '~> 3.0.
|
45
|
+
`gem 'paper_trail', '~> 3.0.6'`
|
46
46
|
|
47
47
|
2. Generate a migration which will add a `versions` table to your database.
|
48
48
|
|
@@ -64,7 +64,7 @@ your applications `ActiveRecord` connection in a manner similar to the way `Rail
|
|
64
64
|
|
65
65
|
1. Add PaperTrail to your `Gemfile`.
|
66
66
|
|
67
|
-
`gem 'paper_trail', '~> 3.0.
|
67
|
+
`gem 'paper_trail', '~> 3.0.6'`
|
68
68
|
|
69
69
|
2. Generate a migration to add a `versions` table to your database.
|
70
70
|
|
@@ -360,8 +360,16 @@ module PaperTrail
|
|
360
360
|
end
|
361
361
|
end
|
362
362
|
|
363
|
+
# This method is invoked in order to determine whether it is appropriate to generate a new version instance.
|
364
|
+
# In ActiveRecord 4, the way ActiveModel::Dirty handles the `changes` hash has changed so that
|
365
|
+
# `timestamp_attributes_for_update` get inserted PRIOR to the persistence happening, so we must accomodate
|
366
|
+
# this by checking to ensure attributes other than those ignored and update timestamps are really being modified.
|
363
367
|
def changed_notably?
|
364
|
-
|
368
|
+
if self.paper_trail_options[:ignore].any? && (changed & self.paper_trail_options[:ignore]).any?
|
369
|
+
(notably_changed - timestamp_attributes_for_update_in_model.map(&:to_s)).any?
|
370
|
+
else
|
371
|
+
notably_changed.any?
|
372
|
+
end
|
365
373
|
end
|
366
374
|
|
367
375
|
def notably_changed
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gadget do
|
4
|
+
it { should be_versioned }
|
5
|
+
|
6
|
+
let(:gadget) { Gadget.create!(:name => 'Wrench', :brand => 'Acme') }
|
7
|
+
|
8
|
+
describe "updates", :versioning => true do
|
9
|
+
it "should generate a version for updates to `name` attribute" do
|
10
|
+
expect { gadget.update_attribute(:name, 'Hammer').to change{gadget.versions.size}.by(1) }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should ignore for updates to `brand` attribute" do
|
14
|
+
expect { gadget.update_attribute(:brand, 'Stanley') }.to_not change{gadget.versions.size}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should still generate a version when only the `updated_at` attribute is updated" do
|
18
|
+
expect { gadget.update_attribute(:updated_at, Time.now) }.to change{gadget.versions.size}.by(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Methods" do
|
23
|
+
describe "Instance", :versioning => true do
|
24
|
+
describe "private" do
|
25
|
+
describe :changed_notably? do
|
26
|
+
subject { Gadget.new(:created_at => Time.now) }
|
27
|
+
|
28
|
+
# apparently the private methods list in Ruby18 is different than in Ruby19+
|
29
|
+
if RUBY_VERSION.to_f >= 1.9
|
30
|
+
its(:private_methods) { should include(:changed_notably?) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "create events" do
|
34
|
+
it { subject.send(:changed_notably?).should == true }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "update events" do
|
38
|
+
before { subject.save! }
|
39
|
+
|
40
|
+
context "without update timestamps" do
|
41
|
+
it "should only acknowledge non-ignored attrs" do
|
42
|
+
subject.name = 'Wrench'
|
43
|
+
subject.send(:changed_notably?).should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not acknowledge ignored attrs and timestamps only" do
|
47
|
+
subject.brand = 'Acme'
|
48
|
+
subject.send(:changed_notably?).should == false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with update timestamps" do
|
53
|
+
it "should only acknowledge non-ignored attrs" do
|
54
|
+
subject.name, subject.updated_at = 'Wrench', Time.now
|
55
|
+
subject.send(:changed_notably?).should == true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not acknowledge ignored attrs and timestamps only" do
|
59
|
+
subject.brand, subject.updated_at = 'Acme', Time.now
|
60
|
+
subject.send(:changed_notably?).should == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -116,6 +116,12 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
116
116
|
t.string :language_code
|
117
117
|
t.string :type
|
118
118
|
end
|
119
|
+
|
120
|
+
create_table :gadgets, :force => true do |t|
|
121
|
+
t.string :name
|
122
|
+
t.string :brand
|
123
|
+
t.timestamps
|
124
|
+
end
|
119
125
|
end
|
120
126
|
|
121
127
|
def self.down
|
@@ -136,5 +142,6 @@ class SetUpTestTables < ActiveRecord::Migration
|
|
136
142
|
drop_table :documents
|
137
143
|
drop_table :legacy_widgets
|
138
144
|
drop_table :translations
|
145
|
+
drop_table :gadgets
|
139
146
|
end
|
140
147
|
end
|
data/test/unit/model_test.rb
CHANGED
@@ -224,7 +224,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
224
224
|
'id' => [nil, @widget.id]
|
225
225
|
}
|
226
226
|
|
227
|
-
assert_equal
|
227
|
+
assert_equal Time, @widget.versions.last.changeset['updated_at'][1].class
|
228
228
|
assert_equal changes, @widget.versions.last.changeset
|
229
229
|
end
|
230
230
|
|
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: 3.0.
|
4
|
+
version: 3.0.6
|
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: 2014-
|
12
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -263,6 +263,7 @@ files:
|
|
263
263
|
- lib/paper_trail/version_number.rb
|
264
264
|
- paper_trail.gemspec
|
265
265
|
- spec/generators/install_generator_spec.rb
|
266
|
+
- spec/models/gadget_spec.rb
|
266
267
|
- spec/models/joined_version_spec.rb
|
267
268
|
- spec/models/post_with_status_spec.rb
|
268
269
|
- spec/models/version_spec.rb
|
@@ -290,6 +291,7 @@ files:
|
|
290
291
|
- test/dummy/app/models/elephant.rb
|
291
292
|
- test/dummy/app/models/fluxor.rb
|
292
293
|
- test/dummy/app/models/foo_widget.rb
|
294
|
+
- test/dummy/app/models/gadget.rb
|
293
295
|
- test/dummy/app/models/legacy_widget.rb
|
294
296
|
- test/dummy/app/models/person.rb
|
295
297
|
- test/dummy/app/models/post.rb
|
@@ -378,6 +380,7 @@ specification_version: 4
|
|
378
380
|
summary: Track changes to your models' data. Good for auditing or versioning.
|
379
381
|
test_files:
|
380
382
|
- spec/generators/install_generator_spec.rb
|
383
|
+
- spec/models/gadget_spec.rb
|
381
384
|
- spec/models/joined_version_spec.rb
|
382
385
|
- spec/models/post_with_status_spec.rb
|
383
386
|
- spec/models/version_spec.rb
|
@@ -405,6 +408,7 @@ test_files:
|
|
405
408
|
- test/dummy/app/models/elephant.rb
|
406
409
|
- test/dummy/app/models/fluxor.rb
|
407
410
|
- test/dummy/app/models/foo_widget.rb
|
411
|
+
- test/dummy/app/models/gadget.rb
|
408
412
|
- test/dummy/app/models/legacy_widget.rb
|
409
413
|
- test/dummy/app/models/person.rb
|
410
414
|
- test/dummy/app/models/post.rb
|