paper_trail_without_deprecated 3.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +21 -0
  5. data/CHANGELOG.md +68 -0
  6. data/Gemfile +2 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +979 -0
  9. data/Rakefile +18 -0
  10. data/gemfiles/3.0.gemfile +31 -0
  11. data/lib/generators/paper_trail/USAGE +2 -0
  12. data/lib/generators/paper_trail/install_generator.rb +23 -0
  13. data/lib/generators/paper_trail/templates/add_object_changes_column_to_versions.rb +9 -0
  14. data/lib/generators/paper_trail/templates/create_versions.rb +18 -0
  15. data/lib/paper_trail.rb +115 -0
  16. data/lib/paper_trail/cleaner.rb +34 -0
  17. data/lib/paper_trail/config.rb +14 -0
  18. data/lib/paper_trail/frameworks/cucumber.rb +31 -0
  19. data/lib/paper_trail/frameworks/rails.rb +79 -0
  20. data/lib/paper_trail/frameworks/rspec.rb +24 -0
  21. data/lib/paper_trail/frameworks/rspec/extensions.rb +20 -0
  22. data/lib/paper_trail/frameworks/sinatra.rb +31 -0
  23. data/lib/paper_trail/has_paper_trail.rb +308 -0
  24. data/lib/paper_trail/serializers/json.rb +17 -0
  25. data/lib/paper_trail/serializers/yaml.rb +17 -0
  26. data/lib/paper_trail/version.rb +200 -0
  27. data/lib/paper_trail/version_number.rb +3 -0
  28. data/paper_trail.gemspec +36 -0
  29. data/spec/models/widget_spec.rb +13 -0
  30. data/spec/paper_trail_spec.rb +47 -0
  31. data/spec/spec_helper.rb +41 -0
  32. data/test/custom_json_serializer.rb +13 -0
  33. data/test/dummy/Rakefile +7 -0
  34. data/test/dummy/app/controllers/application_controller.rb +17 -0
  35. data/test/dummy/app/controllers/test_controller.rb +5 -0
  36. data/test/dummy/app/controllers/widgets_controller.rb +31 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/models/animal.rb +4 -0
  39. data/test/dummy/app/models/article.rb +16 -0
  40. data/test/dummy/app/models/authorship.rb +5 -0
  41. data/test/dummy/app/models/book.rb +5 -0
  42. data/test/dummy/app/models/cat.rb +2 -0
  43. data/test/dummy/app/models/document.rb +4 -0
  44. data/test/dummy/app/models/dog.rb +2 -0
  45. data/test/dummy/app/models/elephant.rb +3 -0
  46. data/test/dummy/app/models/fluxor.rb +3 -0
  47. data/test/dummy/app/models/foo_widget.rb +2 -0
  48. data/test/dummy/app/models/legacy_widget.rb +4 -0
  49. data/test/dummy/app/models/person.rb +28 -0
  50. data/test/dummy/app/models/post.rb +4 -0
  51. data/test/dummy/app/models/protected_widget.rb +3 -0
  52. data/test/dummy/app/models/song.rb +12 -0
  53. data/test/dummy/app/models/translation.rb +4 -0
  54. data/test/dummy/app/models/widget.rb +10 -0
  55. data/test/dummy/app/models/wotsit.rb +4 -0
  56. data/test/dummy/app/versions/post_version.rb +3 -0
  57. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  58. data/test/dummy/config.ru +4 -0
  59. data/test/dummy/config/application.rb +63 -0
  60. data/test/dummy/config/boot.rb +10 -0
  61. data/test/dummy/config/database.yml +22 -0
  62. data/test/dummy/config/environment.rb +5 -0
  63. data/test/dummy/config/environments/development.rb +40 -0
  64. data/test/dummy/config/environments/production.rb +73 -0
  65. data/test/dummy/config/environments/test.rb +37 -0
  66. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/test/dummy/config/initializers/inflections.rb +10 -0
  68. data/test/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/dummy/config/initializers/paper_trail.rb +5 -0
  70. data/test/dummy/config/initializers/secret_token.rb +7 -0
  71. data/test/dummy/config/initializers/session_store.rb +8 -0
  72. data/test/dummy/config/locales/en.yml +5 -0
  73. data/test/dummy/config/routes.rb +3 -0
  74. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +136 -0
  75. data/test/dummy/db/schema.rb +101 -0
  76. data/test/dummy/public/404.html +26 -0
  77. data/test/dummy/public/422.html +26 -0
  78. data/test/dummy/public/500.html +26 -0
  79. data/test/dummy/public/favicon.ico +0 -0
  80. data/test/dummy/public/javascripts/application.js +2 -0
  81. data/test/dummy/public/javascripts/controls.js +965 -0
  82. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  83. data/test/dummy/public/javascripts/effects.js +1123 -0
  84. data/test/dummy/public/javascripts/prototype.js +6001 -0
  85. data/test/dummy/public/javascripts/rails.js +175 -0
  86. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  87. data/test/dummy/script/rails +6 -0
  88. data/test/functional/controller_test.rb +90 -0
  89. data/test/functional/modular_sinatra_test.rb +44 -0
  90. data/test/functional/sinatra_test.rb +45 -0
  91. data/test/functional/thread_safety_test.rb +26 -0
  92. data/test/paper_trail_test.rb +27 -0
  93. data/test/test_helper.rb +40 -0
  94. data/test/unit/cleaner_test.rb +143 -0
  95. data/test/unit/inheritance_column_test.rb +43 -0
  96. data/test/unit/model_test.rb +1314 -0
  97. data/test/unit/protected_attrs_test.rb +46 -0
  98. data/test/unit/serializer_test.rb +117 -0
  99. data/test/unit/serializers/json_test.rb +40 -0
  100. data/test/unit/serializers/mixin_json_test.rb +36 -0
  101. data/test/unit/serializers/mixin_yaml_test.rb +49 -0
  102. data/test/unit/serializers/yaml_test.rb +40 -0
  103. data/test/unit/timestamp_test.rb +44 -0
  104. data/test/unit/version_test.rb +74 -0
  105. metadata +286 -0
