paper_trail_manager 0.5.0 → 0.7.0

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 (154) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +88 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +33 -0
  5. data/Appraisals +26 -34
  6. data/CHANGES.md +14 -2
  7. data/Gemfile +2 -1
  8. data/README.md +10 -1
  9. data/Rakefile +17 -5
  10. data/app/controllers/paper_trail_manager/changes_controller.rb +103 -100
  11. data/app/helpers/paper_trail_manager/changes_helper.rb +34 -51
  12. data/app/views/paper_trail_manager/changes/_version.html.erb +7 -3
  13. data/app/views/paper_trail_manager/changes/index.atom.builder +23 -19
  14. data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +13 -0
  15. data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +13 -0
  16. data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +13 -0
  17. data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +13 -0
  18. data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +13 -0
  19. data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +13 -0
  20. data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +13 -0
  21. data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +13 -0
  22. data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +13 -0
  23. data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +13 -0
  24. data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +13 -0
  25. data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +13 -0
  26. data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +13 -0
  27. data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +13 -0
  28. data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +13 -0
  29. data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +13 -0
  30. data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +13 -0
  31. data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +13 -0
  32. data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +13 -0
  33. data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +13 -0
  34. data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +13 -0
  35. data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +13 -0
  36. data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +13 -0
  37. data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +13 -0
  38. data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +13 -0
  39. data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +13 -0
  40. data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +13 -0
  41. data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +13 -0
  42. data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +13 -0
  43. data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +13 -0
  44. data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +13 -0
  45. data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +13 -0
  46. data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +14 -0
  47. data/gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile +15 -0
  48. data/lib/paper_trail_manager.rb +22 -27
  49. data/paper_trail_manager.gemspec +22 -21
  50. data/spec/app_template.rb +30 -0
  51. data/spec/integration/navigation_spec.rb +4 -2
  52. data/spec/integration/paper_trail_manager_spec.rb +94 -110
  53. data/spec/rails_helper.rb +6 -4
  54. data/spec/spec_helper.rb +7 -5
  55. data/spec/support/factories.rb +2 -1
  56. data/spec/support/rspec_html_matchers.rb +7 -0
  57. metadata +87 -224
  58. data/.travis.yml +0 -15
  59. data/gemfiles/rails_3.2_kaminari.gemfile +0 -8
  60. data/gemfiles/rails_3.2_will_paginate.gemfile +0 -8
  61. data/gemfiles/rails_4.0_kaminari.gemfile +0 -8
  62. data/gemfiles/rails_4.0_will_paginate.gemfile +0 -8
  63. data/gemfiles/rails_4.1_kaminari.gemfile +0 -8
  64. data/gemfiles/rails_4.1_will_paginate.gemfile +0 -8
  65. data/gemfiles/rails_4.2_kaminari.gemfile +0 -8
  66. data/gemfiles/rails_4.2_will_paginate.gemfile +0 -8
  67. data/spec/controllers/entities_controller_spec.rb +0 -125
  68. data/spec/controllers/platforms_controller_spec.rb +0 -125
  69. data/spec/dummy/.gitignore +0 -15
  70. data/spec/dummy/Gemfile +0 -9
  71. data/spec/dummy/README.rdoc +0 -261
  72. data/spec/dummy/Rakefile +0 -7
  73. data/spec/dummy/app/assets/images/rails.png +0 -0
  74. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  75. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  76. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  77. data/spec/dummy/app/controllers/entities_controller.rb +0 -83
  78. data/spec/dummy/app/controllers/platforms_controller.rb +0 -83
  79. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  80. data/spec/dummy/app/helpers/entities_helper.rb +0 -2
  81. data/spec/dummy/app/helpers/platforms_helper.rb +0 -2
  82. data/spec/dummy/app/mailers/.gitkeep +0 -0
  83. data/spec/dummy/app/models/.gitkeep +0 -0
  84. data/spec/dummy/app/models/entity.rb +0 -6
  85. data/spec/dummy/app/models/platform.rb +0 -6
  86. data/spec/dummy/app/views/application/index.html.erb +0 -6
  87. data/spec/dummy/app/views/entities/_form.html.erb +0 -17
  88. data/spec/dummy/app/views/entities/edit.html.erb +0 -6
  89. data/spec/dummy/app/views/entities/index.html.erb +0 -21
  90. data/spec/dummy/app/views/entities/new.html.erb +0 -5
  91. data/spec/dummy/app/views/entities/show.html.erb +0 -5
  92. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/dummy/app/views/platforms/_form.html.erb +0 -17
  94. data/spec/dummy/app/views/platforms/edit.html.erb +0 -6
  95. data/spec/dummy/app/views/platforms/index.html.erb +0 -21
  96. data/spec/dummy/app/views/platforms/new.html.erb +0 -5
  97. data/spec/dummy/app/views/platforms/show.html.erb +0 -5
  98. data/spec/dummy/config/application.rb +0 -64
  99. data/spec/dummy/config/boot.rb +0 -6
  100. data/spec/dummy/config/database.yml +0 -22
  101. data/spec/dummy/config/environment.rb +0 -5
  102. data/spec/dummy/config/environments/development.rb +0 -37
  103. data/spec/dummy/config/environments/production.rb +0 -67
  104. data/spec/dummy/config/environments/test.rb +0 -36
  105. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  106. data/spec/dummy/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  109. data/spec/dummy/config/initializers/session_store.rb +0 -8
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  111. data/spec/dummy/config/locales/en.yml +0 -5
  112. data/spec/dummy/config/routes.rb +0 -8
  113. data/spec/dummy/config.ru +0 -4
  114. data/spec/dummy/db/migrate/20110228091428_create_entities.rb +0 -14
  115. data/spec/dummy/db/migrate/20110228093241_create_platforms.rb +0 -14
  116. data/spec/dummy/db/migrate/20110228094444_create_versions.rb +0 -18
  117. data/spec/dummy/db/schema.rb +0 -41
  118. data/spec/dummy/db/seeds.rb +0 -7
  119. data/spec/dummy/doc/README_FOR_APP +0 -2
  120. data/spec/dummy/lib/assets/.gitkeep +0 -0
  121. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  122. data/spec/dummy/log/.gitkeep +0 -0
  123. data/spec/dummy/public/404.html +0 -26
  124. data/spec/dummy/public/422.html +0 -26
  125. data/spec/dummy/public/500.html +0 -25
  126. data/spec/dummy/public/favicon.ico +0 -0
  127. data/spec/dummy/public/index.html +0 -241
  128. data/spec/dummy/public/robots.txt +0 -5
  129. data/spec/dummy/script/rails +0 -6
  130. data/spec/dummy/test/fixtures/.gitkeep +0 -0
  131. data/spec/dummy/test/functional/.gitkeep +0 -0
  132. data/spec/dummy/test/integration/.gitkeep +0 -0
  133. data/spec/dummy/test/performance/browsing_test.rb +0 -12
  134. data/spec/dummy/test/test_helper.rb +0 -13
  135. data/spec/dummy/test/unit/.gitkeep +0 -0
  136. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  137. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  138. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  139. data/spec/helpers/entities_helper_spec.rb +0 -15
  140. data/spec/helpers/platforms_helper_spec.rb +0 -15
  141. data/spec/models/entity_spec.rb +0 -14
  142. data/spec/models/platform_spec.rb +0 -14
  143. data/spec/requests/entities_spec.rb +0 -11
  144. data/spec/requests/platforms_spec.rb +0 -11
  145. data/spec/routing/entities_routing_spec.rb +0 -35
  146. data/spec/routing/platforms_routing_spec.rb +0 -35
  147. data/spec/views/entities/edit.html.erb_spec.rb +0 -15
  148. data/spec/views/entities/index.html.erb_spec.rb +0 -14
  149. data/spec/views/entities/new.html.erb_spec.rb +0 -15
  150. data/spec/views/entities/show.html.erb_spec.rb +0 -11
  151. data/spec/views/platforms/edit.html.erb_spec.rb +0 -15
  152. data/spec/views/platforms/index.html.erb_spec.rb +0 -14
  153. data/spec/views/platforms/new.html.erb_spec.rb +0 -15
  154. data/spec/views/platforms/show.html.erb_spec.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2549171549b22c9328db417189798ea21871029c
