paper_trail 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +28 -9
  3. data/.github/ISSUE_TEMPLATE.md +13 -0
  4. data/.gitignore +2 -1
  5. data/.rubocop.yml +100 -0
  6. data/.rubocop_todo.yml +14 -0
  7. data/.travis.yml +8 -9
  8. data/Appraisals +41 -0
  9. data/CHANGELOG.md +49 -9
  10. data/Gemfile +1 -1
  11. data/README.md +130 -109
  12. data/Rakefile +19 -19
  13. data/doc/bug_report_template.rb +20 -14
  14. data/gemfiles/ar3.gemfile +10 -53
  15. data/gemfiles/ar4.gemfile +7 -0
  16. data/gemfiles/ar5.gemfile +13 -0
  17. data/lib/generators/paper_trail/install_generator.rb +26 -18
  18. data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb +4 -2
  19. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +2 -0
  20. data/lib/generators/paper_trail/templates/create_version_associations.rb +9 -4
  21. data/lib/generators/paper_trail/templates/create_versions.rb +39 -5
  22. data/lib/paper_trail.rb +169 -146
  23. data/lib/paper_trail/attributes_serialization.rb +89 -17
  24. data/lib/paper_trail/cleaner.rb +15 -9
  25. data/lib/paper_trail/config.rb +28 -11
  26. data/lib/paper_trail/frameworks/active_record.rb +4 -0
  27. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb +5 -1
  28. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +6 -2
  29. data/lib/paper_trail/frameworks/cucumber.rb +1 -0
  30. data/lib/paper_trail/frameworks/rails.rb +2 -7
  31. data/lib/paper_trail/frameworks/rails/controller.rb +29 -9
  32. data/lib/paper_trail/frameworks/rails/engine.rb +7 -1
  33. data/lib/paper_trail/frameworks/rspec.rb +5 -5
  34. data/lib/paper_trail/frameworks/rspec/helpers.rb +3 -1
  35. data/lib/paper_trail/frameworks/sinatra.rb +6 -4
  36. data/lib/paper_trail/has_paper_trail.rb +199 -106
  37. data/lib/paper_trail/record_history.rb +1 -3
  38. data/lib/paper_trail/reifier.rb +297 -118
  39. data/lib/paper_trail/serializers/json.rb +3 -3
  40. data/lib/paper_trail/serializers/yaml.rb +27 -8
  41. data/lib/paper_trail/version_association_concern.rb +3 -1
  42. data/lib/paper_trail/version_concern.rb +75 -35
  43. data/lib/paper_trail/version_number.rb +6 -9
  44. data/paper_trail.gemspec +44 -51
  45. data/spec/generators/install_generator_spec.rb +24 -25
  46. data/spec/generators/paper_trail/templates/create_versions_spec.rb +51 -0
  47. data/spec/models/animal_spec.rb +12 -12
  48. data/spec/models/boolit_spec.rb +8 -8
  49. data/spec/models/callback_modifier_spec.rb +47 -47
  50. data/spec/models/car_spec.rb +13 -0
  51. data/spec/models/fluxor_spec.rb +3 -3
  52. data/spec/models/gadget_spec.rb +19 -19
  53. data/spec/models/joined_version_spec.rb +3 -3
  54. data/spec/models/json_version_spec.rb +23 -24
  55. data/spec/models/kitchen/banana_spec.rb +3 -3
  56. data/spec/models/not_on_update_spec.rb +7 -4
  57. data/spec/models/post_with_status_spec.rb +13 -3
  58. data/spec/models/skipper_spec.rb +10 -10
  59. data/spec/models/thing_spec.rb +4 -4
  60. data/spec/models/truck_spec.rb +5 -0
  61. data/spec/models/vehicle_spec.rb +5 -0
  62. data/spec/models/version_spec.rb +103 -59
  63. data/spec/models/widget_spec.rb +82 -52
  64. data/spec/modules/paper_trail_spec.rb +2 -2
  65. data/spec/modules/version_concern_spec.rb +11 -12
  66. data/spec/modules/version_number_spec.rb +2 -4
  67. data/spec/paper_trail/config_spec.rb +10 -29
  68. data/spec/paper_trail_spec.rb +16 -14
  69. data/spec/rails_helper.rb +10 -9
  70. data/spec/requests/articles_spec.rb +11 -7
  71. data/spec/spec_helper.rb +41 -22
  72. data/spec/support/alt_db_init.rb +8 -13
  73. data/test/custom_json_serializer.rb +3 -3
  74. data/test/dummy/Rakefile +2 -2
  75. data/test/dummy/app/controllers/application_controller.rb +21 -8
  76. data/test/dummy/app/controllers/articles_controller.rb +11 -8
  77. data/test/dummy/app/controllers/widgets_controller.rb +13 -12
  78. data/test/dummy/app/models/animal.rb +1 -1
  79. data/test/dummy/app/models/article.rb +19 -11
  80. data/test/dummy/app/models/authorship.rb +1 -1
  81. data/test/dummy/app/models/bar_habtm.rb +4 -0
  82. data/test/dummy/app/models/book.rb +4 -4
  83. data/test/dummy/app/models/boolit.rb +1 -1
  84. data/test/dummy/app/models/callback_modifier.rb +6 -6
  85. data/test/dummy/app/models/car.rb +3 -0
  86. data/test/dummy/app/models/chapter.rb +4 -4
  87. data/test/dummy/app/models/customer.rb +1 -1
  88. data/test/dummy/app/models/document.rb +2 -2
  89. data/test/dummy/app/models/editor.rb +1 -1
  90. data/test/dummy/app/models/foo_habtm.rb +4 -0
  91. data/test/dummy/app/models/fruit.rb +2 -2
  92. data/test/dummy/app/models/gadget.rb +1 -1
  93. data/test/dummy/app/models/kitchen/banana.rb +1 -1
  94. data/test/dummy/app/models/legacy_widget.rb +2 -2
  95. data/test/dummy/app/models/line_item.rb +1 -1
  96. data/test/dummy/app/models/not_on_update.rb +1 -1
  97. data/test/dummy/app/models/person.rb +6 -6
  98. data/test/dummy/app/models/post.rb +1 -1
  99. data/test/dummy/app/models/post_with_status.rb +1 -1
  100. data/test/dummy/app/models/quotation.rb +1 -1
  101. data/test/dummy/app/models/section.rb +1 -1
  102. data/test/dummy/app/models/skipper.rb +2 -2
  103. data/test/dummy/app/models/song.rb +13 -4
  104. data/test/dummy/app/models/thing.rb +2 -2
  105. data/test/dummy/app/models/translation.rb +2 -2
  106. data/test/dummy/app/models/truck.rb +4 -0
  107. data/test/dummy/app/models/vehicle.rb +4 -0
  108. data/test/dummy/app/models/whatchamajigger.rb +1 -1
  109. data/test/dummy/app/models/widget.rb +7 -6
  110. data/test/dummy/app/versions/joined_version.rb +4 -3
  111. data/test/dummy/app/versions/json_version.rb +1 -1
  112. data/test/dummy/app/versions/kitchen/banana_version.rb +1 -1
  113. data/test/dummy/app/versions/post_version.rb +2 -2
  114. data/test/dummy/config.ru +1 -1
  115. data/test/dummy/config/application.rb +20 -9
  116. data/test/dummy/config/boot.rb +5 -5
  117. data/test/dummy/config/environment.rb +1 -1
  118. data/test/dummy/config/environments/development.rb +4 -3
  119. data/test/dummy/config/environments/production.rb +3 -2
  120. data/test/dummy/config/environments/test.rb +15 -5
  121. data/test/dummy/config/initializers/backtrace_silencers.rb +4 -2
  122. data/test/dummy/config/initializers/paper_trail.rb +1 -2
  123. data/test/dummy/config/initializers/secret_token.rb +3 -1
  124. data/test/dummy/config/initializers/session_store.rb +1 -1
  125. data/test/dummy/config/routes.rb +2 -2
  126. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +120 -74
  127. data/test/dummy/db/schema.rb +29 -6
  128. data/test/dummy/script/rails +6 -4
  129. data/test/functional/controller_test.rb +34 -35
  130. data/test/functional/enabled_for_controller_test.rb +6 -7
  131. data/test/functional/modular_sinatra_test.rb +43 -38
  132. data/test/functional/sinatra_test.rb +49 -40
  133. data/test/functional/thread_safety_test.rb +4 -6
  134. data/test/paper_trail_test.rb +15 -14
  135. data/test/test_helper.rb +68 -44
  136. data/test/time_travel_helper.rb +1 -15
  137. data/test/unit/associations_test.rb +517 -251
  138. data/test/unit/cleaner_test.rb +66 -60
  139. data/test/unit/inheritance_column_test.rb +17 -17
  140. data/test/unit/model_test.rb +611 -504
  141. data/test/unit/protected_attrs_test.rb +16 -12
  142. data/test/unit/serializer_test.rb +44 -43
  143. data/test/unit/serializers/json_test.rb +17 -18
  144. data/test/unit/serializers/mixin_json_test.rb +15 -14
  145. data/test/unit/serializers/mixin_yaml_test.rb +20 -16
  146. data/test/unit/serializers/yaml_test.rb +12 -13
  147. data/test/unit/timestamp_test.rb +10 -12
  148. data/test/unit/version_test.rb +7 -7
  149. metadata +92 -40
