paper_trail 1.6.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +107 -0
- data/MIT-LICENSE +20 -0
- data/README.md +11 -5
- data/Rakefile +1 -1
- data/lib/paper_trail.rb +9 -4
- data/lib/paper_trail/controller.rb +0 -2
- data/lib/paper_trail/has_paper_trail.rb +2 -3
- data/lib/paper_trail/version.rb +15 -18
- data/lib/paper_trail/version_number.rb +1 -1
- data/paper_trail.gemspec +17 -24
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +16 -0
- data/test/dummy/app/controllers/test_controller.rb +5 -0
- data/test/dummy/app/controllers/widgets_controller.rb +18 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/article.rb +11 -0
- data/test/dummy/app/models/authorship.rb +5 -0
- data/test/dummy/app/models/book.rb +5 -0
- data/test/dummy/app/models/fluxor.rb +3 -0
- data/test/dummy/app/models/foo_widget.rb +2 -0
- data/test/dummy/app/models/person.rb +5 -0
- data/test/dummy/app/models/song.rb +12 -0
- data/test/dummy/app/models/widget.rb +5 -0
- data/test/dummy/app/models/wotsit.rb +4 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +84 -0
- data/test/dummy/db/schema.rb +82 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +175 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/{paper_trail_controller_test.rb → functional/controller_test.rb} +7 -44
- data/test/{thread_safe_test.rb → functional/thread_safety_test.rb} +1 -7
- data/test/integration/navigation_test.rb +7 -0
- data/test/paper_trail_test.rb +7 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +27 -33
- data/test/{paper_trail_model_test.rb → unit/model_test.rb} +5 -68
- metadata +138 -123
- data/generators/paper_trail/USAGE +0 -2
- data/generators/paper_trail/paper_trail_generator.rb +0 -9
- data/generators/paper_trail/templates/create_versions.rb +0 -18
- data/init.rb +0 -1
- data/install.rb +0 -1
- data/test/paper_trail_schema_test.rb +0 -15
- data/test/schema.rb +0 -71
- data/test/schema_change.rb +0 -3
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paper_trail (2.0.0)
|
5
|
+
rails (~> 3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionmailer (3.0.3)
|
12
|
+
actionpack (= 3.0.3)
|
13
|
+
mail (~> 2.2.9)
|
14
|
+
actionpack (3.0.3)
|
15
|
+
activemodel (= 3.0.3)
|
16
|
+
activesupport (= 3.0.3)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.4)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.13)
|
22
|
+
rack-test (~> 0.5.6)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.3)
|
25
|
+
activesupport (= 3.0.3)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.4)
|
28
|
+
activerecord (3.0.3)
|
29
|
+
activemodel (= 3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
arel (~> 2.0.2)
|
32
|
+
tzinfo (~> 0.3.23)
|
33
|
+
activeresource (3.0.3)
|
34
|
+
activemodel (= 3.0.3)
|
35
|
+
activesupport (= 3.0.3)
|
36
|
+
activesupport (3.0.3)
|
37
|
+
arel (2.0.7)
|
38
|
+
builder (2.1.2)
|
39
|
+
capybara (0.4.1.1)
|
40
|
+
celerity (>= 0.7.9)
|
41
|
+
culerity (>= 0.2.4)
|
42
|
+
mime-types (>= 1.16)
|
43
|
+
nokogiri (>= 1.3.3)
|
44
|
+
rack (>= 1.0.0)
|
45
|
+
rack-test (>= 0.5.4)
|
46
|
+
selenium-webdriver (>= 0.0.27)
|
47
|
+
xpath (~> 0.1.3)
|
48
|
+
celerity (0.8.7)
|
49
|
+
childprocess (0.1.6)
|
50
|
+
ffi (~> 0.6.3)
|
51
|
+
culerity (0.2.15)
|
52
|
+
erubis (2.6.6)
|
53
|
+
abstract (>= 1.0.0)
|
54
|
+
ffi (0.6.3)
|
55
|
+
rake (>= 0.8.7)
|
56
|
+
i18n (0.5.0)
|
57
|
+
json_pure (1.5.1)
|
58
|
+
mail (2.2.15)
|
59
|
+
activesupport (>= 2.3.6)
|
60
|
+
i18n (>= 0.4.0)
|
61
|
+
mime-types (~> 1.16)
|
62
|
+
treetop (~> 1.4.8)
|
63
|
+
mime-types (1.16)
|
64
|
+
nokogiri (1.4.4)
|
65
|
+
polyglot (0.3.1)
|
66
|
+
rack (1.2.1)
|
67
|
+
rack-mount (0.6.13)
|
68
|
+
rack (>= 1.0.0)
|
69
|
+
rack-test (0.5.7)
|
70
|
+
rack (>= 1.0)
|
71
|
+
rails (3.0.3)
|
72
|
+
actionmailer (= 3.0.3)
|
73
|
+
actionpack (= 3.0.3)
|
74
|
+
activerecord (= 3.0.3)
|
75
|
+
activeresource (= 3.0.3)
|
76
|
+
activesupport (= 3.0.3)
|
77
|
+
bundler (~> 1.0)
|
78
|
+
railties (= 3.0.3)
|
79
|
+
railties (3.0.3)
|
80
|
+
actionpack (= 3.0.3)
|
81
|
+
activesupport (= 3.0.3)
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
thor (~> 0.14.4)
|
84
|
+
rake (0.8.7)
|
85
|
+
rubyzip (0.9.4)
|
86
|
+
selenium-webdriver (0.1.2)
|
87
|
+
childprocess (~> 0.1.5)
|
88
|
+
ffi (~> 0.6.3)
|
89
|
+
json_pure
|
90
|
+
rubyzip
|
91
|
+
shoulda (2.10.3)
|
92
|
+
sqlite3-ruby (1.3.1)
|
93
|
+
thor (0.14.6)
|
94
|
+
treetop (1.4.9)
|
95
|
+
polyglot (>= 0.3.1)
|
96
|
+
tzinfo (0.3.24)
|
97
|
+
xpath (0.1.3)
|
98
|
+
nokogiri (~> 1.3)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
capybara (>= 0.4.0)
|
105
|
+
paper_trail!
|
106
|
+
shoulda (= 2.10.3)
|
107
|
+
sqlite3-ruby (~> 1.2)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andy Stewart, AirBlade Software Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ PaperTrail lets you track changes to your models' data. It's good for auditing
|
|
26
26
|
|
27
27
|
## Rails Version
|
28
28
|
|
29
|
-
Works on Rails 3 and Rails 2.3.
|
29
|
+
Works on Rails 3 and Rails 2.3. The Rails 3 code is on the master branch and tagged v2.x. The Rails 2.3 code is on the Rails 2 branch and tagged 1.x.
|
30
30
|
|
31
31
|
|
32
32
|
## API Summary
|
@@ -383,8 +383,12 @@ You can store arbitrary model-level metadata alongside each version like this:
|
|
383
383
|
|
384
384
|
class Article < ActiveRecord::Base
|
385
385
|
belongs_to :author
|
386
|
-
has_paper_trail :meta => { :author_id
|
387
|
-
:
|
386
|
+
has_paper_trail :meta => { :author_id => Proc.new { |article| article.author_id },
|
387
|
+
:word_count => :count_words,
|
388
|
+
:answer => 42 }
|
389
|
+
def count_words
|
390
|
+
153
|
391
|
+
end
|
388
392
|
end
|
389
393
|
|
390
394
|
PaperTrail will call your proc with the current article and store the result in the `author_id` column of the `versions` table. (Remember to add your metadata columns to the table.)
|
@@ -393,6 +397,8 @@ Why would you do this? In this example, `author_id` is an attribute of `Article
|
|
393
397
|
|
394
398
|
Version.all(:conditions => ['author_id = ?', author_id])
|
395
399
|
|
400
|
+
Note you can pass a symbol as a value in the `meta` hash to signal a method to call.
|
401
|
+
|
396
402
|
You can also store any information you like from your controller. Just override the `info_for_paper_trail` method in your controller to return a hash whose keys correspond to columns in your `versions` table. E.g.:
|
397
403
|
|
398
404
|
class ApplicationController
|
@@ -484,7 +490,7 @@ Over time your `versions` table will grow to an unwieldy size. Because each ver
|
|
484
490
|
|
485
491
|
1. Install PaperTrail as a gem via your `Gemfile`:
|
486
492
|
|
487
|
-
`gem 'paper_trail'`
|
493
|
+
`gem 'paper_trail', '~> 2'`
|
488
494
|
|
489
495
|
2. Generate a migration which will add a `versions` table to your database.
|
490
496
|
|
@@ -500,7 +506,7 @@ Over time your `versions` table will grow to an unwieldy size. Because each ver
|
|
500
506
|
|
501
507
|
1. Install PaperTrail as a gem via your `config/environment.rb`:
|
502
508
|
|
503
|
-
`config.gem 'paper_trail'`
|
509
|
+
`config.gem 'paper_trail', :version => '~> 1'`
|
504
510
|
|
505
511
|
2. Generate a migration which will add a `versions` table to your database.
|
506
512
|
|
data/Rakefile
CHANGED
data/lib/paper_trail.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
require 'action_controller'
|
5
|
-
require 'active_record'
|
6
|
-
|
7
4
|
require 'paper_trail/config'
|
8
5
|
require 'paper_trail/controller'
|
9
6
|
require 'paper_trail/has_paper_trail'
|
10
7
|
require 'paper_trail/version'
|
11
8
|
|
12
|
-
|
13
9
|
# PaperTrail's module methods can be called in both models and controllers.
|
14
10
|
module PaperTrail
|
15
11
|
|
@@ -66,3 +62,12 @@ module PaperTrail
|
|
66
62
|
end
|
67
63
|
|
68
64
|
end
|
65
|
+
|
66
|
+
|
67
|
+
ActiveSupport.on_load(:active_record) do
|
68
|
+
include PaperTrail::Model
|
69
|
+
end
|
70
|
+
|
71
|
+
ActiveSupport.on_load(:action_controller) do
|
72
|
+
include PaperTrail::Controller
|
73
|
+
end
|
@@ -64,7 +64,7 @@ module PaperTrail
|
|
64
64
|
|
65
65
|
# Returns who put the object into its current state.
|
66
66
|
def originator
|
67
|
-
|
67
|
+
Version.with_item_keys(self.class.name, id).last.try :whodunnit
|
68
68
|
end
|
69
69
|
|
70
70
|
# Returns the object (not a Version) as it was at the given timestamp.
|
@@ -112,6 +112,7 @@ module PaperTrail
|
|
112
112
|
:object => object_to_string(item_before_change),
|
113
113
|
:whodunnit => PaperTrail.whodunnit)
|
114
114
|
end
|
115
|
+
versions.send :load_target
|
115
116
|
end
|
116
117
|
|
117
118
|
def merge_metadata(data)
|
@@ -158,5 +159,3 @@ module PaperTrail
|
|
158
159
|
|
159
160
|
end
|
160
161
|
end
|
161
|
-
|
162
|
-
ActiveRecord::Base.send :include, PaperTrail::Model
|
data/lib/paper_trail/version.rb
CHANGED
@@ -2,25 +2,22 @@ class Version < ActiveRecord::Base
|
|
2
2
|
belongs_to :item, :polymorphic => true
|
3
3
|
validates_presence_of :event
|
4
4
|
|
5
|
-
|
6
|
-
:
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
named_scope :after, lambda { |timestamp| {
|
20
|
-
:conditions => ['created_at > ?', timestamp],
|
5
|
+
scope :with_item_keys, lambda { |item_type, item_id|
|
6
|
+
where(:item_type => item_type, :item_id => item_id)
|
7
|
+
}
|
8
|
+
|
9
|
+
scope :subsequent, lambda { |version|
|
10
|
+
where(["id > ?", version.is_a?(Version) ? version.id : version]).order("id ASC")
|
11
|
+
}
|
12
|
+
|
13
|
+
scope :preceding, lambda { |version|
|
14
|
+
where(["id < ?", version.is_a?(Version) ? version.id : version]).order("id DESC")
|
15
|
+
}
|
16
|
+
|
17
|
+
scope :after, lambda { |timestamp|
|
21
18
|
# TODO: is this :order necessary, considering its presence on the has_many :versions association?
|
22
|
-
|
23
|
-
}
|
19
|
+
where(['created_at > ?', timestamp]).order('created_at ASC, id ASC')
|
20
|
+
}
|
24
21
|
|
25
22
|
# Restore the item from this version.
|
26
23
|
#
|
data/paper_trail.gemspec
CHANGED
@@ -1,30 +1,23 @@
|
|
1
|
-
$LOAD_PATH.unshift 'lib'
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
2
|
require 'paper_trail/version_number'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.summary
|
8
|
-
s.description
|
9
|
-
s.homepage
|
10
|
-
s.authors
|
11
|
-
s.email
|
12
|
-
s.files = %w[ README.md Rakefile paper_trail.gemspec ]
|
13
|
-
s.files += %w[ init.rb install.rb ]
|
14
|
-
s.files += Dir.glob("lib/**/*")
|
15
|
-
s.files += Dir.glob("generators/**/*")
|
16
|
-
s.require_path = 'lib'
|
17
|
-
s.test_files = Dir.glob("test/**/*")
|
5
|
+
s.name = 'paper_trail'
|
6
|
+
s.version = PaperTrail::VERSION
|
7
|
+
s.summary = "Track changes to your models' data. Good for auditing or versioning."
|
8
|
+
s.description = s.summary
|
9
|
+
s.homepage = 'http://github.com/airblade/paper_trail'
|
10
|
+
s.authors = ['Andy Stewart']
|
11
|
+
s.email = 'boss@airbladesoftware.com'
|
18
12
|
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
s.
|
23
|
-
s.add_development_dependency 'sqlite3-ruby', '~> 1.2'
|
24
|
-
# Repeated here to make bundler happy
|
25
|
-
s.add_development_dependency 'activerecord', '~> 2.3'
|
26
|
-
s.add_development_dependency 'actionpack', '~> 2.3'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ['lib']
|
27
17
|
|
28
|
-
s.add_dependency '
|
29
|
-
|
18
|
+
s.add_dependency 'rails', '~> 3'
|
19
|
+
|
20
|
+
s.add_development_dependency 'shoulda', '2.10.3'
|
21
|
+
s.add_development_dependency 'sqlite3-ruby', '~> 1.2'
|
22
|
+
s.add_development_dependency 'capybara', '>= 0.4.0'
|
30
23
|
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery
|
3
|
+
|
4
|
+
def rescue_action(e)
|
5
|
+
raise e
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns id of hypothetical current user
|
9
|
+
def current_user
|
10
|
+
153
|
11
|
+
end
|
12
|
+
|
13
|
+
def info_for_paper_trail
|
14
|
+
{:ip => request.remote_ip, :user_agent => request.user_agent}
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class WidgetsController < ApplicationController
|
2
|
+
def create
|
3
|
+
@widget = Widget.create params[:widget]
|
4
|
+
head :ok
|
5
|
+
end
|
6
|
+
|
7
|
+
def update
|
8
|
+
@widget = Widget.find params[:id]
|
9
|
+
@widget.update_attributes params[:widget]
|
10
|
+
head :ok
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy
|
14
|
+
@widget = Widget.find params[:id]
|
15
|
+
@widget.destroy
|
16
|
+
head :ok
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Article < ActiveRecord::Base
|
2
|
+
has_paper_trail :ignore => [:title],
|
3
|
+
:meta => {:answer => 42,
|
4
|
+
:action => :action_data_provider_method,
|
5
|
+
:question => Proc.new { "31 + 11 = #{31 + 11}" },
|
6
|
+
:article_id => Proc.new { |article| article.id } }
|
7
|
+
|
8
|
+
def action_data_provider_method
|
9
|
+
self.object_id.to_s
|
10
|
+
end
|
11
|
+
end
|