4
- data.tar.gz: 150cc4d55fbf5db0818687c333c6df8d463226af
2
+ SHA256:
3
+ metadata.gz: fcc29d8525d99579c156724e3ae0632d363f633419b1fe2e3d8424be01a2cc8f
4
+ data.tar.gz: 4a18af9ec1ce747d7f1be7cb090172694ac1cd05ff7bfdfe8b4cfbf7a064f73b
5
5
  SHA512:
6
- metadata.gz: fea549305c1d60b72b0ee0cb7638967f5618789b8ee4fe709c200706a118ed4e5d6a7a63dfb30228313008ac41e61cbbd083fd663f03610108b73b409c257775
7
- data.tar.gz: 2b3e7b426fd66283adabdfee001ce2415eec56537fdbc8c249509fb3428c893f2b736db4a3ad5e10e1739c70094aba8e0678b9042026fa13f00cdb2dd863a5d8
6
+ metadata.gz: b8d7880ea9aee2269b2d99702559bc30323bc3ba932c850124c640e0508ed841f1eb9ed11c81c1af9a233903cfa83f9cc526c0e57e6648a1d3b163c2d48439a8
7
+ data.tar.gz: d4daf880c144649090bf0d29d373783890d9b332f41a39c032aa11efb4489432272e60b683904884facdbdc1f62d4ee67d7f8109549e262c5ad3625f7c668240
@@ -0,0 +1,88 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+ - reopened
8
+ - synchronize
9
+ - ready_for_review
10
+ push:
11
+ branches:
12
+ - 'master'
13
+
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby:
22
+ - 2.5.7
23
+ - 2.6.5
24
+ gemfile:
25
+ - gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile
26
+ - gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile
27
+ - gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile
28
+ - gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile
29
+ - gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile
30
+ - gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile
31
+ - gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile
32
+ - gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile
33
+ - gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile
34
+ - gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile
35
+ - gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile
36
+ - gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile
37
+ - gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile
38
+ - gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile
39
+ - gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile
40
+ - gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile
41
+ - gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile
42
+ - gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile
43
+ - gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile
44
+ - gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile
45
+ - gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile
46
+ - gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile
47
+ - gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile
48
+ - gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile
49
+ - gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile
50
+ - gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile
51
+ - gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile
52
+ - gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile
53
+ - gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile
54
+ - gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile
55
+ - gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile
56
+ - gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile
57
+ - gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile
58
+ - gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile
59
+
60
+ env:
61
+ BUNDLER_VERSION: 1.17.3
62
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
63
+
64
+ steps:
65
+ - uses: actions/checkout@v2
66
+ - uses: actions/setup-ruby@v1
67
+ with:
68
+ ruby-version: ${{ matrix.ruby }}
69
+ - uses: actions/cache@v1
70
+ with:
71
+ path: vendor/bundle
72
+ key: ${{ runner.os }}-${{ matrix.ruby}}-gems-${{ hashFiles('**/paper_trail_manager.gemspec') }}
73
+ restore-keys: |
74
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-
75
+ - name: Install System Dependencies
76
+ run: |
77
+ sudo apt-get update
78
+ sudo apt-get install sqlite3 libsqlite3-dev
79
+ gem install bundler -v $BUNDLER_VERSION
80
+ - name: bundle install
81
+ run: |
82
+ bundle config path vendor/bundle
83
+ bundle install --jobs 4 --retry 3
84
+ - name: Generate host app for testing
85
+ run: bundle exec rake generate_spec_app
86
+ - name: Run RSpec
87
+ run: |
88
+ bundle exec rake spec
data/.gitignore CHANGED
@@ -13,3 +13,4 @@ Gemfile.lock
13
13
  *.a