@@ -1,17 +1,18 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= 'test'
3
- ENV["DB"] ||= 'sqlite'
2
+ ENV["RAILS_ENV"] ||= "test"
3
+ ENV["DB"] ||= "sqlite"
4
4
 
5
- unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
5
+ unless File.exist?(File.expand_path("../../test/dummy/config/database.yml", __FILE__))
6
6
  warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
7
7
  end
8
8
 
9
- require 'spec_helper'
10
- require File.expand_path('../../test/dummy/config/environment', __FILE__)
11
- require 'rspec/rails'
12
- require 'paper_trail/frameworks/rspec'
13
- require 'shoulda/matchers'
14
- require 'ffaker'
9
+ require "spec_helper"
10
+ require File.expand_path("../../test/dummy/config/environment", __FILE__)
11
+ require "rspec/rails"
12
+ require "paper_trail/frameworks/rspec"
13
+ require "shoulda/matchers"
14
+ require "ffaker"
15
+ require "timecop"
15
16
 
16
17
  # prevent Test::Unit's AutoRunner from executing during RSpec's rake task
17
18
  Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
@@ -1,14 +1,16 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
- describe "Articles management", :type => :request, :order => :defined do
4
- let(:valid_params) { { :article => { :title => 'Doh', :content => Faker::Lorem.sentence } } }
3
+ describe "Articles management", type: :request, order: :defined do
4
+ let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
5
5
 
