paper_trail 2.6.2 → 2.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -347,7 +347,7 @@ You can specify custom version subclasses with the `:class_name` option:
347
347
 
348
348
  class PostVersion < Version
349
349
  # custom behaviour, e.g:
350
- set_table_name :post_versions
350
+ self.table_name = :post_versions
351
351
  end
352
352
 
353
353
  class Post < ActiveRecord::Base
@@ -718,7 +718,8 @@ Many thanks to:
718
718
  * [Jason Noble](https://github.com/jasonnoble)
719
719
  * [Jared Mehle](https://github.com/jrmehle)
720
720
  * [Eric Schwartz](https://github.com/emschwar)
721
-
721
+ * [Ben Woosley](https://github.com/Empact)
722
+ * [Philip Arndt](https://github.com/parndt)
722
723
 
723
724
 
724
725
  ## Inspirations
@@ -7,12 +7,24 @@ class Version < ActiveRecord::Base
7
7
  scoped(:conditions => { :item_type => item_type, :item_id => item_id })
8
8
  end
9
9
 
10
+ def self.creates
11
+ where :event => 'create'
12
+ end
13
+
14
+ def self.updates
15
+ where :event => 'update'
16
+ end
17
+
18
+ def self.destroys
19
+ where :event => 'destroy'
20
+ end
21
+
10
22
  scope :subsequent, lambda { |version|
11
- where(["#{self.primary_key} > ?", version.is_a?(self) ? version.send(self.primary_key) : version]).order("#{self.primary_key} ASC")
23
+ where(["#{self.primary_key} > ?", version]).order("#{self.primary_key} ASC")
12
24
  }
13
25
 
14
26
  scope :preceding, lambda { |version|
15
- where(["#{self.primary_key} < ?", version.is_a?(self) ? version.send(self.primary_key) : version]).order("#{self.primary_key} DESC")
27
+ where(["#{self.primary_key} < ?", version]).order("#{self.primary_key} DESC")
16
28
  }
17
29
 
18
30
  scope :following, lambda { |timestamp|
@@ -68,9 +80,9 @@ class Version < ActiveRecord::Base
68
80
  end
69
81
 
70
82
  attrs.each do |k, v|
71
- begin
72
- model.send :write_attribute, k.to_sym , v
73
- rescue NoMethodError
83
+ if model.respond_to?("#{k}=")
84
+ model.send :write_attribute, k.to_sym, v
85
+ else
74
86
  logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
75
87
  end
76
88
  end
@@ -1,3 +1,3 @@
1
1
  module PaperTrail
2
- VERSION = '2.6.2'
2
+ VERSION = '2.6.3'
3
3
  end
@@ -15,10 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_dependency 'rails', '~> 3'
18
+ s.add_dependency 'railties', '~> 3.0'
19
+ s.add_dependency 'activerecord', '~> 3.0'
19
20
 
20
21
  s.add_development_dependency 'rake'
21
22
  s.add_development_dependency 'shoulda', '2.10.3'
22
- s.add_development_dependency 'sqlite3-ruby', '~> 1.2'
23
+ s.add_development_dependency 'sqlite3', '~> 1.2'
23
24
  s.add_development_dependency 'capybara', '~> 1.0.0'
24
25
  end
@@ -4,7 +4,6 @@ require "active_model/railtie"
4
4
  require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_view/railtie"
7
- require "action_mailer/railtie"
8
7
 
9
8
  Bundler.require
10
9
  require 'paper_trail'
@@ -23,7 +23,7 @@ Dummy::Application.configure do
23
23
  # Tell Action Mailer not to deliver emails to the real world.
24
24
  # The :test delivery method accumulates sent emails in the
25
25
  # ActionMailer::Base.deliveries array.
26
- config.action_mailer.delivery_method = :test
26
+ config.action_mailer.delivery_method = :test if config.respond_to?(:action_mailer)
27
27
 
28
28
  # Use SQL instead of Active Record's schema dumper when creating the test database.
29
29
  # This is necessary if your schema can't be completely dumped by the schema dumper,
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class VersionTest < ActiveSupport::TestCase
4
+ setup {
5
+ change_schema
6
+ @article = Animal.create
7
+ assert Version.creates.present?
8
+ }
9
+
10
+ context "Version.creates" do
11
+ should "return only create events" do
12
+ Version.creates.each do |version|
13
+ assert_equal "create", version.event
14
+ end
15
+ end
16
+ end
17
+
18
+ context "Version.updates" do
19
+ setup {
20
+ @article.update_attributes(:name => 'Animal')
21
+ assert Version.updates.present?
22
+ }
23
+
24
+ should "return only update events" do
25
+ Version.updates.each do |version|
26
+ assert_equal "update", version.event
27
+ end
28
+ end
29
+ end
30
+
31
+ context "Version.destroys" do
32
+ setup {
33
+ @article.destroy
34
+ assert Version.destroys.present?
35
+ }
36
+
37
+ should "return only destroy events" do
38
+ Version.destroys.each do |version|
39
+ assert_equal "destroy", version.event
40
+ end
41
+ end
42
+ end
43
+ end
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 6
9
- - 2
10
- version: 2.6.2
9
+ - 3
10
+ version: 2.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,27 +15,43 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-12 00:00:00 +01:00
18
+ date: 2012-03-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rails
22
+ name: railties
23
23
  prerelease: false
24
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 5
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
- version: "3"
32
+ - 0
33
+ version: "3.0"
33
34
  type: :runtime
34
35
  requirement: *id001
35
36
  - !ruby/object:Gem::Dependency
36
- name: rake
37
+ name: activerecord
37
38
  prerelease: false
38
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 3
47
+ - 0
48
+ version: "3.0"
49
+ type: :runtime
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
53
+ prerelease: false
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
55
  none: false
40
56
  requirements:
41
57
  - - ">="
@@ -45,11 +61,11 @@ dependencies:
45
61
  - 0
46
62
  version: "0"
47
63
  type: :development
48
- requirement: *id002
64
+ requirement: *id003
49
65
  - !ruby/object:Gem::Dependency
50
66
  name: shoulda
51
67
  prerelease: false
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
53
69
  none: false
54
70
  requirements:
55
71
  - - "="
@@ -61,11 +77,11 @@ dependencies:
61
77
  - 3
62
78
  version: 2.10.3
63
79
  type: :development
64
- requirement: *id003
80
+ requirement: *id004
65
81
  - !ruby/object:Gem::Dependency
66
- name: sqlite3-ruby
82
+ name: sqlite3
67
83
  prerelease: false
68
- version_requirements: &id004 !ruby/object:Gem::Requirement
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
69
85
  none: false
70
86
  requirements:
71
87
  - - ~>
@@ -76,11 +92,11 @@ dependencies:
76
92
  - 2
77
93
  version: "1.2"
78
94
  type: :development
79
- requirement: *id004
95
+ requirement: *id005
80
96
  - !ruby/object:Gem::Dependency
81
97
  name: capybara
82
98
  prerelease: false
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
84
100
  none: false
85
101
  requirements:
86
102
  - - ~>
@@ -92,7 +108,7 @@ dependencies:
92
108
  - 0
93
109
  version: 1.0.0
94
110
  type: :development
95
- requirement: *id005
111
+ requirement: *id006
96
112
  description: Track changes to your models' data. Good for auditing or versioning.
97
113
  email: boss@airbladesoftware.com
98
114
  executables: []
@@ -181,6 +197,7 @@ files:
181
197
  - test/unit/inheritance_column_test.rb
182
198
  - test/unit/model_test.rb
183
199
  - test/unit/timestamp_test.rb
200
+ - test/unit/version_test.rb
184
201
  has_rdoc: true
185
202
  homepage: http://github.com/airblade/paper_trail
186
203
  licenses: []
@@ -278,3 +295,4 @@ test_files:
278
295
  - test/unit/inheritance_column_test.rb
279
296
  - test/unit/model_test.rb
280
297
  - test/unit/timestamp_test.rb
298
+ - test/unit/version_test.rb