14
14
  mkmf.log
15
15
  *.gemfile.lock
16
+ spec/dummy
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rails
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ Exclude:
9
+ - 'spec/dummy/**/*'
10
+
11
+ Rails:
12
+ Enabled: true
13
+
14
+ Style/HashEachMethods:
15
+ Enabled: true
16
+
17
+ Style/HashTransformKeys:
18
+ Enabled: true
19
+
20
+ Style/HashTransformValues:
21
+ Enabled: true
22
+
23
+ Layout/LineLength:
24
+ Max: 120
25
+
26
+ RSpec/NestedGroups:
27
+ Enabled: false
28
+
29
+ RSpec/MultipleExpectations:
30
+ Enabled: false
31
+
32
+ Metrics/BlockLength:
33
+ Enabled: false
data/Appraisals CHANGED
@@ -1,39 +1,31 @@
1
- appraise "rails-3.2-will-paginate" do
2
- gem "rails", "~> 3.2.21"
3
- gem "will_paginate", "~> 3.0"
4
- end
5
-
6
- appraise "rails-4.0-will-paginate" do
7
- gem "rails", "~> 4.0.13"
8
- gem "will_paginate", "~> 3.0"
9
- end
10
-
11
- appraise "rails-4.1-will-paginate" do
12
- gem "rails", "~> 4.1.11"
13
- gem "will_paginate", "~> 3.0"
14
- end
1
+ # frozen_string_literal: true
15
2
 