@@ -0,0 +1,3 @@
1
+ module PaperTrail
2
+ VERSION = '3.0.0.beta1'
3
+ end
@@ -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
@@ -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
@@ -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,5 @@
1
+ class TestController < ActionController::Base
2
+ def current_user
3
+ Thread.current.object_id
4
+ end
5
+ 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,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Animal < ActiveRecord::Base
2
+ has_paper_trail
3
+ self.inheritance_column = 'species'
4
+ 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,5 @@
1
+ class Authorship < ActiveRecord::Base
2
+ belongs_to :book
3
+ belongs_to :person
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,5 @@
1
+ class Book < ActiveRecord::Base
2
+ has_many :authorships, :dependent => :destroy
3
+ has_many :authors, :through => :authorships, :source => :person
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,2 @@
1
+ class Cat < Animal
2
+ end
@@ -0,0 +1,4 @@
1
+ class Document < ActiveRecord::Base
2
+ has_paper_trail :versions => :paper_trail_versions,
3
+ :on => [:create, :update]
4
+ end
@@ -0,0 +1,2 @@
1
+ class Dog < Animal
2
+ end
@@ -0,0 +1,3 @@
1
+ class Elephant < Animal
2
+ paper_trail_off
3
+ end
@@ -0,0 +1,3 @@
1
+ class Fluxor < ActiveRecord::Base
2
+ belongs_to :widget
3
+ end
@@ -0,0 +1,2 @@
1
+ class FooWidget < Widget
2
+ end
@@ -0,0 +1,4 @@
1
+ class LegacyWidget < ActiveRecord::Base
2
+ has_paper_trail :ignore => :version,
3
+ :version => 'custom_version'
4
+ 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,4 @@
1
+ class Post < ActiveRecord::Base
2
+ has_paper_trail :class_name => "PostVersion"
3
+
4
+ end
@@ -0,0 +1,3 @@
1
+ class ProtectedWidget < Widget
2
+ attr_accessible :name, :a_text if ::PaperTrail.active_record_protected_attributes?
3
+ 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,4 @@
1
+ class Translation < ActiveRecord::Base
2
+ has_paper_trail :if => Proc.new { |t| t.language_code == 'US' },
3
+ :unless => Proc.new { |t| t.type == 'DRAFT' }
4
+ 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,4 @@
1
+ class Wotsit < ActiveRecord::Base
2
+ has_paper_trail
3
+ belongs_to :widget
4
+ end
@@ -0,0 +1,3 @@
1
+ class PostVersion < PaperTrail::Version
2
+ self.table_name = 'post_versions'
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -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