paper_trail 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +3 -3
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +10 -20
  5. data/lib/paper_trail.rb +0 -20
  6. data/lib/paper_trail/frameworks/rails/controller.rb +10 -33
  7. data/lib/paper_trail/version_association_concern.rb +0 -4
  8. data/lib/paper_trail/version_concern.rb +1 -29
  9. data/lib/paper_trail/version_number.rb +1 -1
  10. data/spec/models/post_with_status_spec.rb +33 -37
  11. data/test/dummy/app/controllers/application_controller.rb +5 -8
  12. data/test/dummy/app/controllers/articles_controller.rb +1 -5
  13. data/test/dummy/app/controllers/widgets_controller.rb +1 -5
  14. data/test/dummy/app/models/animal.rb +0 -2
  15. data/test/dummy/app/models/document.rb +4 -2
  16. data/test/dummy/app/models/legacy_widget.rb +1 -2
  17. data/test/dummy/app/models/post_with_status.rb +3 -4
  18. data/test/dummy/app/models/skipper.rb +1 -4
  19. data/test/dummy/app/models/translation.rb +4 -2
  20. data/test/dummy/app/models/vehicle.rb +1 -1
  21. data/test/dummy/app/models/widget.rb +2 -10
  22. data/test/dummy/config/application.rb +0 -8
  23. data/test/dummy/config/environments/development.rb +0 -5
  24. data/test/dummy/config/environments/test.rb +0 -5
  25. data/test/dummy/config/initializers/paper_trail.rb +0 -8
  26. data/test/test_helper.rb +1 -10
  27. data/test/unit/model_test.rb +16 -33
  28. metadata +1 -11
  29. data/test/dummy/app/helpers/application_helper.rb +0 -2
  30. data/test/dummy/app/models/protected_widget.rb +0 -3
  31. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  32. data/test/dummy/script/rails +0 -8
  33. data/test/unit/protected_attrs_test.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70bf4fda92d269f953d7e88fc0a78f72ff3e288e
4
- data.tar.gz: 52bf0491880b3dba4905af331f84bc9de67d0bef
3
+ metadata.gz: e2aaa66f683707d78b3d5c9a294e01c9e9b16813
4
+ data.tar.gz: f9e5043fea515093cd21d151eda33e7b915de194
5
5
  SHA512:
6
- metadata.gz: 7b139581b4bf0efa29562edc58d30e3854d746d6064c1e4d0a36204ffb1ed34c81d909eea0e6866fa42b35c34f8a3b0fef5e77858f00579bdeca50441d3c13d7
7
- data.tar.gz: 1608f17448169a8f2084ce44782cfcac844bd6cf4faba4f283c81b5c338dbed9afc68f5b985279e35019cdb5f40f90a2835a2f9b4ed50ff1e998dc5d78471ea2
6
+ metadata.gz: ac92887f5f16f868f7f5936e9e9c6353533c3a9f233989ae075d3cb1550a3c4bc9b51b6523dc22899e695b2bbfded7f3a9ed4a7bbd814fe9e9c4ec15eabea30b
7
+ data.tar.gz: 8b31ac54123aeba74eb156b5d6971c3a579e3a3cae0ee8e2b55c2c824c018e8e0267f616fb92aa09ebec1a2404b93e57e2ffe8ad4c9554a9509c4ea4d38e142f
@@ -89,9 +89,9 @@ DB=postgres bundle exec appraisal ar-5.0 rake
89
89
  1. In the changelog,
90
90
  - Replace "Unreleased" with the date in iso-8601 format
91
91
  - Add a new "Unreleased" section
92
- 1. In the readme,
93
- - Update any other references to version number, including
94
- - Update version number(s) in the documentation links table
92
+ 1. In the readme, update references to version number, including
93
+ - documentation links table
94
+ - compatability table
95
95
  1. Commit
96
96
  1. git tag -a -m "v5.0.0" "v5.0.0" # or whatever number
97
97
  1. git push --tags origin 5-stable # or whatever branch
@@ -17,6 +17,21 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
17
17
 
18
18
  - None
19
19
 