16
- appraise "rails-4.2-will-paginate" do
17
- gem "rails", "~> 4.2.2"
18
- gem "will_paginate", "~> 3.0"
19
- end
3
+ {
4
+ '4.2.2' => %w[3.0 4.0 5.0 6.0 7.0 8.0],
5
+ '5.0.0' => %w[5.0 6.0 7.0 8.0],
6
+ '5.1.0' => %w[7.0 8.0 9.0 10.0],
7
+ '5.2.0' => %w[9.0 10.0],
8
+ '6.0.0' => %w[10.0]
9
+ }.each do |rails_version, paper_trail_versions|
10
+ paper_trail_versions.each do |paper_trail_version|
11
+ appraise "rails-#{rails_version}-paper_trail-#{paper_trail_version}-will-paginate" do
12
+ gem 'rails', "~> #{rails_version}"
13
+ gem 'jquery-rails'
14
+ gem 'sqlite3', rails_version == '6.0.0' ? '~> 1.4' : '~> 1.3.6'
15
+ gem 'paper_trail', "~> #{paper_trail_version}"
16
+ gem 'will_paginate', '~> 3.0'
20
17
 
21
- appraise "rails-3.2-kaminari" do
22
- gem "rails", "~> 3.2.21"
23
- gem "kaminari", "~> 0.16"
24
- end
18
+ gem 'webpacker' if rails_version == '6.0.0'
19
+ end
25
20
 
26
- appraise "rails-4.0-kaminari" do
27
- gem "rails", "~> 4.0.13"
28
- gem "kaminari", "~> 0.16"
29
- end
30
-
31
- appraise "rails-4.1-kaminari" do
32
- gem "rails", "~> 4.1.11"
33
- gem "kaminari", "~> 0.16"
34
- end
21
+ appraise "rails-#{rails_version}-paper_trail-#{paper_trail_version}-kaminari" do
22
+ gem 'rails', "~> #{rails_version}"
23
+ gem 'jquery-rails'
24
+ gem 'sqlite3', rails_version == '6.0.0' ? '~> 1.4' : '~> 1.3.6'
25
+ gem 'paper_trail', "~> #{paper_trail_version}"
26
+ gem 'kaminari', '>= 0.16'
35
27
 
36
- appraise "rails-4.2-kaminari" do
37
- gem "rails", "~> 4.2.2"
38
- gem "kaminari", "~> 0.16"
28
+ gem 'webpacker' if rails_version == '6.0.0'
29
+ end
30
+ end
39
31
  end
data/CHANGES.md CHANGED
@@ -1,10 +1,22 @@
1
1
  Changes to `paper_trail_manager`
2
2
  ================================
3
3
 
4
+ * 0.7.0
5
+ * Add support for Rails 5 and 6
6
+ * Add support for paper_trail 5.x – 10.x
7
+ * Drop support for Rails < 4.1
8
+ * Drop support for Ruby < 2.5
9
+
10
+ * 0.6.0
11
+ * Add support for linking changes to user records via `PaperTrailManager.whodunnit_name_method` and `PaperTrailManager.user_path_method`
12
+ * Add new `PaperTrailManager.item_name_method` configuration option
13
+ * Add support for paper_trail 4.x
14
+ * Refactoring, code simplification, and performance improvements
15
+
4
16
  * 0.5.0