6
6
  context "versioning disabled" do
7
7
  specify { expect(PaperTrail).not_to be_enabled }
8
8
 
9
9
  it "should not create a version" do
10
10
  expect(PaperTrail).to be_enabled_for_controller
11
- expect { post(articles_path, valid_params) }.to_not change(PaperTrail::Version, :count)
11
+ expect {
12
+ post articles_path, params_wrapper(valid_params)
13
+ }.to_not change(PaperTrail::Version, :count)
12
14
  end
13
15
 
14
16
  it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
@@ -21,9 +23,11 @@ describe "Articles management", :type => :request, :order => :defined do
21
23
 
22
24
  context "`current_user` method returns a `String`" do
23
25
  it "should set that value as the `whodunnit`" do
24
- expect { post articles_path, valid_params }.to change(PaperTrail::Version, :count).by(1)
25
- expect(article.title).to eq('Doh')
26
- expect(article.versions.last.whodunnit).to eq('foobar')
26
+ expect {
27
+ post articles_path, params_wrapper(valid_params)
28
+ }.to change(PaperTrail::Version, :count).by(1)
29
+ expect(article.title).to eq("Doh")
30
+ expect(article.versions.last.whodunnit).to eq("foobar")
27
31
  end
28
32
  end
29
33
  end
@@ -1,8 +1,4 @@
1
- begin
2
- require 'pry-nav'
3
- rescue LoadError
4
- # It's OK, we don't include pry in e.g. gemfiles/3.0.gemfile
5
- end
1
+ require "pry-nav"
6
2
 
7
3
  # This file was generated by the `rspec --init` command. Conventionally, all
8
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -44,52 +40,75 @@ RSpec.configure do |config|
44
40
  mocks.verify_partial_doubles = true
45
41
  end
46
42
 