20
+ ## 6.0.1 (2016-12-04)
21
+
22
+ ### Breaking Changes
23
+
24
+ - None
25
+
26
+ ### Added
27
+
28
+ - None
29
+
30
+ ### Fixed
31
+
32
+ - Remove rails 3 features that are no longer supported, most notably,
33
+ `protected_attributes`.
34
+
20
35
  ## 6.0.0 (2016-12-03)
21
36
 
22
37
  Now with rails 5.1 support, and less model pollution! About 40 methods that were
data/README.md CHANGED
@@ -10,7 +10,8 @@ has been destroyed.
10
10
 
11
11
  | Version | Documentation |
12
12
  | -------------- | ------------- |
13
- | 6.0.0 | https://github.com/airblade/paper_trail/blob/master/README.md |
13
+ | Unreleased | https://github.com/airblade/paper_trail/blob/master/README.md |
14
+ | 6.0.1 | https://github.com/airblade/paper_trail/blob/v6.0.1/README.md |
14
15
  | 5.2.3 | https://github.com/airblade/paper_trail/blob/v5.2.3/README.md |
15
16
  | 4.2.0 | https://github.com/airblade/paper_trail/blob/v4.2.0/README.md |
16
17
  | 3.0.9 | https://github.com/airblade/paper_trail/blob/v3.0.9/README.md |
