paper_trail 2.2.9 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
- # PaperTrail
1
+ # PaperTrail [![Build Status](http://travis-ci.org/airblade/paper_trail.png)](http://travis-ci.org/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
 
5
5
  There's an excellent [Railscast on implementing Undo with Paper Trail](http://railscasts.com/episodes/255-undo-with-paper-trail).
6
6
 
7
+
7
8
  ## Features
8
9
 
9
- * Stores every create, update and destroy.
10
+ * Stores every create, update and destroy (or only the lifecycle events you specify).
10
11
  * Does not store updates which don't change anything.
11
12
  * Allows you to specify attributes (by inclusion or exclusion) which must change for a Version to be stored.
12
13
  * Allows you to get at every version, including the original, even once destroyed.
@@ -168,6 +169,16 @@ Here's a helpful table showing what PaperTrail stores:
168
169
  PaperTrail stores the values in the Model Before column. Most other auditing/versioning plugins store the After column.
169
170
 
170
171
 
172
+ ## Choosing Lifecycle Events To Monitor
173
+
174
+ You can choose which events to track with the `on` option. For example, to ignore `create` events:
175
+
176
+ class Article < ActiveRecord::Base
177
+ has_paper_trail :on => [:update, :destroy]
178
+ end
179
+
180
+
181
+
171
182
  ## Choosing Attributes To Monitor
172
183
 
173
184
  You can ignore changes to certain attributes like this:
@@ -331,7 +342,7 @@ Alternatively you could store certain metadata for one type of version, and othe
331
342
  You can also specify a custom name for the versions association. This is useful if you already have a `versions` method on your model. For example:
332
343
 
333
344
  class Post < ActiveRecord::Base
334
- has_paper_trail :versions_association_name => :paper_trail_versions
345
+ has_paper_trail :versions => :paper_trail_versions
335
346
 
336
347
  # Existing versions method. We don't want to clash.
337
348
  def versions
@@ -11,6 +11,8 @@ module PaperTrail
11
11
  # the model is available in the `versions` association.
12
12
  #
13
13
  # Options:
14
+ # :on the events to track (optional; defaults to all of them). Set to an array of
15
+ # `:create`, `:update`, `:destroy` as desired.
14
16
  # :class_name the name of a custom Version class. This class should inherit from Version.
15
17
  # :ignore an array of attributes for which a new `Version` will not be created if only they change.
16
18
  # :only inverse of `ignore` - a new `Version` will be created only for these attributes if supplied
@@ -18,7 +20,7 @@ module PaperTrail
18
20
  # Values are objects or procs (which are called with `self`, i.e. the model with the paper
19
21
  # trail). See `PaperTrail::Controller.info_for_paper_trail` for how to store data from
20
22
  # the controller.
21
- # :versions_association_name the name to use for the versions association. Default is `:versions`.
23
+ # :versions the name to use for the versions association. Default is `:versions`.
22
24
  def has_paper_trail(options = {})
23
25
  # Lazily include the instance methods so we don't clutter up
24
26
  # any more ActiveRecord models than we have to.
@@ -50,9 +52,9 @@ module PaperTrail
50
52
  :as => :item,
51
53
  :order => "created_at ASC, #{self.primary_key} ASC"
52
54
 
53
- after_create :record_create
54
- before_update :record_update
55
- after_destroy :record_destroy
55
+ after_create :record_create if !options[:on] || options[:on].include?(:create)
56
+ before_update :record_update if !options[:on] || options[:on].include?(:update)
57
+ after_destroy :record_destroy if !options[:on] || options[:on].include?(:destroy)
56
58
  end
57
59
 
58
60
  # Switches PaperTrail off for this class.
@@ -1,3 +1,3 @@
1
1
  module PaperTrail
2
- VERSION = '2.2.9'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -1,3 +1,4 @@
1
1
  class Document < ActiveRecord::Base
2
- has_paper_trail :versions => :paper_trail_versions
2
+ has_paper_trail :versions => :paper_trail_versions,
3
+ :on => [:create, :update]
3
4
  end
@@ -833,6 +833,57 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
833
833
  end
834
834
  end
835
835
 
836
+ context 'The `on` option' do
837
+ context 'on create' do
838
+ setup do
839
+ Fluxor.instance_eval <<-END
840
+ has_paper_trail :on => [:create]
841
+ END
842
+ @fluxor = Fluxor.create
843
+ @fluxor.update_attributes :name => 'blah'
844
+ @fluxor.destroy
845
+ end
846
+ should 'only have a version for the create event' do
847
+ assert_equal 1, @fluxor.versions.length
848
+ assert_equal 'create', @fluxor.versions.last.event
849
+ end
850
+ end
851
+ context 'on update' do
852
+ setup do
853
+ Fluxor.reset_callbacks :create
854
+ Fluxor.reset_callbacks :update
855
+ Fluxor.reset_callbacks :destroy
856
+ Fluxor.instance_eval <<-END
857
+ has_paper_trail :on => [:update]
858
+ END
859
+ @fluxor = Fluxor.create
860
+ @fluxor.update_attributes :name => 'blah'
861
+ @fluxor.destroy
862
+ end
863
+ should 'only have a version for the update event' do
864
+ assert_equal 1, @fluxor.versions.length
865
+ assert_equal 'update', @fluxor.versions.last.event
866
+ end
867
+ end
868
+ context 'on destroy' do
869
+ setup do
870
+ Fluxor.reset_callbacks :create
871
+ Fluxor.reset_callbacks :update
872
+ Fluxor.reset_callbacks :destroy
873
+ Fluxor.instance_eval <<-END
874
+ has_paper_trail :on => [:destroy]
875
+ END
876
+ @fluxor = Fluxor.create
877
+ @fluxor.update_attributes :name => 'blah'
878
+ @fluxor.destroy
879
+ end
880
+ should 'only have a version for the destroy event' do
881
+ assert_equal 1, @fluxor.versions.length
882
+ assert_equal 'destroy', @fluxor.versions.last.event
883
+ end
884
+ end
885
+ end
886
+
836
887
  private
837
888
 
838
889
  # Updates `model`'s last version so it looks like the version was
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 2
9
- - 9
10
- version: 2.2.9
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-23 00:00:00 +01:00
18
+ date: 2011-08-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
 
104
104
  files:
105
105
  - .gitignore
106
+ - .travis.yml
106
107
  - Gemfile
107
108
  - MIT-LICENSE
108
109
  - README.md