47
- # The settings below are suggested to provide a good initial experience
48
- # with RSpec, but feel free to customize to your heart's content.
49
- =begin
43
+ # Support for disabling `verify_partial_doubles` on specific examples.
44
+ config.around(:each, verify_stubs: false) do |ex|
45
+ config.mock_with :rspec do |mocks|
46
+ mocks.verify_partial_doubles = false
47
+ ex.run
48
+ mocks.verify_partial_doubles = true
49
+ end
50
+ end
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+
50
55
  # These two settings work together to allow you to limit a spec run
51
56
  # to individual examples or groups you care about by tagging them with
52
57
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
58
  # get run.
54
- config.filter_run :focus
55
- config.run_all_when_everything_filtered = true
59
+ # config.filter_run :focus
60
+ # config.run_all_when_everything_filtered = true
56
61
 
57
62
  # Limits the available syntax to the non-monkey patched syntax that is recommended.
58
63
  # For more details, see:
59
64
  # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
65
  # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
66
  # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
- config.disable_monkey_patching!
67
+ # config.disable_monkey_patching!
63
68
 
64
69
  # This setting enables warnings. It's recommended, but in some cases may
65
70
  # be too noisy due to issues in dependencies.
66
- config.warnings = true
71
+ # config.warnings = true
67
72
 
68
73
  # Many RSpec users commonly either run the entire suite or an individual
69
74
  # file, and it's useful to allow more verbose output when running an
70
75
  # individual spec file.
71
- if config.files_to_run.one?
72
- # Use the documentation formatter for detailed output,
73
- # unless a formatter has already been configured
74
- # (e.g. via a command-line flag).
75
- config.default_formatter = 'doc'
76
- end
76
+ # if config.files_to_run.one?
77
+ # # Use the documentation formatter for detailed output,
78
+ # # unless a formatter has already been configured
79
+ # # (e.g. via a command-line flag).
80
+ # config.default_formatter = 'doc'
81
+ # end
77
82
 
78
83
  # Print the 10 slowest examples and example groups at the
79
84
  # end of the spec run, to help surface which specs are running
80
85
  # particularly slow.
81
- config.profile_examples = 10
86
+ # config.profile_examples = 10
82
87
 
83
88
  # Run specs in random order to surface order dependencies. If you find an
84
89
  # order dependency and want to debug it, you can fix the order by providing
85
90
  # the seed, which is printed after each run.
86
91
  # --seed 1234
87
- config.order = :random
92
+ # config.order = :random
88
93
 
89
94
  # Seed global randomization in this process using the `--seed` CLI option.
90
95
  # Setting this allows you to use `--seed` to deterministically reproduce
91
96
  # test failures related to randomization by passing the same `--seed` value
92
97
  # as the one that triggered the failure.
93
- Kernel.srand config.seed
94
- =end
98
+ # Kernel.srand config.seed
99
+ end
100
+
101
+ def active_record_gem_version
102
+ Gem::Version.new(ActiveRecord::VERSION::STRING)
103
+ end
104
+
105
+ # Wrap args in a hash to support the ActionController::TestCase and
106
+ # ActionDispatch::Integration HTTP request method switch to keyword args
107
+ # (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
108
+ def params_wrapper(args)
109
+ if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
110
+ { params: args }
111
+ else
112
+ args
113
+ end
95
114
  end
@@ -2,21 +2,16 @@
2
2
  # then defines those namespaces, then establishes the sqlite3 connection for the namespaces
3
3
  # to simulate an application with multiple database connections.
4
4
 
5
- #Load database yaml to use
5
+ # Load database yaml to use
6
6
  configs = YAML.load_file("#{Rails.root}/config/database.yml")
7
7
 
8
- #If we are testing with sqlite make it quick
8
+ # If we are testing with sqlite make it quick
9
9
  db_directory = "#{Rails.root}/db"
10
- # setup alternate databases
10
+
11
+ # Set up alternate databases
11
12
  if ENV["DB"] == "sqlite"
12
- if RUBY_VERSION >= '1.9'
13
- FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
14
- FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
15
- else
16
- require 'ftools'
17
- File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
18
- File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
19
- end
13
+ FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
14
+ FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
20
15
  end
21
16
 
22
17
  module Foo
@@ -29,7 +24,7 @@ module Foo
29
24
  end
30
25
 
31
26
  class Document < Base
32
- has_paper_trail :class_name => 'Foo::Version'
27
+ has_paper_trail class_name: "Foo::Version"
33
28
  end
34
29
  end
35
30
 
