paper_trail_without_deprecated 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +68 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +20 -0
- data/README.md +979 -0
- data/Rakefile +18 -0
- data/gemfiles/3.0.gemfile +31 -0
- data/lib/generators/paper_trail/USAGE +2 -0
- data/lib/generators/paper_trail/install_generator.rb +23 -0
- data/lib/generators/paper_trail/templates/add_object_changes_column_to_versions.rb +9 -0
- data/lib/generators/paper_trail/templates/create_versions.rb +18 -0
- data/lib/paper_trail.rb +115 -0
- data/lib/paper_trail/cleaner.rb +34 -0
- data/lib/paper_trail/config.rb +14 -0
- data/lib/paper_trail/frameworks/cucumber.rb +31 -0
- data/lib/paper_trail/frameworks/rails.rb +79 -0
- data/lib/paper_trail/frameworks/rspec.rb +24 -0
- data/lib/paper_trail/frameworks/rspec/extensions.rb +20 -0
- data/lib/paper_trail/frameworks/sinatra.rb +31 -0
- data/lib/paper_trail/has_paper_trail.rb +308 -0
- data/lib/paper_trail/serializers/json.rb +17 -0
- data/lib/paper_trail/serializers/yaml.rb +17 -0
- data/lib/paper_trail/version.rb +200 -0
- data/lib/paper_trail/version_number.rb +3 -0
- data/paper_trail.gemspec +36 -0
- data/spec/models/widget_spec.rb +13 -0
- data/spec/paper_trail_spec.rb +47 -0
- data/spec/spec_helper.rb +41 -0
- data/test/custom_json_serializer.rb +13 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +17 -0
- data/test/dummy/app/controllers/test_controller.rb +5 -0
- data/test/dummy/app/controllers/widgets_controller.rb +31 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/animal.rb +4 -0
- data/test/dummy/app/models/article.rb +16 -0
- data/test/dummy/app/models/authorship.rb +5 -0
- data/test/dummy/app/models/book.rb +5 -0
- data/test/dummy/app/models/cat.rb +2 -0
- data/test/dummy/app/models/document.rb +4 -0
- data/test/dummy/app/models/dog.rb +2 -0
- data/test/dummy/app/models/elephant.rb +3 -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/legacy_widget.rb +4 -0
- data/test/dummy/app/models/person.rb +28 -0
- data/test/dummy/app/models/post.rb +4 -0
- data/test/dummy/app/models/protected_widget.rb +3 -0
- data/test/dummy/app/models/song.rb +12 -0
- data/test/dummy/app/models/translation.rb +4 -0
- data/test/dummy/app/models/widget.rb +10 -0
- data/test/dummy/app/models/wotsit.rb +4 -0
- data/test/dummy/app/versions/post_version.rb +3 -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 +63 -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 +40 -0
- data/test/dummy/config/environments/production.rb +73 -0
- data/test/dummy/config/environments/test.rb +37 -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/paper_trail.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/migrate/20110208155312_set_up_test_tables.rb +136 -0
- data/test/dummy/db/schema.rb +101 -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/functional/controller_test.rb +90 -0
- data/test/functional/modular_sinatra_test.rb +44 -0
- data/test/functional/sinatra_test.rb +45 -0
- data/test/functional/thread_safety_test.rb +26 -0
- data/test/paper_trail_test.rb +27 -0
- data/test/test_helper.rb +40 -0
- data/test/unit/cleaner_test.rb +143 -0
- data/test/unit/inheritance_column_test.rb +43 -0
- data/test/unit/model_test.rb +1314 -0
- data/test/unit/protected_attrs_test.rb +46 -0
- data/test/unit/serializer_test.rb +117 -0
- data/test/unit/serializers/json_test.rb +40 -0
- data/test/unit/serializers/mixin_json_test.rb +36 -0
- data/test/unit/serializers/mixin_yaml_test.rb +49 -0
- data/test/unit/serializers/yaml_test.rb +40 -0
- data/test/unit/timestamp_test.rb +44 -0
- data/test/unit/version_test.rb +74 -0
- metadata +286 -0
data/paper_trail.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'paper_trail/version_number'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'paper_trail_without_deprecated'
|
6
|
+
s.version = PaperTrail::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.summary = "Track changes to your models' data. Good for auditing or versioning."
|
9
|
+
s.description = s.summary
|
10
|
+
s.homepage = 'http://github.com/airblade/paper_trail'
|
11
|
+
s.authors = ['Andy Stewart', 'Ben Atkins']
|
12
|
+
s.email = 'boss@airbladesoftware.com'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'activerecord', ['>= 3.0', '< 5.0']
|
21
|
+
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'shoulda', '~> 3.5'
|
24
|
+
s.add_development_dependency 'ffaker', '>= 1.15'
|
25
|
+
s.add_development_dependency 'railties', ['>= 3.0', '< 5.0']
|
26
|
+
s.add_development_dependency 'sinatra', '~> 1.0'
|
27
|
+
s.add_development_dependency 'rack-test', '>= 0.6'
|
28
|
+
s.add_development_dependency 'rspec-rails', '~> 2.14'
|
29
|
+
|
30
|
+
# JRuby support for the test ENV
|
31
|
+
unless defined?(JRUBY_VERSION)
|
32
|
+
s.add_development_dependency 'sqlite3', '~> 1.2'
|
33
|
+
else
|
34
|
+
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', ['>= 1.3.0.rc1', '< 1.4']
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Widget do
|
4
|
+
it { should be_versioned }
|
5
|
+
|
6
|
+
context 'be_versioned matcher', :versioning => true do
|
7
|
+
it 'should respond to be_versioned' do
|
8
|
+
widget = Widget.create :name => 'Bob', :an_integer => 1
|
9
|
+
widget.should be_versioned
|
10
|
+
widget.versions.size.should == 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "PaperTrail RSpec Helper" do
|
4
|
+
describe :enabled do
|
5
|
+
context 'default' do
|
6
|
+
it 'should have versioning off by default' do
|
7
|
+
::PaperTrail.should_not be_enabled
|
8
|
+
end
|
9
|
+
it 'should turn versioning on in a with_versioning block' do
|
10
|
+
::PaperTrail.should_not be_enabled
|
11
|
+
with_versioning do
|
12
|
+
::PaperTrail.should be_enabled
|
13
|
+
end
|
14
|
+
::PaperTrail.should_not be_enabled
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'versioning: true', :versioning => true do
|
19
|
+
it 'should have versioning on by default' do
|
20
|
+
::PaperTrail.should be_enabled
|
21
|
+
end
|
22
|
+
it 'should keep versioning on after a with_versioning block' do
|
23
|
+
::PaperTrail.should be_enabled
|
24
|
+
with_versioning do
|
25
|
+
::PaperTrail.should be_enabled
|
26
|
+
end
|
27
|
+
::PaperTrail.should be_enabled
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe :whodunnit do
|
33
|
+
before(:all) { ::PaperTrail.whodunnit = 'foobar' }
|
34
|
+
|
35
|
+
it "should get set to `nil` by default" do
|
36
|
+
::PaperTrail.whodunnit.should be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe :controller_info do
|
41
|
+
before(:all) { ::PaperTrail.controller_info = {:foo => 'bar'} }
|
42
|
+
|
43
|
+
it "should get set to an empty hash before each test" do
|
44
|
+
::PaperTrail.controller_info.should == {}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
require File.expand_path('../../test/dummy/config/environment', __FILE__)
|
3
|
+
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
10
|
+
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
|
15
|
+
# ## Mock Framework
|
16
|
+
#
|
17
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
18
|
+
#
|
19
|
+
# config.mock_with :mocha
|
20
|
+
# config.mock_with :flexmock
|
21
|
+
# config.mock_with :rr
|
22
|
+
|
23
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
24
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
25
|
+
|
26
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
27
|
+
# examples within a transaction, remove the following line or assign false
|
28
|
+
# instead of true.
|
29
|
+
config.use_transactional_fixtures = true
|
30
|
+
|
31
|
+
# If true, the base class of anonymous controllers will be inferred
|
32
|
+
# automatically. This will be the default behavior in future versions of
|
33
|
+
# rspec-rails.
|
34
|
+
config.infer_base_class_for_anonymous_controllers = false
|
35
|
+
|
36
|
+
# Run specs in random order to surface order dependencies. If you find an
|
37
|
+
# order dependency and want to debug it, you can fix the order by providing
|
38
|
+
# the seed, which is printed after each run.
|
39
|
+
# --seed 1234
|
40
|
+
config.order = 'random'
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This custom serializer excludes nil values
|
2
|
+
module CustomJsonSerializer
|
3
|
+
extend PaperTrail::Serializers::Json
|
4
|
+
|
5
|
+
def self.load(string)
|
6
|
+
parsed_value = super(string)
|
7
|
+
parsed_value.is_a?(Hash) ? parsed_value.reject { |k,v| k.blank? || v.blank? } : parsed_value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.dump(object)
|
11
|
+
object.is_a?(Hash) ? super(object.reject { |k,v| v.nil? }) : super
|
12
|
+
end
|
13
|
+
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,17 @@
|
|
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
|
+
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class WidgetsController < ApplicationController
|
2
|
+
|
3
|
+
def paper_trail_enabled_for_controller
|
4
|
+
request.user_agent != 'Disable User-Agent'
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
if PaperTrail.active_record_protected_attributes?
|
9
|
+
@widget = Widget.create params[:widget]
|
10
|
+
else
|
11
|
+
@widget = Widget.create params[:widget].permit!
|
12
|
+
end
|
13
|
+
head :ok
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
@widget = Widget.find params[:id]
|
18
|
+
if PaperTrail.active_record_protected_attributes?
|
19
|
+
@widget.update_attributes params[:widget]
|
20
|
+
else
|
21
|
+
@widget.update_attributes params[:widget].permit!
|
22
|
+
end
|
23
|
+
head :ok
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
@widget = Widget.find params[:id]
|
28
|
+
@widget.destroy
|
29
|
+
head :ok
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Article < ActiveRecord::Base
|
2
|
+
has_paper_trail :ignore => :title,
|
3
|
+
:only => [:content],
|
4
|
+
:skip => [:file_upload],
|
5
|
+
:meta => {
|
6
|
+
:answer => 42,
|
7
|
+
:action => :action_data_provider_method,
|
8
|
+
:question => Proc.new { "31 + 11 = #{31 + 11}" },
|
9
|
+
:article_id => Proc.new { |article| article.id },
|
10
|
+
:title => :title
|
11
|
+
}
|
12
|
+
|
13
|
+
def action_data_provider_method
|
14
|
+
self.object_id.to_s
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Person < ActiveRecord::Base
|
2
|
+
has_many :authorships, :dependent => :destroy
|
3
|
+
has_many :books, :through => :authorships
|
4
|
+
has_paper_trail
|
5
|
+
|
6
|
+
# Convert strings to TimeZone objects when assigned
|
7
|
+
def time_zone=(value)
|
8
|
+
if value.is_a? ActiveSupport::TimeZone
|
9
|
+
super
|
10
|
+
else
|
11
|
+
zone = ::Time.find_zone(value) # nil if can't find time zone
|
12
|
+
super zone
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Store TimeZone objects as strings when serialized to database
|
17
|
+
class TimeZoneSerializer
|
18
|
+
def dump(zone)
|
19
|
+
zone.try(:name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def load(value)
|
23
|
+
::Time.find_zone!(value) rescue nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
serialize :time_zone, TimeZoneSerializer.new
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Example from 'Overwriting default accessors' in ActiveRecord::Base.
|
2
|
+
class Song < ActiveRecord::Base
|
3
|
+
has_paper_trail
|
4
|
+
|
5
|
+
# Uses an integer of seconds to hold the length of the song
|
6
|
+
def length=(minutes)
|
7
|
+
write_attribute(:length, minutes.to_i * 60)
|
8
|
+
end
|
9
|
+
def length
|
10
|
+
read_attribute(:length) / 60
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Widget < ActiveRecord::Base
|
2
|
+
has_paper_trail
|
3
|
+
has_one :wotsit
|
4
|
+
|
5
|
+
if ActiveRecord::VERSION::STRING.to_f >= 4.0 # `has_many` syntax for specifying order uses a lambda in Rails 4
|
6
|
+
has_many :fluxors, lambda { order(:name) }
|
7
|
+
else
|
8
|
+
has_many :fluxors, :order => :name
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
|
7
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
+
require 'paper_trail'
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
# Settings in config/environments/* take precedence over those specified here.
|
13
|
+
# Application configuration should go into files in config/initializers
|
14
|
+
# -- all .rb files in that directory are automatically loaded.
|
15
|
+
|
16
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
17
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
18
|
+
|
19
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
20
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
21
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
22
|
+
|
23
|
+
# Activate observers that should always be running.
|
24
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
25
|
+
|
26
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
27
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
28
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
29
|
+
|
30
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
31
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
32
|
+
# config.i18n.default_locale = :de
|
33
|
+
|
34
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
35
|
+
config.encoding = "utf-8"
|
36
|
+
|
37
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
38
|
+
config.filter_parameters += [:password]
|
39
|
+
|
40
|
+
# Enable escaping HTML in JSON.
|
41
|
+
config.active_support.escape_html_entities_in_json = true
|
42
|
+
|
43
|
+
# Use SQL instead of Active Record's schema dumper when creating the database.
|
44
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
45
|
+
# like if you have constraints or database-specific column types
|
46
|
+
# config.active_record.schema_format = :sql
|
47
|
+
|
48
|
+
# Enforce whitelist mode for mass assignment.
|
49
|
+
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
50
|
+
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
51
|
+
# parameters by using an attr_accessible or attr_protected declaration.
|
52
|
+
config.active_record.whitelist_attributes = false if ::PaperTrail.active_record_protected_attributes?
|
53
|
+
|
54
|
+
# Enable the asset pipeline
|
55
|
+
config.assets.enabled = false
|
56
|
+
|
57
|
+
# Version of your assets, change this if you want to expire all your assets
|
58
|
+
# config.assets.version = '1.0'
|
59
|
+
|
60
|
+
# Rails 4 key for generating secret key
|
61
|
+
config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
|
62
|
+
end
|
63
|
+
end
|