5
- * Added support for pagination with [Kaminari](https://github.com/amatsuda/kaminari) in addition to [will_paginate](https://github.com/mislav/will_paginate).
17
+ * Add support for pagination with [Kaminari](https://github.com/amatsuda/kaminari) in addition to [will_paginate](https://github.com/mislav/will_paginate).
6
18
  * **[!]** Removed direct dependency on will_paginate. You must now include either `will_paginate` or `kaminari` in your Gemfile.
7
- * Fixed a bug with route generation when paper_trail_manager is used within another Rails engine.
19
+ * Fix a bug with route generation when paper_trail_manager is used within another Rails engine.
8
20
 
9
21
  * 0.4.0
10
22
  * Allow configuration of ChangesController's parent class, route helpers, and layout
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in paper_trail_manager.gemspec
4
6
  gemspec
5
-
data/README.md CHANGED
@@ -35,7 +35,7 @@ Restart the server and go to the `/changes` URI to browse, subscribe, view and r
35
35
  ### Configuration
36
36
 
37
37
  Several aspects of PaperTrailManager may be optionally configured
38
- by creating an initializer in your application
38
+ by creating an initializer in your application
39
39
  (e.g. `config/initializers/paper_trail_manager.rb`).
40
40
 
41
41
  To specify when reverts are allowed:
@@ -49,6 +49,15 @@ To specify how to look up users/memebers/etc specified in Paper Trail's 'whodunn
49
49
  PaperTrailManager.whodunnit_class = User
50
50
  PaperTrailManager.whodunnit_name_method = :nicename # defaults to :name
51
51
 
52
+ To specify a method to call to identify an item on an index page:
53
+
54
+ PaperTrailManager.item_name_method = :nicename
55
+
56
+ And for linking (or not) to the user with a custom path helper:
57
+
58
+ PaperTrailManager.user_path_method = :admin_path # defaults to :user_path
59
+ PaperTrailManager.user_path_method = nil # no "show user" page in app
60
+
52
61
  When including PaperTrailManager within another Rails engine, you may need to
53
62
  override PaperTrailManager::ChangesController's parent class to reference the
54
63
  engine's ApplicationController configure it to use your engine's url helpers:
data/Rakefile CHANGED
@@ -1,18 +1,23 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'rubygems'
4
4
 
5
- require "bundler/gem_tasks"
5
+ require 'bundler/gem_tasks'
6
6
  Bundler::GemHelper.install_tasks
7
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
- load 'rails/tasks/engine.rake'
7
+
8
+ app_rakefile_path = File.expand_path('spec/dummy/Rakefile', __dir__)
9
+
10
+ if File.exist?(app_rakefile_path)
11
+ APP_RAKEFILE = app_rakefile_path
12
+ load 'rails/tasks/engine.rake'
13
+ end
9
14
 
10
15
  require 'rake'
11
16
  require 'rdoc/task'
12
17
 
13
18
  require 'rspec/core/rake_task'
14
19
  RSpec::Core::RakeTask.new
15
- task :default => ["db:create", "db:migrate", "spec"]
20
+ task default: ['db:create', 'db:migrate', 'spec']
16
21
 
17
22
  Rake::RDocTask.new(:rdoc) do |rdoc|
18
23
  rdoc.rdoc_dir = 'rdoc'
@@ -22,3 +27,10 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
22
27
  rdoc.rdoc_files.include('lib/**/*.rb')
23
28
  end
24
29
 
30
+ task :generate_spec_app do
31
+ sh 'rm -rf spec/dummy'
32
+ sh 'rails new spec/dummy --skip-bootsnap --skip-bundle --skip-yarn \
33
+ --skip-git --skip-action-mailer --skip-puma --skip-test --skip-coffee \
34
+ --skip-spring --skip-listen --skip-turbolinks \
35
+ --template=spec/app_template.rb'
36
+ end
@@ -1,128 +1,131 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Allow the parent class of ChangesController to be configured in the host app
2
4
  PaperTrailManager::ChangesController = Class.new(PaperTrailManager.base_controller.constantize)
3
5
 
4
- class PaperTrailManager::ChangesController
5
- # Default number of changes to list on a pagenated index page.
6
- PER_PAGE = 50
6
+ class PaperTrailManager
7
+ class ChangesController
8
+ # Default number of changes to list on a pagenated index page.
9
+ PER_PAGE = 50
7
10
 
8
- helper PaperTrailManager.route_helpers if PaperTrailManager.route_helpers
9
- helper PaperTrailManager::ChangesHelper
10
- layout PaperTrailManager.layout if PaperTrailManager.layout
11
+ helper PaperTrailManager.route_helpers if PaperTrailManager.route_helpers
12
+ helper PaperTrailManager::ChangesHelper
13
+ layout PaperTrailManager.layout if PaperTrailManager.layout
11
14
 
12
- # List changes
13
- def index
14
- unless change_index_allowed?
15
- flash[:error] = "You do not have permission to list changes."
16
- return(redirect_to root_url)
17
- end
15
+ # List changes
16
+ def index
17
+ unless change_index_allowed?
18
+ flash[:error] = 'You do not have permission to list changes.'
19
+ return(redirect_to root_url)
20
+ end
18
21
 
19
- @versions = PaperTrail::Version.order('created_at DESC, id DESC')
20
- if params[:type]
21
- @versions = @versions.where(:item_type => params[:type])
22
- end
23
- if params[:id]
24
- @versions = @versions.where(:item_id => params[:id])
25
- end
22
+ @versions = PaperTrail::Version.order('created_at DESC, id DESC')
23
+ @versions = @versions.where(item_type: params[:type]) if params[:type]
24
+ @versions = @versions.where(item_id: params[:id]) if params[:id]
26
25
 
27
- # Ensure pagination parameters have sensible values
28
- @page = (v = params[:page].to_i; v == 0 ? nil : v)
29
- @per_page = (v = params[:per_page].to_i; v == 0 ? PER_PAGE : v)
26
+ # Ensure pagination parameters have sensible values
27
+ @page = params[:page].to_i
28
+ @page = nil if @page.zero?
30
29
 
31
- if defined?(WillPaginate)
32
- @versions = @versions.paginate(:page => @page, :per_page => @per_page)
33
- else
34
- @versions = @versions.page(@page).per(@per_page)
35
- end
30
+ @per_page = params[:per_page].to_i
31
+ @per_page = nil if @per_page.zero?
36
32
 
37
- respond_to do |format|
38
- format.html # index.html.erb
39
- format.atom # index.atom.builder
40
- format.json { render :json => @versions }
41
- end
42
- end
33
+ @versions = if defined?(WillPaginate)
34
+ @versions.paginate(page: @page, per_page: @per_page)
35
+ else
36
+ @versions.page(@page).per(@per_page)
37
+ end
43
38
 
44
- # Show a change
45
- def show
46
- begin
47
- @version = PaperTrail::Version.find(params[:id])
48
- rescue ActiveRecord::RecordNotFound
49
- flash[:error] = "No such version."
50
- return(redirect_to :action => :index)
39
+ respond_to do |format|
40
+ format.html # index.html.erb
41
+ format.atom # index.atom.builder
42
+ format.json { render json: @versions }
43
+ end
51
44
  end
52
45
 
53
- unless change_show_allowed?(@version)
54
- flash[:error] = "You do not have permission to show that change."
55
- return(redirect_to :action => :index)
56
- end
46
+ # Show a change
47
+ def show
48
+ begin
49
+ @version = PaperTrail::Version.find(params[:id])
50
+ rescue ActiveRecord::RecordNotFound
51
+ flash[:error] = 'No such version.'
52
+ return(redirect_to action: :index)
53
+ end
57
54
 
58
- respond_to do |format|
59
- format.html # show.html.erb
60
- format.json { render :json => @version }
61
- end
62
- end
55
+ unless change_show_allowed?(@version)
56
+ flash[:error] = 'You do not have permission to show that change.'
57
+ return(redirect_to action: :index)
58
+ end
63
59
 
64
- # Rollback a change
65
- def update
66
- begin
67
- @version = PaperTrail::Version.find(params[:id])
68
- rescue ActiveRecord::RecordNotFound
69
- flash[:error] = "No such version."
70
- return(redirect_to(changes_path))
60
+ respond_to do |format|
61
+ format.html # show.html.erb
62
+ format.json { render json: @version }
63
+ end
71
64
  end
72
65
 
73
- unless change_revert_allowed?(@version)
74
- flash[:error] = "You do not have permission to revert this change."
75
- return(redirect_to changes_path)
76
- end
66
+ # Rollback a change
67
+ def update
68
+ begin
69
+ @version = PaperTrail::Version.find(params[:id])
70
+ rescue ActiveRecord::RecordNotFound
71
+ flash[:error] = 'No such version.'
72
+ return(redirect_to(changes_path))
73
+ end
77
74
 
78
- if @version.event == "create"
79
- @record = @version.item_type.constantize.find(@version.item_id)
80
- @result = @record.destroy
81
- else
82
- @record = @version.reify
83
- @result = @record.save
84
- end
75
+ unless change_revert_allowed?(@version)
76
+ flash[:error] = 'You do not have permission to revert this change.'
77
+ return(redirect_to changes_path)
78
+ end
85
79
 
86
- if @result
87
- if @version.event == "create"
88
- flash[:notice] = "Rolled back newly-created record by destroying it."
89
- redirect_to changes_path
80
+ if @version.event == 'create'
81
+ @record = @version.item_type.constantize.find(@version.item_id)
82
+ @result = @record.destroy
90
83
  else
91
- flash[:notice] = "Rolled back changes to this record."
92
- redirect_to change_item_url(@version)
84
+ @record = @version.reify
85
+ @result = @record.save
86
+ end
87
+
88
+ if @result
89
+ if @version.event == 'create'
90
+ flash[:notice] = 'Rolled back newly-created record by destroying it.'
91
+ redirect_to changes_path
92
+ else
93
+ flash[:notice] = 'Rolled back changes to this record.'
94
+ redirect_to change_item_url(@version)
95
+ end
96
+ else
97
+ flash[:error] = "Couldn't rollback. Sorry."
98
+ redirect_to changes_path
93
99
  end
94
- else
95
- flash[:error] = "Couldn't rollback. Sorry."
96
- redirect_to changes_path
97
100
  end
98
- end
99
101
 
100
- protected
102
+ protected
101
103
 
102
- # Return the URL for the item represented by the +version+, e.g. a Company record instance referenced by a version.
103
- def change_item_url(version)
104
- version_type = version.item_type.underscore.split('/').last
105
- return send("#{version_type}_url", version.item_id)
106
- rescue NoMethodError
107
- return nil
108
- end
109
- helper_method :change_item_url
104
+ # Return the URL for the item represented by the +version+, e.g. a Company record instance referenced by a version.
105
+ def change_item_url(version)
106
+ version_type = version.item_type.underscore.split('/').last
107
+ send("#{version_type}_url", version.item_id)
108
+ rescue NoMethodError
109
+ nil
110
+ end
111
+ helper_method :change_item_url
110
112
 
111
- # Allow index?
112
- def change_index_allowed?
113
- return PaperTrailManager.allow_index?(self)
114
- end
115
- helper_method :change_index_allowed?
113
+ # Allow index?
114
+ def change_index_allowed?
115
+ PaperTrailManager.allow_index?(self)
116
+ end
117
+ helper_method :change_index_allowed?
116
118
 
117
- # Allow show?
118
- def change_show_allowed?(version)
119
- return PaperTrailManager.allow_show?(self, version)
120
- end
121
- helper_method :change_show_allowed?
119
+ # Allow show?
120
+ def change_show_allowed?(version)
121
+ PaperTrailManager.allow_show?(self, version)
122
+ end
123
+ helper_method :change_show_allowed?
122
124
 
123
- # Allow revert?
124
- def change_revert_allowed?(version)
125
- return PaperTrailManager.allow_revert?(self, version)
125
+ # Allow revert?
126
+ def change_revert_allowed?(version)
127
+ PaperTrailManager.allow_revert?(self, version)
128
+ end
129
+ helper_method :change_revert_allowed?
126
130
  end
127
- helper_method :change_revert_allowed?
128
131
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PaperTrailManager
2
4
  module ChangesHelper
3
5
  # Return HTML representing the +object+, which is either its text or a stylized "nil".
4
6
  def text_or_nil(object)
5
7
  if object.nil?
6
- return content_tag("em", "nil")
8
+ content_tag('em', 'nil')
7
9
  else
8
- return h(object)
10
+ h(object)
9
11
  end
10
12
  end
11
13
 
@@ -25,75 +27,56 @@ class PaperTrailManager
25
27
  # ...
26
28
  # }
27
29
  def changes_for(version)
28
- changes = {}
29
- current = version.next.try(:reify)
30
- # FIXME #reify randomly throws "ArgumentError Exception: syntax error on line 13, col 30:" -- why?
31
- previous = version.reify rescue nil
32
- record = \
33
- begin
34
- version.item_type.constantize.find(version.item_id)
35
- rescue ActiveRecord::RecordNotFound
36
- previous || current
37
- end
30
+ case version.event
31
+ when 'create', 'update'
32
+ return {} unless version.changeset
38
33
 
39
- # Bail out if no changes are available
40
- return changes unless record
34
+ version.changeset.inject({}) do |changes, (attr, (prev, curr))|
35
+ changes.store(attr, { previous: prev, current: curr }) && changes
36
+ end
37
+ when 'destroy'
38
+ record = version_reify(version)
39
+ return {} unless record
41
40
 
42
- case version.event
43
- when "create", "update"
44
- current ||= record
45
- when "destroy"
46
- previous ||= record
41
+ record.attributes.reject { |_k, v| v.nil? }.inject({}) do |changes, (attr, value)|
42
+ changes.store(attr, { previous: value, current: nil }) && changes
43
+ end
47
44
  else
48
45
  raise ArgumentError, "Unknown event: #{version.event}"
49
46
  end
50
-
51
- (current or previous).attribute_names.each do |name|
52
- next if name == "updated_at"
53
- next if name == "created_at"
54
- current_value = current.read_attribute(name) if current
55
- previous_value = previous.read_attribute(name) if previous
56
- unless current_value == previous_value || (version.event == "create" && current_value.blank?)
57
- changes[name] = {
58
- :previous => previous_value,
59
- :current => current_value,
60
- }
61
- end
62
- end
63
-
64
- return changes
65
47
  end
66
48
 
67
49
  # Returns string title for the versioned record.
68
50
  def change_title_for(version)
69
- current = version.next.try(:reify)
70
- previous = version.reify rescue nil
71
- record = version.item_type.constantize.find(version.item_id) rescue nil
72
-
73
- name = nil
74
- [:name, :title, :to_s].each do |name_method|
75
- [previous, current, record].each do |obj|
76
- name = obj.send(name_method) if obj.respond_to?(name_method)
77
- break if name
78
- end
79
- break if name
51
+ if PaperTrailManager.item_name_method
52
+ record = version_reify(version) || version.next.try(:reify) || version.item
53
+ name = record.send(PaperTrailManager.item_name_method)
54
+ else
55
+ name = "#{version.item_type} #{version.item_id}"
80
56
  end
81
57
 
82
- return h(name)
58
+ h(name)
83
59
  end
84
60
 
85
- # Returns sorted array of types of items that there are changes for.
86
61
  def change_item_types
87
- return ActiveRecord::Base.connection.select_values('SELECT DISTINCT(item_type) FROM versions ORDER BY item_type')
62
+ ActiveRecord::Base.subclasses.select do |klass|
63
+ klass.include?(PaperTrail::Model::InstanceMethods)
64
+ end.map(&:to_s)
88
65
  end
89
66
 
90
67
  # Returns HTML link for the item stored in the version, e.g. a link to a Company record stored in the version.
91
68
  def change_item_link(version)
92
- if url = change_item_url(version)
93
- return link_to(change_title_for(version), url, :class => 'change_item')
69
+ if (url = change_item_url(version))
70
+ link_to(change_title_for(version), url, class: 'change_item')
94
71
  else
95
- return content_tag(:span, change_title_for(version), :class => 'change_item')
72
+ content_tag(:span, change_title_for(version), class: 'change_item')
96
73
  end
97
74
  end
75
+
76
+ def version_reify(version)
77
+ version.reify
78
+ rescue ArgumentError
79
+ nil
80
+ end
98
81
  end
99
82
  end