paper_trail 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -335,28 +335,33 @@ To find out who made a `version`'s object look that way, use `version.originator
335
335
 
336
336
  You can specify custom version subclasses with the `:class_name` option:
337
337
 
338
- class Post < ActiveRecord::Base
339
- has_paper_trail :class_name => 'PostVersion'
340
- end
341
-
342
338
  class PostVersion < Version
343
339
  # custom behaviour, e.g:
344
340
  set_table_name :post_versions
345
341
  end
346
342
 
343
+ class Post < ActiveRecord::Base
344
+ has_paper_trail :class_name => 'PostVersion'
345
+ end
346
+
347
347
  This allows you to store each model's versions in a separate table, which is useful if you have a lot of versions being created.
348
348
 
349
349
  Alternatively you could store certain metadata for one type of version, and other metadata for other versions.
350
350
 
351
- 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:
351
+ You can also specify custom names for the versions and version associations. This is useful if you already have `versions` or/and `version` methods on your model. For example:
352
352
 
353
353
  class Post < ActiveRecord::Base
354
- has_paper_trail :versions => :paper_trail_versions
354
+ has_paper_trail :versions => :paper_trail_versions,
355
+ :version => :paper_trail_version
355
356
 
356
357
  # Existing versions method. We don't want to clash.
357
358
  def versions
358
359
  ...
359
360
  end
361
+ # Existing version method. We don't want to clash.
362
+ def version
363
+ ...
364
+ end
360
365
  end
361
366
 
362
367
 
@@ -633,6 +638,17 @@ Please see the `rails2` branch.
633
638
 
634
639
  PaperTrail uses Bundler to manage its dependencies (in development and testing). You can run the tests with `bundle exec rake test`. (You may need to `bundle install` first.)
635
640
 
641
+ It's a good idea to reset PaperTrail before each test so data from one test doesn't spill over another. For example:
642
+
643
+ RSpec.configure do |config|
644
+ config.before :each do
645
+ PaperTrail.controller_info = {}
646
+ PaperTrail.whodunnit = nil
647
+ end
648
+ end
649
+
650
+ You may want to turn PaperTrail off to speed up your tests. See the "Turning PaperTrail Off/On" section above.
651
+
636
652
 
637
653
  ## Articles
638
654
 