@@ -48,7 +43,7 @@ module Bar
48
43
  end
49
44
 
50
45
  class Document < Base
51
- has_paper_trail :class_name => 'Bar::Version'
46
+ has_paper_trail class_name: "Bar::Version"
52
47
  end
53
48
  end
54
49
 
@@ -4,10 +4,10 @@ module CustomJsonSerializer
4
4
 
5
5
  def self.load(string)
6
6
  parsed_value = super(string)
7
- parsed_value.is_a?(Hash) ? parsed_value.reject { |k,v| k.blank? || v.blank? } : parsed_value
7
+ parsed_value.is_a?(Hash) ? parsed_value.reject { |k, v| k.blank? || v.blank? } : parsed_value
8
8
  end
9
9
 
10
10
  def self.dump(object)
11
- object.is_a?(Hash) ? super(object.reject { |k,v| v.nil? }) : super
11
+ object.is_a?(Hash) ? super(object.reject { |_k, v| v.nil? }) : super
12
12
  end
13
- end
13
+ end
@@ -1,7 +1,7 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
4
+ require File.expand_path("../config/application", __FILE__)
5
+ require "rake"
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -1,20 +1,33 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
+ # Rails 5 deprecates `before_filter`
5
+ name_of_before_callback = respond_to?(:before_action) ? :before_action : :before_filter
6
+
7
+ # Some applications and libraries modify `current_user`. Their changes need
8
+ # to be reflected in `whodunnit`, so the `set_paper_trail_whodunnit` below
9
+ # must happen after this.
10
+ send(name_of_before_callback, :modify_current_user)
11
+
12
+ # Going forward, we'll no longer add this `before_filter`, requiring people
13
+ # to do so themselves, allowing them to control the order in which this filter
14
+ # happens.
15
+ send(name_of_before_callback, :set_paper_trail_whodunnit)
16
+
4
17
  def rescue_action(e)
5
18
  raise e
6
19
  end
7
20
 
8
21
  # Returns id of hypothetical current user
9
- def current_user
10
- @current_user ||= OpenStruct.new(:id => 153).tap do |obj|
11
- # Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten
12
- def obj.id; 153; end if RUBY_VERSION < '1.9'
13
- end
14
- end
22
+ attr_reader :current_user
15
23
 
16
24
  def info_for_paper_trail
17
- {:ip => request.remote_ip, :user_agent => request.user_agent}
25
+ { ip: request.remote_ip, user_agent: request.user_agent }
26
+ end
27
+
28
+ private
29
+
30
+ def modify_current_user
31
+ @current_user = OpenStruct.new(id: 153)
18
32
  end
19
-
20
33
  end
@@ -1,17 +1,20 @@
1
1
  class ArticlesController < ApplicationController
2
2
  def create
3
- if PaperTrail.active_record_protected_attributes?
4
- @article = Article.create params[:article]
5
- else
6
- @article = Article.create params.require(:article).permit!
7
- end
3
+ @article = Article.create article_params
8
4
  head :ok
9
5
  end
10
6
 
11
7
  def current_user
12
- 'foobar'.tap do |string|
13
- # Invoking `id` returns the `object_id` value in Ruby18 by default
14
- string.class_eval { undef_method(:id) } if RUBY_VERSION < '1.9'
8
+ "foobar"
9
+ end
10
+
11
+ private
12
+
13
+ def article_params
14
+ if PaperTrail.active_record_protected_attributes?
15
+ params[:article]
16
+ else
17
+ params.require(:article).permit!
15
18
  end
16
19
  end
17
20
  end
@@ -1,25 +1,16 @@
1
1
  class WidgetsController < ApplicationController
2
-
3
2
  def paper_trail_enabled_for_controller
4
- request.user_agent != 'Disable User-Agent'
3
+ request.user_agent != "Disable User-Agent"
5
4
  end
6
5
 
7
6
  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
7
+ @widget = Widget.create widget_params
13
8
  head :ok
14
9
  end
15
10
 
16
11
  def update
17
12
  @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
13
+ @widget.update_attributes widget_params
23
14
  head :ok
24
15
  end
25
16
 
@@ -28,4 +19,14 @@ class WidgetsController < ApplicationController
28
19
  @widget.destroy
29
20
  head :ok
30
21
  end