@@ -45,6 +46,7 @@ has been destroyed.
45
46
  - [5.a. Single Table Inheritance](#5a-single-table-inheritance-sti)
46
47
  - [5.b. Configuring the `versions` Association](#5b-configuring-the-versions-association)
47
48
  - [5.c. Generators](#5c-generators)
49
+ - [5.d. Protected Attributes](#5d-protected-attributes)
48
50
  - [6. Extensibility](#6-extensibility)
49
51
  - [6.a. Custom Version Classes](#6a-custom-version-classes)
50
52
  - [6.b. Custom Serializer](#6b-custom-serializer)
@@ -1008,30 +1010,12 @@ class ApplicationController
1008
1010
  end
1009
1011
  ```
1010
1012
 
1011
- #### Protected Attributes and Metadata
1012
-
1013
- If you are using rails 3 or the [protected_attributes][17] gem you must declare
1014
- your metadata columns to be `attr_accessible`.
1015
-
1016
- ```ruby
1017
- # app/models/paper_trail/version.rb
1018
- module PaperTrail
1019
- class Version < ActiveRecord::Base
1020
- include PaperTrail::VersionConcern
1021
- attr_accessible :author_id, :word_count, :answer
1022
- end
1023
- end
1024
- ```
1025
-
1026
- If you're using [strong_parameters][18] instead of [protected_attributes][17]
1027
- then there is no need to use `attr_accessible`.
1028
-
1029
1013
  ## 5. ActiveRecord
1030
1014
 
1031
1015
  ### 5.a. Single Table Inheritance (STI)
1032
1016
 
1033
1017
  PaperTrail supports [Single Table Inheritance][39], and even supports an
1034
- un-versioned base model, as of 23ffbdc7e1.
1018
+ un-versioned base model, as of `23ffbdc7e1`.
1035
1019
 
1036
1020
  ```ruby
1037
1021
  class Fruit < ActiveRecord::Base
@@ -1087,6 +1071,12 @@ Runtime options:
1087
1071
  Generates (but does not run) a migration to add a versions table. Also generates an initializer file for configuring PaperTrail
1088
1072
  ```
1089
1073
 
1074
+ ### 5.d. Protected Attributes
1075
+
1076
+ As of version 6, PT no longer supports rails 3 or the [protected_attributes][17]
1077
+ gem. If you are still using them, you may use PT 5 or lower. We recommend
1078
+ upgrading to [strong_parameters][18] as soon as possible.
1079
+
1090
1080
  ## 6. Extensibility
1091
1081
 
1092
1082
  ### 6.a. Custom Version Classes
@@ -121,15 +121,6 @@ module PaperTrail
121
121
  PaperTrail.config.serializer
122
122
  end
123
123
 
124
- # Returns a boolean indicating whether "protected attibutes" should be
125
- # configured, e.g. attr_accessible, mass_assignment_sanitizer,
126
- # whitelist_attributes, etc.
127
- # @api public
128
- def active_record_protected_attributes?
129
- @active_record_protected_attributes ||= ::ActiveRecord::VERSION::MAJOR < 4 ||
130
- !!defined?(ProtectedAttributes)
131
- end
132
-
133
124
  # @api public
134
125
  def transaction?
135
126
  ::ActiveRecord::Base.connection.open_transactions > 0
@@ -167,17 +158,6 @@ module PaperTrail
167
158
  end
168
159
  end
169
160
 
170
- # If available, ensure that the `protected_attributes` gem is loaded
171
- # before the `Version` class.
172
- unless PaperTrail.active_record_protected_attributes?
173
- PaperTrail.send(:remove_instance_variable, :@active_record_protected_attributes)
174
- begin
175
- require "protected_attributes"
176
- rescue LoadError # rubocop:disable Lint/HandleExceptions
177
- # In case `protected_attributes` gem is not available.
178
- end
179
- end
180
-
181
161
  ActiveSupport.on_load(:active_record) do
182
162
  include PaperTrail::Model
183
163
  end
@@ -4,24 +4,11 @@ module PaperTrail
4
4
  # information to the model layer, with `controller_info` and `whodunnit`.
5
5
  # Also includes a convenient on/off switch, `enabled_for_controller`.
6
6
  module Controller
7
- def self.included(base)
8
- before = [
7
+ def self.included(controller)
8
+ controller.before_action(
9
9
  :set_paper_trail_enabled_for_controller,
10
10
  :set_paper_trail_controller_info
11
- ]
12
- after = [
13
- :warn_about_not_setting_whodunnit
14
- ]
15
-
16
- if base.respond_to? :before_action
17
- # Rails 4+
18
- before.map { |sym| base.before_action sym }
19
- after.map { |sym| base.after_action sym }
20
- else
21
- # Rails 3.
22
- before.map { |sym| base.before_filter sym }
23
- after.map { |sym| base.after_filter sym }
24
- end
11
+ )
25
12
  end
26
13
 
27
14
  protected
@@ -89,24 +76,14 @@ module PaperTrail
89
76
  ::PaperTrail.controller_info = info_for_paper_trail if ::PaperTrail.enabled_for_controller?
90
77
  end
91
78
 
79
+ # We have removed this warning. We no longer add it as a callback.
80
+ # However, some people use `skip_after_action :warn_about_not_setting_whodunnit`,
81
+ # so removing this method would be a breaking change. We can remove it
82
+ # in the next major version.
92
83
  def warn_about_not_setting_whodunnit
93
- return unless ::PaperTrail.enabled_for_controller?
94
-
95
- user_present = user_for_paper_trail.present?
96
- whodunnit_blank = ::PaperTrail.whodunnit.blank?
97
- if user_present && whodunnit_blank && !@set_paper_trail_whodunnit_called
98
- source_file_location = self.class.instance_methods(false).map { |m|
99
- self.class.instance_method(m).source_location.first
100
- }.uniq.first
101
- ::Kernel.warn <<-EOS.strip_heredoc
102
- #{source_file_location}:
103
- user_for_paper_trail is present, but whodunnit has not been set.
104
- PaperTrail no longer adds the set_paper_trail_whodunnit callback for
105
- you. To continue recording whodunnit, please add this before_action
106
- callback to your ApplicationController. For more information,
107
- please see https://git.io/vrTsk
108
- EOS
109
- end
84
+ ::ActiveSupport::Deprecation.warn(
85
+ "warn_about_not_setting_whodunnit is a no-op and is deprecated."
86
+ )
110
87
  end
111
88
  end
112
89
  end
@@ -8,10 +8,6 @@ module PaperTrail
8
8
 
9
9
  included do
10
10
  belongs_to :version
11
-
12
- if PaperTrail.active_record_protected_attributes?
13
- attr_accessible :version_id, :foreign_key_name, :foreign_key_id
14
- end
15
11
  end
16
12
  end
17
13
  end
@@ -21,22 +21,7 @@ module PaperTrail
21
21
  end
22
22
 
23
23
  validates_presence_of :event
24
-
25
- if PaperTrail.active_record_protected_attributes?
26
- attr_accessible(
27
- :item_type,
28
- :item_id,
29
- :event,
30
- :whodunnit,
31
- :object,
32
- :object_changes,
33
- :transaction_id,
34
- :created_at
35
- )
36
- end
37
-
38
24
  after_create :enforce_version_limit!
39
-
40
25
  scope :within_transaction, ->(id) { where transaction_id: id }
41
26
  end
42
27
 
@@ -225,9 +210,7 @@ module PaperTrail
225
210
  #
226
211
  def reify(options = {})
227
212
  return nil if object.nil?
228
- without_identity_map do
229
- ::PaperTrail::Reifier.reify(self, options)
230
- end
213
+ ::PaperTrail::Reifier.reify(self, options)
231
214
  end
232
215
 
233
216
  # Returns what changed in this version of the item.
@@ -323,17 +306,6 @@ module PaperTrail
323
306
  end
324
307
  end
325
308
 
326
- # In Rails 3.1+, calling reify on a previous version confuses the
327
- # IdentityMap, if enabled. This prevents insertion into the map.
328
- # @api private
329
- def without_identity_map(&block)
330
- if defined?(::ActiveRecord::IdentityMap) && ::ActiveRecord::IdentityMap.respond_to?(:without)
331
- ::ActiveRecord::IdentityMap.without(&block)
332
- else
333
- yield
334
- end
335
- end
336
-
337
309
  # Checks that a value has been set for the `version_limit` config
338
310
  # option, and if so enforces it.
339
311
  # @api private
@@ -3,7 +3,7 @@ module PaperTrail
3
3
  module VERSION
4
4
  MAJOR = 6
5
5
  MINOR = 0
6
- TINY = 0
6
+ TINY = 1
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
@@ -1,49 +1,45 @@
1
1
  require "rails_helper"
2
2
 
3
- # This model tests ActiveRecord::Enum, which was added in AR 4.1
4
- # http://edgeguides.rubyonrails.org/4_1_release_notes.html#active-record-enums
5
3
  describe PostWithStatus, type: :model do
6
- if defined?(ActiveRecord::Enum)
7
- with_versioning do
8
- let(:post) { described_class.create!(status: "draft") }
4
+ with_versioning do
5
+ let(:post) { described_class.create!(status: "draft") }
9
6
 
10
- it "should stash the enum value properly in versions" do
11
- post.published!
12
- post.archived!
13
- expect(post.paper_trail.previous_version.published?).to be true
14
- end
7
+ it "should stash the enum value properly in versions" do
8
+ post.published!
9
+ post.archived!
10
+ expect(post.paper_trail.previous_version.published?).to be true
11
+ end
15
12
 
16
- it "can read enums in version records written by PT 4" do
17
- post = described_class.create(status: "draft")
18
- post.published!
19
- version = post.versions.last
20
- # Simulate behavior PT 4, which used to save the string version of
21
- # enums to `object_changes`
22
- version.update(object_changes: "---\nid:\n- \n- 1\nstatus:\n- draft\n- published\n")
23
- assert_equal %w(draft published), version.changeset["status"]
24
- end
13
+ it "can read enums in version records written by PT 4" do
14
+ post = described_class.create(status: "draft")
15
+ post.published!
16
+ version = post.versions.last
17
+ # Simulate behavior PT 4, which used to save the string version of
18
+ # enums to `object_changes`
19
+ version.update(object_changes: "---\nid:\n- \n- 1\nstatus:\n- draft\n- published\n")
20
+ assert_equal %w(draft published), version.changeset["status"]
21
+ end
25
22
 
26
- context "storing enum object_changes" do
27
- subject { post.versions.last }
23
+ context "storing enum object_changes" do
24
+ subject { post.versions.last }
28
25
 
29
- it "should stash the enum value properly in versions object_changes" do
30
- post.published!
31
- post.archived!
32
- expect(subject.changeset["status"]).to eql %w(published archived)
33
- end
26
+ it "should stash the enum value properly in versions object_changes" do
27
+ post.published!
28
+ post.archived!
29
+ expect(subject.changeset["status"]).to eql %w(published archived)
34
30
  end
31
+ end
35
32
 
36
- describe "#touch_with_version" do
37
- it "preserves the enum value (and all other attributes)" do
38
- post = described_class.create(status: :draft)
39
- expect(post.versions.count).to eq(1)
40
- expect(post.status).to eq("draft")
41
- Timecop.travel 1.second.since # because MySQL lacks fractional seconds precision
42
- post.paper_trail.touch_with_version
43
- expect(post.versions.count).to eq(2)
44
- expect(post.versions.last[:object]).to include("status: 0")
45
- expect(post.paper_trail.previous_version.status).to eq("draft")
46
- end
33
+ describe "#touch_with_version" do
34
+ it "preserves the enum value (and all other attributes)" do
35
+ post = described_class.create(status: :draft)
36
+ expect(post.versions.count).to eq(1)
37
+ expect(post.status).to eq("draft")
38
+ Timecop.travel 1.second.since # because MySQL lacks fractional seconds precision
39
+ post.paper_trail.touch_with_version
40
+ expect(post.versions.count).to eq(2)
41
+ expect(post.versions.last[:object]).to include("status: 0")
42
+ expect(post.paper_trail.previous_version.status).to eq("draft")
47
43
  end
48
44
  end
49
45
  end
@@ -1,18 +1,15 @@
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
4
  # Some applications and libraries modify `current_user`. Their changes need
8
5
  # to be reflected in `whodunnit`, so the `set_paper_trail_whodunnit` below
9
6
  # must happen after this.
10
- send(name_of_before_callback, :modify_current_user)
7
+ before_action :modify_current_user
11
8
 
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)
9
+ # PT used to add this callback automatically. Now people are required to add
10
+ # it themsevles, like this, allowing them to control the order of callbacks.
11
+ # The `modify_current_user` callback above shows why this control is useful.
12
+ before_action :set_paper_trail_whodunnit
16
13
 
17
14
  def rescue_action(e)
18
15
  raise e
@@ -11,10 +11,6 @@ class ArticlesController < ApplicationController
11
11
  private
12
12
 
13
13
  def article_params
14
- if PaperTrail.active_record_protected_attributes?
15
- params[:article]
16
- else
17
- params.require(:article).permit!
18
- end
14
+ params.require(:article).permit!
19
15
  end
20
16
  end
@@ -23,10 +23,6 @@ class WidgetsController < ApplicationController
23
23
  private
24
24
 
25
25
  def widget_params
26
- if PaperTrail.active_record_protected_attributes?
27
- params[:widget]
28
- else
29
- params[:widget].permit!
30
- end
26
+ params[:widget].permit!
31
27
  end
32
28
  end
@@ -1,6 +1,4 @@
1
1
  class Animal < ActiveRecord::Base
2
2
  has_paper_trail
3
3
  self.inheritance_column = "species"
4
-
5
- attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
6
4
  end
@@ -1,4 +1,6 @@
1
1
  class Document < ActiveRecord::Base
2
- has_paper_trail versions: :paper_trail_versions,
3
- on: [:create, :update]
2
+ has_paper_trail(
3
+ versions: :paper_trail_versions,
4
+ on: [:create, :update]
5
+ )
4
6
  end
@@ -1,4 +1,3 @@
1
1
  class LegacyWidget < ActiveRecord::Base
2
- has_paper_trail ignore: :version,
3
- version: "custom_version"
2
+ has_paper_trail ignore: :version, version: "custom_version"
4
3
  end
@@ -1,8 +1,7 @@
1
+ # This model tests ActiveRecord::Enum, which was added in AR 4.1
2
+ # http://edgeguides.rubyonrails.org/4_1_release_notes.html#active-record-enums
1
3
  class PostWithStatus < ActiveRecord::Base
2
4
  has_paper_trail
3
5
 
4
- # ActiveRecord::Enum is only supported in AR4.1+
5
- if defined?(ActiveRecord::Enum)
6
- enum status: { draft: 0, published: 1, archived: 2 }
7
- end
6
+ enum status: { draft: 0, published: 1, archived: 2 }
8
7
  end
@@ -1,6 +1,3 @@
1
1
  class Skipper < ActiveRecord::Base
2
- has_paper_trail(
3
- ignore: [:created_at],
4
- skip: [:another_timestamp]
5
- )
2
+ has_paper_trail ignore: [:created_at], skip: [:another_timestamp]
6
3
  end
@@ -1,4 +1,6 @@
1
1
  class Translation < ActiveRecord::Base
2
- has_paper_trail if: proc { |t| t.language_code == "US" },
3
- unless: proc { |t| t.type == "DRAFT" }
2
+ has_paper_trail(
3
+ if: proc { |t| t.language_code == "US" },
4
+ unless: proc { |t| t.type == "DRAFT" }
5
+ )
4
6
  end
@@ -1,4 +1,4 @@
1
1
  class Vehicle < ActiveRecord::Base
2
2
  # This STI parent class specifically does not call `has_paper_trail`.
3
- # Of the sub-classes of `Vehicle`, only `Car` is versioned.
3
+ # Of its sub-classes, only `Car` is versioned.
4
4
  end
@@ -1,16 +1,8 @@
1
1
  class Widget < ActiveRecord::Base
2
+ EXCLUDED_NAME = "Biglet".freeze
2
3
  has_paper_trail
3
4
  has_one :wotsit
5
+ has_many :fluxors, -> { order(:name) }
4
6
  has_many :whatchamajiggers, as: :owner
5
-
6
- EXCLUDED_NAME = "Biglet".freeze
7
-
8
7
  validates :name, exclusion: { in: [EXCLUDED_NAME] }
9
-
10
- # `has_many` syntax for specifying order uses a lambda in Rails 4
11
- if ::ActiveRecord::VERSION::MAJOR >= 4
12
- has_many :fluxors, -> { order(:name) }
13
- else
14
- has_many :fluxors, order: :name
15
- end
16
8
  end
@@ -45,14 +45,6 @@ module Dummy
45
45
  # like if you have constraints or database-specific column types
46
46
  # config.active_record.schema_format = :sql
47
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
- if ::PaperTrail.active_record_protected_attributes?
53
- config.active_record.whitelist_attributes = false
54
- end
55
-
56
48
  # `config.assets` is a `NoMethodError` in rails 5.
57
49
  config.assets.enabled = false if config.respond_to?(:assets)
58
50
 
@@ -22,11 +22,6 @@ Dummy::Application.configure do
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
24
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- if ::PaperTrail.active_record_protected_attributes?
27
- config.active_record.mass_assignment_sanitizer = :strict
28
- end
29
-
30
25
  # Log the query plan for queries taking more than this (works
31
26
  # with SQLite, MySQL, and PostgreSQL)
32
27
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
@@ -41,11 +41,6 @@ Dummy::Application.configure do
41
41
  # ActionMailer::Base.deliveries array.
42
42
  # config.action_mailer.delivery_method = :test
43
43
 
44
- # Raise exception on mass assignment protection for Active Record models
45
- if ::PaperTrail.active_record_protected_attributes?
46
- config.active_record.mass_assignment_sanitizer = :strict
47
- end
48
-
49
44
  # Print deprecation notices to the stderr
50
45
  config.active_support.deprecation = :stderr
51
46
  end
@@ -1,9 +1 @@
1
1
  PaperTrail.config.track_associations = true
2
-
3
- module PaperTrail
4
- class Version < ActiveRecord::Base
5
- if ::PaperTrail.active_record_protected_attributes?
6
- attr_accessible :answer, :action, :question, :article_id, :ip, :user_agent, :title
7
- end
8
- end
9
- end
@@ -104,16 +104,7 @@ module CleanupCallbacks
104
104
  original_callbacks = nil
105
105
 
106
106
  setup do
107
- if ActiveRecord::VERSION::MAJOR > 3
108
- original_callbacks = target.send(:get_callbacks, type).deep_dup
109
- else
110
- # While this defeats the purpose of targeted callback
111
- # cleanup, callbacks were incredibly difficult to modify
112
- # prior to Rails 4, and Rails internal callbacks were only
113
- # used for autosaving associations in Rails 3. Our tests
114
- # don't care whether a Fluxor's widget is autosaved.
115
- target.reset_callbacks(type)
116
- end
107
+ original_callbacks = target.send(:get_callbacks, type).deep_dup
117
108
  end
118
109
 
119
110
  teardown do
@@ -678,39 +678,22 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
678
678
  end
679
679
  end
680
680
 
681
- context "Timestamps" do
682
- setup do
683
- @wotsit = Wotsit.create! name: "wotsit"
684
- end
685
-
686
- should "record timestamps" do
687
- @wotsit.update_attributes! name: "changed"
688
- assert_not_nil @wotsit.versions.last.reify.created_at
689
- assert_not_nil @wotsit.versions.last.reify.updated_at
690
- end
691
-
692
- # Tests that it doesn't try to write created_on as an attribute just because
693
- # a created_on method exists.
694
- #
695
- # - Deprecation warning in Rails 3.2
696
- # - ActiveModel::MissingAttributeError in Rails 4
697
- #
698
- # In rails 5, `capture` is deprecated in favor of `capture_io`.
699
- #
700
- should "not generate warning" do
701
- assert_update_raises_nothing = lambda {
702
- assert_nothing_raised {
703
- @wotsit.update_attributes! name: "changed"
704
- }
705
- }
706
- warnings =
707
- if respond_to?(:capture_io)
708
- capture_io { assert_update_raises_nothing.call }.last
709
- else
710
- capture(:stderr) { assert_update_raises_nothing.call }
711
- end
712
- assert_equal "", warnings
713
- end
681
+ test "update_attributes! records timestamps" do
682
+ wotsit = Wotsit.create! name: "wotsit"
683
+ wotsit.update_attributes! name: "changed"
684
+ reified = wotsit.versions.last.reify
685
+ assert_not_nil reified.created_at
686
+ assert_not_nil reified.updated_at
687
+ end
688
+
689
+ # Tests that it doesn't try to write created_on as an attribute just because
690
+ # a created_on method exists.
691
+ #
692
+ # - ActiveModel::MissingAttributeError in Rails 4
693
+ #
694
+ test "update_attributes! does not raise error" do
695
+ wotsit = Wotsit.create! name: "name1"
696
+ assert_nothing_raised { wotsit.update_attributes! name: "name2" }
714
697
  end
715
698
 
716
699
  context "A subclass" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
@@ -356,7 +356,6 @@ files:
356
356
  - test/dummy/app/controllers/articles_controller.rb
357
357
  - test/dummy/app/controllers/test_controller.rb
358
358
  - test/dummy/app/controllers/widgets_controller.rb
359
- - test/dummy/app/helpers/application_helper.rb
360
359
  - test/dummy/app/models/animal.rb
361
360
  - test/dummy/app/models/article.rb
362
361
  - test/dummy/app/models/authorship.rb
@@ -389,7 +388,6 @@ files:
389
388
  - test/dummy/app/models/person.rb
390
389
  - test/dummy/app/models/post.rb
391
390
  - test/dummy/app/models/post_with_status.rb
392
- - test/dummy/app/models/protected_widget.rb
393
391
  - test/dummy/app/models/quotation.rb
394
392
  - test/dummy/app/models/section.rb
395
393
  - test/dummy/app/models/skipper.rb
@@ -406,7 +404,6 @@ files:
406
404
  - test/dummy/app/versions/json_version.rb
407
405
  - test/dummy/app/versions/kitchen/banana_version.rb
408
406
  - test/dummy/app/versions/post_version.rb
409
- - test/dummy/app/views/layouts/application.html.erb
410
407
  - test/dummy/config.ru
411
408
  - test/dummy/config/application.rb
412
409
  - test/dummy/config/boot.rb
@@ -427,7 +424,6 @@ files:
427
424
  - test/dummy/config/routes.rb
428
425
  - test/dummy/db/migrate/20110208155312_set_up_test_tables.rb
429
426
  - test/dummy/db/schema.rb
430
- - test/dummy/script/rails
431
427
  - test/functional/controller_test.rb
432
428
  - test/functional/enabled_for_controller_test.rb
433
429
  - test/functional/modular_sinatra_test.rb
@@ -439,7 +435,6 @@ files:
439
435
  - test/unit/cleaner_test.rb
440
436
  - test/unit/inheritance_column_test.rb
441
437
  - test/unit/model_test.rb
442
- - test/unit/protected_attrs_test.rb
443
438
  - test/unit/serializer_test.rb
444
439
  - test/unit/serializers/json_test.rb
445
440
  - test/unit/serializers/mixin_json_test.rb
@@ -505,7 +500,6 @@ test_files:
505
500
  - test/dummy/app/controllers/articles_controller.rb
506
501
  - test/dummy/app/controllers/test_controller.rb
507
502
  - test/dummy/app/controllers/widgets_controller.rb
508
- - test/dummy/app/helpers/application_helper.rb
509
503
  - test/dummy/app/models/animal.rb
510
504
  - test/dummy/app/models/article.rb
511
505
  - test/dummy/app/models/authorship.rb
@@ -538,7 +532,6 @@ test_files:
538
532
  - test/dummy/app/models/person.rb
539
533
  - test/dummy/app/models/post.rb
540
534
  - test/dummy/app/models/post_with_status.rb
541
- - test/dummy/app/models/protected_widget.rb
542
535
  - test/dummy/app/models/quotation.rb
543
536
  - test/dummy/app/models/section.rb
544
537
  - test/dummy/app/models/skipper.rb
@@ -555,7 +548,6 @@ test_files:
555
548
  - test/dummy/app/versions/json_version.rb
556
549
  - test/dummy/app/versions/kitchen/banana_version.rb
557
550
  - test/dummy/app/versions/post_version.rb
558
- - test/dummy/app/views/layouts/application.html.erb
559
551
  - test/dummy/config.ru
560
552
  - test/dummy/config/application.rb
561
553
  - test/dummy/config/boot.rb
@@ -576,7 +568,6 @@ test_files:
576
568
  - test/dummy/config/routes.rb
577
569
  - test/dummy/db/migrate/20110208155312_set_up_test_tables.rb
578
570
  - test/dummy/db/schema.rb
579
- - test/dummy/script/rails
580
571
  - test/functional/controller_test.rb
581
572
  - test/functional/enabled_for_controller_test.rb
582
573
  - test/functional/modular_sinatra_test.rb
@@ -588,7 +579,6 @@ test_files:
588
579
  - test/unit/cleaner_test.rb
589
580
  - test/unit/inheritance_column_test.rb
590
581
  - test/unit/model_test.rb
591
- - test/unit/protected_attrs_test.rb
592
582
  - test/unit/serializer_test.rb
593
583
  - test/unit/serializers/json_test.rb
594
584
  - test/unit/serializers/mixin_json_test.rb
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,3 +0,0 @@
1
- class ProtectedWidget < Widget
2
- attr_accessible :name, :a_text if ::PaperTrail.active_record_protected_attributes?
3
- end
@@ -1,14 +0,0 @@
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>
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This command will automatically be run when you run "rails" with Rails 3 gems
4
- # installed from the root of your application.
5
-
6
- APP_PATH = File.expand_path("../../config/application", __FILE__)
7
- require File.expand_path("../../config/boot", __FILE__)
8
- require "rails/commands"
@@ -1,52 +0,0 @@
1
- require "test_helper"
2
-
3
- class ProtectedAttrsTest < ActiveSupport::TestCase
4
- subject { ProtectedWidget.new }
5
-
6
- # These ActiveModel matchers (provided by shoulda-matchers) only work for
7
- # Rails 3.
8
- if ActiveRecord::VERSION::MAJOR < 4
9
- accessible_attrs = ProtectedWidget.accessible_attributes.to_a
10
- accessible_attrs.each do |attr_name|
11
- should allow_mass_assignment_of(attr_name.to_sym)
12
- end
13
- inaccessible = ProtectedWidget.
14
- column_names.
15
- reject { |column_name| accessible_attrs.include?(column_name) }
16
- inaccessible.each do |attr_name|
17
- should_not allow_mass_assignment_of(attr_name.to_sym)
18
- end
19
- end
20
-
21
- context "A model with `attr_accessible` created" do
22
- setup do
23
- @widget = ProtectedWidget.create! name: "Henry"
24
- @initial_attributes = @widget.attributes
25
- end
26
-
27
- should "be `nil` in its previous version" do
28
- assert_nil @widget.paper_trail.previous_version
29
- end
30
-
31
- context "which is then updated" do
32
- setup do
33
- @widget.assign_attributes(name: "Jeff", a_text: "Short statement")
34
- @widget.an_integer = 42
35
- @widget.save!
36
- end
37
-
38
- should "not be `nil` in its previous version" do
39
- assert_not_nil @widget.paper_trail.previous_version
40
- end
41
-
42
- should "the previous version should contain right attributes" do
43
- # For some reason this test seems to be broken in JRuby 1.9 mode in the
44
- # test env even though it works in the console. WTF?
45
- unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION)
46
- previous_attributes = @widget.paper_trail.previous_version.attributes
47
- assert_attributes_equal previous_attributes, @initial_attributes
48
- end
49
- end
50
- end
51
- end
52
- end