@@ -672,6 +688,7 @@ Many thanks to:
672
688
  * [Mathieu Arnold](https://github.com/mat813)
673
689
  * [Nicholas Thrower](https://github.com/throwern)
674
690
  * [Benjamin Curtis](https://github.com/stympy)
691
+ * [Peter Harkins](https://github.com/pushcx)
675
692
 
676
693
 
677
694
  ## Inspirations
@@ -24,18 +24,18 @@ module PaperTrail
24
24
  # trail). See `PaperTrail::Controller.info_for_paper_trail` for how to store data from
25
25
  # the controller.
26
26
  # :versions the name to use for the versions association. Default is `:versions`.
27
- # :version_name the name to use for the method which returns the version the instance was reified from.
27
+ # :version the name to use for the method which returns the version the instance was reified from.
28
28
  # Default is `:version`.
29
29
  def has_paper_trail(options = {})
30
30
  # Lazily include the instance methods so we don't clutter up
31
31
  # any more ActiveRecord models than we have to.
32
32
  send :include, InstanceMethods
33
33
 
34
- class_attribute :version_name
35
- self.version_name = options[:version_name] || 'version'
34
+ class_attribute :version_association_name
35
+ self.version_association_name = options[:version] || :version
36
36
 
37
37
  # The version this instance was reified from.
38
- attr_accessor self.version_name
38
+ attr_accessor self.version_association_name
39
39
 
40
40
  class_attribute :version_class_name
41
41
  self.version_class_name = options[:class_name] || 'Version'
@@ -131,7 +131,7 @@ module PaperTrail
131
131
  end
132
132
 
133
133
  def source_version
134
- send self.class.version_name
134
+ send self.class.version_association_name
135
135
  end
136
136
 
137
137
  def record_create
@@ -69,7 +69,7 @@ class Version < ActiveRecord::Base
69
69
  end
70
70
  end
71
71
 
72
- model.send "#{model.class.version_name}=", self
72
+ model.send "#{model.class.version_association_name}=", self
73
73
 
74
74
  unless options[:has_one] == false
75
75
  reify_has_ones model, options[:has_one]
@@ -1,3 +1,3 @@
1
1
  module PaperTrail
2
- VERSION = '2.4.1'
2
+ VERSION = '2.5.0'
3
3
  end
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency 'rails', '~> 3'
19
19
 
20
+ s.add_development_dependency 'rake'
20
21
  s.add_development_dependency 'shoulda', '2.10.3'
21
22
  s.add_development_dependency 'sqlite3-ruby', '~> 1.2'
22
23
  s.add_development_dependency 'capybara', '>= 0.4.0'
@@ -1,3 +1,4 @@
1
1
  class LegacyWidget < ActiveRecord::Base
2
- has_paper_trail :version_name => 'custom_version'
2
+ has_paper_trail :ignore => :version,
3
+ :version => 'custom_version'
3
4
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class HasPaperTrailModelTest < ActiveSupport::TestCase
4
4
 
5
- context 'A record' do
5
+ context 'A record with defined "only" and "ignore" attributes' do
6
6
  setup { @article = Article.create }
7
7
 
8
8
  context 'which updates an ignored column' do
@@ -28,12 +28,12 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
28
28
  setup { @article.update_attributes :abstract => 'Other abstract'}
29
29
  should_not_change('the number of versions') { Version.count }
30
30
  end
31
-
31
+
32
32
  context 'which updates a skipped column' do
33
33
  setup { @article.update_attributes :file_upload => 'Your data goes here' }
34
34
  should_not_change('the number of versions') { Version.count }
35
35
  end
36
-
36
+
37
37
  context 'which updates a skipped column and a selected column' do
38
38
  setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
39
39
  should_change('the number of versions', :by => 1) { Version.count }
@@ -41,23 +41,31 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
41
41
  should 'have stored only non-skipped attributes' do
42
42
  assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
43
43
  end
44
-
44
+
45
45
  context 'and when updated again' do
46
46
  setup do
47
47
  @article.update_attributes :file_upload => 'More data goes here', :content => 'More text here.'
48
48
  @old_article = @article.versions.last
49
49
  end
50
-
50
+
51
51
  should 'have removed the skipped attributes when saving the previous version' do
52
52
  assert_equal nil, YAML::load(@old_article.object)['file_upload']
53
53
  end
54
-
54
+
55
55
  should 'have kept the non-skipped attributes in the previous version' do
56
56
  assert_equal 'Some text here.', YAML::load(@old_article.object)['content']
57
57
  end
58
58
  end
59
59
  end
60
-
60
+ end
61
+
62
+ context 'A record with defined "ignore" attribute' do
63
+ setup { @legacy_widget = LegacyWidget.create }
64
+
65
+ context 'which updates an ignored column' do
66
+ setup { @legacy_widget.update_attributes :version => 1 }
67
+ should_not_change('the number of versions') { Version.count }
68
+ end
61
69
  end
62
70
 
63
71
 
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 4
9
- - 1
10
- version: 2.4.1
8
+ - 5
9
+ - 0
10
+ version: 2.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-09 00:00:00 +01:00
18
+ date: 2011-11-11 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rails
23
23
  prerelease: false
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
@@ -31,11 +31,25 @@ dependencies:
31
31
  - 3
32
32
  version: "3"
33
33
  type: :runtime
34
- requirement: *id001
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: shoulda
37
51
  prerelease: false
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
39
53
  none: false
40
54
  requirements:
41
55
  - - "="
@@ -47,11 +61,11 @@ dependencies:
47
61
  - 3
48
62
  version: 2.10.3
49
63
  type: :development
50
- requirement: *id002
64
+ version_requirements: *id003
51
65
  - !ruby/object:Gem::Dependency
52
66
  name: sqlite3-ruby
53
67
  prerelease: false
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
55
69
  none: false
56
70
  requirements:
57
71
  - - ~>
@@ -62,11 +76,11 @@ dependencies:
62
76
  - 2
63
77
  version: "1.2"
64
78
  type: :development
65
- requirement: *id003
79
+ version_requirements: *id004
66
80
  - !ruby/object:Gem::Dependency
67
81
  name: capybara
68
82
  prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
83
+ requirement: &id005 !ruby/object:Gem::Requirement
70
84
  none: false
71
85
  requirements:
72
86
  - - ">="
@@ -78,11 +92,11 @@ dependencies:
78
92
  - 0
79
93
  version: 0.4.0
80
94
  type: :development
81
- requirement: *id004
95
+ version_requirements: *id005
82
96
  - !ruby/object:Gem::Dependency
83
97
  name: turn
84
98
  prerelease: false
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
99
+ requirement: &id006 !ruby/object:Gem::Requirement
86
100
  none: false
87
101
  requirements:
88
102
  - - ">="
@@ -92,7 +106,7 @@ dependencies:
92
106
  - 0
93
107
  version: "0"
94
108
  type: :development
95
- requirement: *id005
109
+ version_requirements: *id006
96
110
  description: Track changes to your models' data. Good for auditing or versioning.
97
111
  email: boss@airbladesoftware.com
98
112
  executables: []