22
+
23
+ private
24
+
25
+ def widget_params
26
+ if PaperTrail.active_record_protected_attributes?
27
+ params[:widget]
28
+ else
29
+ params[:widget].permit!
30
+ end
31
+ end
31
32
  end
@@ -1,6 +1,6 @@
1
1
  class Animal < ActiveRecord::Base
2
2
  has_paper_trail
3
- self.inheritance_column = 'species'
3
+ self.inheritance_column = "species"
4
4
 
5
5
  attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
6
6
  end
@@ -1,16 +1,24 @@
1
1
  class Article < ActiveRecord::Base
2
- has_paper_trail :ignore => [:title, { :abstract => Proc.new { |obj| ['ignore abstract', 'Other abstract'].include? obj.abstract } } ],
3
- :only => [:content, { :abstract => Proc.new { |obj| obj.abstract.present? } } ],
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
- }
2
+ has_paper_trail(
3
+ ignore: [
4
+ :title, {
5
+ abstract: proc { |obj|
6
+ ["ignore abstract", "Other abstract"].include? obj.abstract
7
+ }
8
+ }
9
+ ],
10
+ only: [:content, { abstract: proc { |obj| obj.abstract.present? } }],
11
+ skip: [:file_upload],
12
+ meta: {
13
+ answer: 42,
14
+ action: :action_data_provider_method,
15
+ question: proc { "31 + 11 = #{31 + 11}" },
16
+ article_id: proc { |article| article.id },
17
+ title: :title
18
+ }
19
+ )
12
20
 
13
21
  def action_data_provider_method
14
- self.object_id.to_s
22
+ object_id.to_s
15
23
  end
16
24
  end
@@ -1,5 +1,5 @@
1
1
  class Authorship < ActiveRecord::Base
2
2
  belongs_to :book
3
- belongs_to :person
3
+ belongs_to :author, class_name: "Person"
4
4
  has_paper_trail
5
5
  end
@@ -0,0 +1,4 @@
1
+ class BarHabtm < ActiveRecord::Base
2
+ has_and_belongs_to_many :foo_habtms
3
+ has_paper_trail
4
+ end
@@ -1,9 +1,9 @@
1
1
  class Book < ActiveRecord::Base
2
- has_many :authorships, :dependent => :destroy
3
- has_many :authors, :through => :authorships, :source => :person
2
+ has_many :authorships, dependent: :destroy
3
+ has_many :authors, through: :authorships
4
4
 
5
- has_many :editorships, :dependent => :destroy
6
- has_many :editors, :through => :editorships
5
+ has_many :editorships, dependent: :destroy
6
+ has_many :editors, through: :editorships
7
7
 
8
8
  has_paper_trail
9
9
  end
@@ -1,4 +1,4 @@
1
1
  class Boolit < ActiveRecord::Base
2
- default_scope { where(:scoped => true) }
2
+ default_scope { where(scoped: true) }
3
3
  has_paper_trail
4
4
  end
@@ -1,5 +1,5 @@
1
1
  class CallbackModifier < ActiveRecord::Base
2
- has_paper_trail :on => []
2
+ has_paper_trail on: []
3
3
 
4
4
  def test_destroy
5
5
  transaction do
@@ -16,27 +16,27 @@ class CallbackModifier < ActiveRecord::Base
16
16
  end
17
17
 
18
18
  class BeforeDestroyModifier < CallbackModifier
19
- has_paper_trail :on => []
19
+ has_paper_trail on: []
20
20
  paper_trail_on_destroy :before
21
21
  end
22
22
 
23
23
  class AfterDestroyModifier < CallbackModifier
24
- has_paper_trail :on => []
24
+ has_paper_trail on: []
25
25
  paper_trail_on_destroy :after
26
26
  end
27
27
 
28
28
  class NoArgDestroyModifier < CallbackModifier
29
- has_paper_trail :on => []
29
+ has_paper_trail on: []
30
30
  paper_trail_on_destroy
31
31
  end
32
32
 
33
33
  class UpdateModifier < CallbackModifier
34
- has_paper_trail :on => []
34
+ has_paper_trail on: []
35
35
  paper_trail_on_update
36
36
  end
37
37
 
38
38
  class CreateModifier < CallbackModifier
39
- has_paper_trail :on => []
39
+ has_paper_trail on: []
40
40
  paper_trail_on_create
41
41
  end
42
42