paper_trail 3.0.7 → 3.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6b8b27c90bfd64f2b38cef59276076e4123f38b
4
- data.tar.gz: 02bc459e5c9ae9e74eafdc782eee7cb4708cfb3e
3
+ metadata.gz: de205e84196241d1165f38050f43114114b47cca
4
+ data.tar.gz: 2401292c3098d9050260528490556294f8034a6d
5
5
  SHA512:
6
- metadata.gz: c0581395fd0a5782e279133c26ff723a62eda27470ecd57660d3b495c55ef542a9d08b99a5701762f585fefed54a5191c367469031a1a00cb2efede10690a7b8
7
- data.tar.gz: e12d54c3a6c00dfa21d2634ee6b2561bbf1aba2bbc907e82f0a651b12acf35a391c6ca81a0e589feca9e0c502efbdc052b5b2e18010e44a3a9ea60c7ec99b8fe
6
+ metadata.gz: 89b14153e1f66e8e043532c78a6cda7033e2aa902c9d191fddc29ece1a4036c9808c26e345ca3360d4c70f6d1193eac14eb5884025a45750361419e290217d2f
7
+ data.tar.gz: 531199dd212d76562c9baed8033fd3ca765b5458b19c3b8029e89c8cd3f7a44202cdcb5efd3ad979022c5e4386e47e042fab2617470134a52d3ee6b328779f65
data/CHANGELOG.md CHANGED
@@ -1,18 +1,32 @@
1
+ ## 3.0.9
2
+
3
+ - [#479](https://github.com/airblade/paper_trail/issues/479) - Deprecated `originator` method in favor of
4
+ `paper_trail_originator` Deprecation warning informs users that the `originator` of the methods will be
5
+ removed in version `4.0`. (Backported from v4)
6
+ - Updated deprecation warnings for `Model.paper_trail_on` and `Model.paper_trail_off` to have display correct
7
+ version number the methods will be removed (`4.0`)
8
+
9
+ ## 3.0.8
10
+
11
+ - [#525](https://github.com/airblade/paper_trail/issues/525) / [#512](https://github.com/airblade/paper_trail/pull/512) -
12
+ Support for virtual accessors and redefined setter and getter methods. (Backported from v4)
13
+
1
14
  ## 3.0.7
2
15
 
3
16
  - [#404](https://github.com/airblade/paper_trail/issues/404) / [#428](https://github.com/airblade/paper_trail/issues/428) -
4
- Fix errors occuring when a user attempts to update the inheritance column on an STI model instance in `ActiveRecord` 4.1.x
17
+ Fix errors occuring when a user attempts to update the inheritance column on an STI model instance in `ActiveRecord` 4.1.x.
18
+ (Backported from v4)
5
19
 
6
20
  ## 3.0.6
7
21
 
8
22
  - [#414](https://github.com/airblade/paper_trail/issues/414) - Fix functionality `ignore` argument to `has_paper_trail`
9
- in `ActiveRecord` 4
23
+ in `ActiveRecord` 4. (Backported from v4)
10
24
 
11
25
  ## 3.0.5
12
26
 
13
27
  - [#401](https://github.com/airblade/paper_trail/issues/401) / [#406](https://github.com/airblade/paper_trail/issues/406) -
14
28
  `PaperTrail::Version` class is not loaded via a `Rails::Engine`, even when the gem is used with in Rails. This feature has
15
- will be re-introduced in version `3.1.0`.
29
+ will be re-introduced in version `4.0`.
16
30
  - [#398](https://github.com/airblade/paper_trail/pull/398) - Only require the `RSpec` helper if `RSpec::Core` is required.
17
31
 
18
32
  ## 3.0.3
@@ -57,7 +71,7 @@ in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is use
57
71
  with Rails `4.1.0.rc1`.
58
72
  - [#334](https://github.com/airblade/paper_trail/pull/334) - Add small-scope `whodunnit` method to `PaperTrail::Model::InstanceMethods`.
59
73
  - [#329](https://github.com/airblade/paper_trail/issues/329) - Add `touch_with_version` method to `PaperTrail::Model::InstanceMethods`,
60
- to allow for generating a version `touch`ing a model.
74
+ to allow for generating a version while `touch`ing a model.
61
75
  - [#328](https://github.com/airblade/paper_trail/pull/328) / [#326](https://github.com/airblade/paper_trail/issues/326) /
62
76
  [#307](https://github.com/airblade/paper_trail/issues/307) - `Model.paper_trail_enabled_for_model?` and
63
77
  `model_instance.without_versioning` is now thread-safe.
@@ -68,8 +82,8 @@ in the `PaperTrail::Version` class through a `Rails::Engine` when the gem is use
68
82
  - [#312](https://github.com/airblade/paper_trail/issues/312) - Fix RSpec `with_versioning` class level helper method.
69
83
  - `model_instance.without_versioning` now yields the `model_instance`, enabling syntax like this:
70
84
  `model_instance.without_versioning { |obj| obj.update_attributes(:name => 'value') }`.
71
- - Deprecated `Model.paper_trail_on` and `Model.paper_trail_off` in favor of bang versions of the methods. Deprecation warning
72
- informs users that the non-bang versions of the methods will be removed in version `3.1.0`.
85
+ - Deprecated `Model.paper_trail_on` and `Model.paper_trail_off` in favor of bang versions of the methods.
86
+ Deprecation warning informs users that the non-bang versions of the methods will be removed in version `4.0`
73
87
 
74
88
  ## 3.0.0
75
89
 
data/README.md CHANGED
@@ -42,7 +42,7 @@ The Rails 2.3 code is on the [`rails2`](https://github.com/airblade/paper_trail/
42
42
 
43
43
  1. Add PaperTrail to your `Gemfile`.
44
44
 
45
- `gem 'paper_trail', '~> 3.0.7'`
45
+ `gem 'paper_trail', '~> 3.0.9'`
46
46
 
47
47
  2. Generate a migration which will add a `versions` table to your database.
48
48
 
@@ -64,7 +64,7 @@ your applications `ActiveRecord` connection in a manner similar to the way `Rail
64
64
 
65
65
  1. Add PaperTrail to your `Gemfile`.
66
66
 
67
- `gem 'paper_trail', '~> 3.0.7'`
67
+ `gem 'paper_trail', '~> 3.0.9'`
68
68
 
69
69
  2. Generate a migration to add a `versions` table to your database.
70
70
 
@@ -115,7 +115,7 @@ widget.version
115
115
  widget.live?
116
116
 
117
117
  # Returns who put the widget into its current state.
118
- widget.originator
118
+ widget.paper_trail_originator
119
119
 
120
120
  # Returns the widget (not a version) as it looked at the given timestamp.
121
121
  widget.version_at(timestamp)
@@ -147,7 +147,7 @@ And a `PaperTrail::Version` instance has these methods:
147
147
  version.reify(options = {})
148
148
 
149
149
  # Returns who put the item into the state stored in this version.
150
- version.originator
150
+ version.paper_trail_originator
151
151
 
152
152
  # Returns who changed the item from the state it had in this version.
153
153
  version.terminator
@@ -504,22 +504,22 @@ Sometimes you want to define who is responsible for a change in a small scope wi
504
504
 
505
505
  A version's `whodunnit` records who changed the object causing the `version` to be stored. Because a version stores the object as it looked before the change (see the table above), `whodunnit` returns who stopped the object looking like this -- not who made it look like this. Hence `whodunnit` is aliased as `terminator`.
506
506
 
507
- To find out who made a version's object look that way, use `version.originator`. And to find out who made a "live" object look like it does, use `originator` on the object.
507
+ To find out who made a version's object look that way, use `version.paper_trail_originator`. And to find out who made a "live" object look like it does, call `paper_trail_originator` on the object.
508
508
 
509
509
  ```ruby
510
510
  >> widget = Widget.find 153 # assume widget has 0 versions
511
511
  >> PaperTrail.whodunnit = 'Alice'
512
512
  >> widget.update_attributes :name => 'Yankee'
513
- >> widget.originator # 'Alice'
513
+ >> widget..paper_trail_originator # 'Alice'
514
514
  >> PaperTrail.whodunnit = 'Bob'
515
515
  >> widget.update_attributes :name => 'Zulu'
516
- >> widget.originator # 'Bob'
516
+ >> widget.paper_trail_originator # 'Bob'
517
517
  >> first_version, last_version = widget.versions.first, widget.versions.last
518
518
  >> first_version.whodunnit # 'Alice'
519
- >> first_version.originator # nil
519
+ >> first_version.paper_trail_originator # nil
520
520
  >> first_version.terminator # 'Alice'
521
521
  >> last_version.whodunnit # 'Bob'
522
- >> last_version.originator # 'Alice'
522
+ >> last_version.paper_trail_originator # 'Alice'
523
523
  >> last_version.terminator # 'Bob'
524
524
  ```
525
525
 
data/gemfiles/3.0.gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.0'
4
+ gem 'i18n', '~> 0.6.11'
4
5
 
5
6
  group :development, :test do
6
7
  gem 'rake', '~> 10.1.1'
7
8
  gem 'shoulda', '~> 3.5'
8
- gem 'ffaker', '>= 1.15'
9
+ gem 'ffaker', '<= 1.31.0'
9
10
 
10
11
  # Testing of Rails
11
12
  gem 'railties', '~> 3.0'
@@ -24,7 +25,7 @@ group :development, :test do
24
25
  platforms :ruby do
25
26
  gem 'sqlite3', '~> 1.2'
26
27
  gem 'mysql2', '~> 0.3'
27
- gem 'pg', '~> 0.17'
28
+ gem 'pg', '~> 0.17.1'
28
29
  end
29
30
 
30
31
  platforms :jruby, :ruby_18 do
@@ -38,5 +39,6 @@ group :development, :test do
38
39
  gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
39
40
  gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
40
41
  gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
42
+ gem 'activerecord-jdbc-adapter', '1.3.15'
41
43
  end
42
44
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object' # provides the `try` method
2
+
1
3
  module PaperTrail
2
4
  module Model
3
5
 
@@ -86,7 +88,7 @@ module PaperTrail
86
88
  end
87
89
 
88
90
  def paper_trail_off
89
- warn "DEPRECATED: use `paper_trail_off!` instead of `paper_trail_off`. Support for `paper_trail_off` will be removed in PaperTrail 3.1"
91
+ warn "DEPRECATED: use `paper_trail_off!` instead of `paper_trail_off`. Support for `paper_trail_off` will be removed in PaperTrail 4.0"
90
92
  self.paper_trail_off!
91
93
  end
92
94
 
@@ -96,7 +98,7 @@ module PaperTrail
96
98
  end
97
99
 
98
100
  def paper_trail_on
99
- warn "DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1"
101
+ warn "DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 4.0"
100
102
  self.paper_trail_on!
101
103
  end
102
104
 
@@ -173,10 +175,15 @@ module PaperTrail
173
175
  end
174
176
 
175
177
  # Returns who put the object into its current state.
176
- def originator
178
+ def paper_trail_originator
177
179
  (source_version || send(self.class.versions_association_name).last).try(:whodunnit)
178
180
  end
179
181
 
182
+ def originator
183
+ warn "DEPRECATED: use `paper_trail_originator` instead of `originator`. Support for `originator` will be removed in PaperTrail 4.0"
184
+ self.paper_trail_originator
185
+ end
186
+
180
187
  # Returns the object (not a Version) as it was at the given timestamp.
181
188
  def version_at(timestamp, reify_options={})
182
189
  # Because a version stores how its object looked *before* the change,
@@ -148,8 +148,10 @@ module PaperTrail
148
148
 
149
149
  # Set all the attributes in this version on the model
150
150
  attrs.each do |k, v|
151
- if model.respond_to?("#{k}=")
151
+ if model.has_attribute?(k)
152
152
  model[k.to_sym] = v
153
+ elsif model.respond_to?("#{k}=")
154
+ model.send("#{k}=", v)
153
155
  else
154
156
  logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
155
157
  end
@@ -179,8 +181,13 @@ module PaperTrail
179
181
  end
180
182
 
181
183
  # Returns who put the item into the state stored in this version.
184
+ def paper_trail_originator
185
+ @paper_trail_originator ||= previous.whodunnit rescue nil
186
+ end
187
+
182
188
  def originator
183
- @originator ||= previous.whodunnit rescue nil
189
+ warn "DEPRECATED: use `paper_trail_originator` instead of `originator`. Support for `originator` will be removed in PaperTrail 4.0"
190
+ self.paper_trail_originator
184
191
  end
185
192
 
186
193
  # Returns who changed the item from the state it had in this version.
@@ -2,7 +2,7 @@ module PaperTrail
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 9
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/paper_trail.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'rake', '~> 10.1.1'
26
26
  s.add_development_dependency 'shoulda', '~> 3.5'
27
27
  # s.add_development_dependency 'shoulda-matchers', '~> 1.5' # needed for ActiveRecord < 4
28
- s.add_development_dependency 'ffaker', '>= 1.15'
28
+ s.add_development_dependency 'ffaker', '<= 1.31.0'
29
29
  s.add_development_dependency 'railties', ['>= 3.0', '< 5.0']
30
30
  s.add_development_dependency 'sinatra', '~> 1.0'
31
31
  s.add_development_dependency 'rack-test', '>= 0.6'
@@ -22,13 +22,60 @@ describe PaperTrail::Version do
22
22
  describe "Instance" do
23
23
  subject { PaperTrail::Version.new(attributes) rescue PaperTrail::Version.new }
24
24
 
25
- describe :terminator do
25
+ describe '#paper_trail_originator' do
26
+ it { is_expected.to respond_to(:paper_trail_originator) }
27
+
28
+ context "No previous versions" do
29
+ specify { expect(subject.previous).to be_nil }
30
+
31
+ it "should return nil" do
32
+ expect(subject.paper_trail_originator).to be_nil
33
+ end
34
+ end
35
+
36
+ context "Has previous version", :versioning => true do
37
+ let(:name) { Faker::Name.name }
38
+ let(:widget) { Widget.create!(:name => Faker::Name.name) }
39
+ before do
40
+ widget.versions.first.update_attributes!(:whodunnit => name)
41
+ widget.update_attributes!(:name => Faker::Name.first_name)
42
+ end
43
+ subject { widget.versions.last }
44
+
45
+ specify { expect(subject.previous).to be_instance_of(PaperTrail::Version) }
46
+
47
+ it "should return nil" do
48
+ expect(subject.paper_trail_originator).to eq(name)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#originator" do
54
+ it { is_expected.to respond_to(:originator) }
55
+ let(:warning_msg) do
56
+ "DEPRECATED: use `paper_trail_originator` instead of `originator`." +
57
+ " Support for `originator` will be removed in PaperTrail 4.0"
58
+ end
59
+
60
+ it 'should set the invoke `paper_trail_originator`' do
61
+ is_expected.to receive(:warn)
62
+ is_expected.to receive(:paper_trail_originator)
63
+ subject.originator
64
+ end
65
+
66
+ it 'should display a deprecation warning' do
67
+ is_expected.to receive(:warn).with(warning_msg)
68
+ subject.originator
69
+ end
70
+ end
71
+
72
+ describe '#terminator' do
26
73
  it { should respond_to(:terminator) }
27
74
 
28
75
  let(:attributes) { {:whodunnit => Faker::Name.first_name} }
29
76
 
30
77
  it "is an alias for the `whodunnit` attribute" do
31
- subject.whodunnit.should == attributes[:whodunnit]
78
+ subject.terminator.should == attributes[:whodunnit]
32
79
  end
33
80
  end
34
81
 
@@ -72,8 +72,8 @@ describe Widget do
72
72
 
73
73
  describe "Methods" do
74
74
  describe "Instance", :versioning => true do
75
- describe :originator do
76
- it { should respond_to(:originator) }
75
+ describe '#paper_trail_originator' do
76
+ it { should respond_to(:paper_trail_originator) }
77
77
 
78
78
  describe "return value" do
79
79
  let(:orig_name) { Faker::Name.name }
@@ -84,9 +84,9 @@ describe Widget do
84
84
  specify { widget.should be_live }
85
85
 
86
86
  it "should return the originator for the model at a given state" do
87
- widget.originator.should == orig_name
87
+ widget.paper_trail_originator.should == orig_name
88
88
  widget.whodunnit(new_name) { |w| w.update_attributes(:name => 'Elizabeth') }
89
- widget.originator.should == new_name
89
+ widget.paper_trail_originator.should == new_name
90
90
  end
91
91
  end
92
92
 
@@ -99,13 +99,34 @@ describe Widget do
99
99
  let(:reified_widget) { widget.versions[1].reify }
100
100
 
101
101
  it "should return the appropriate originator" do
102
- reified_widget.originator.should == orig_name
102
+ reified_widget.paper_trail_originator.should == orig_name
103
103
  end
104
104
  end
105
105
  end
106
106
  end
107
107
 
108
- describe :version_at do
108
+ describe "#originator" do
109
+ subject { widget }
110
+
111
+ it { is_expected.to respond_to(:originator) }
112
+ let(:warning_msg) do
113
+ "DEPRECATED: use `paper_trail_originator` instead of `originator`." +
114
+ " Support for `originator` will be removed in PaperTrail 4.0"
115
+ end
116
+
117
+ it 'should set the invoke `paper_trail_originator`' do
118
+ is_expected.to receive(:warn)
119
+ is_expected.to receive(:paper_trail_originator)
120
+ subject.originator
121
+ end
122
+
123
+ it 'should display a deprecation warning' do
124
+ is_expected.to receive(:warn).with(warning_msg)
125
+ subject.originator
126
+ end
127
+ end
128
+
129
+ describe '#version_at' do
109
130
  it { should respond_to(:version_at) }
110
131
 
111
132
  context "Timestamp argument is AFTER object has been destroyed" do
@@ -200,7 +221,7 @@ describe Widget do
200
221
  end
201
222
 
202
223
  it 'should display a deprecation warning' do
203
- subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
224
+ subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 4.0")
204
225
  subject.paper_trail_on
205
226
  end
206
227
  end
@@ -229,7 +250,7 @@ describe Widget do
229
250
  end
230
251
 
231
252
  it 'should display a deprecation warning' do
232
- subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
253
+ subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 4.0")
233
254
  subject.paper_trail_on
234
255
  end
235
256
  end
@@ -15,12 +15,22 @@ class Person < ActiveRecord::Base
15
15
 
16
16
  # Store TimeZone objects as strings when serialized to database
17
17
  class TimeZoneSerializer
18
+ class << self
19
+ def dump(zone)
20
+ zone.try(:name)
21
+ end
22
+
23
+ def load(value)
24
+ ::Time.find_zone!(value) rescue nil
25
+ end
26
+ end
27
+
18
28
  def dump(zone)
19
- zone.try(:name)
29
+ self.class.dump(zone)
20
30
  end
21
-
31
+
22
32
  def load(value)
23
- ::Time.find_zone!(value) rescue nil
33
+ self.class.load(value)
24
34
  end
25
35
  end
26
36
 
@@ -1,6 +1,7 @@
1
1
  # Example from 'Overwriting default accessors' in ActiveRecord::Base.
2
2
  class Song < ActiveRecord::Base
3
3
  has_paper_trail
4
+ attr_accessor :name
4
5
 
5
6
  # Uses an integer of seconds to hold the length of the song
6
7
  def length=(minutes)
@@ -9,4 +10,23 @@ class Song < ActiveRecord::Base
9
10
  def length
10
11
  read_attribute(:length) / 60
11
12
  end
13
+
14
+ # override attributes hashes like some libraries do
15
+ def attributes_with_name
16
+ if name
17
+ attributes_without_name.merge(:name => name)
18
+ else
19
+ attributes_without_name
20
+ end
21
+ end
22
+ alias_method_chain :attributes, :name
23
+
24
+ def changed_attributes_with_name
25
+ if name
26
+ changed_attributes_without_name.merge(:name => name)
27
+ else
28
+ changed_attributes_without_name
29
+ end
30
+ end
31
+ alias_method_chain :changed_attributes, :name
12
32
  end
@@ -59,5 +59,8 @@ module Dummy
59
59
 
60
60
  # Rails 4 key for generating secret key
61
61
  config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
62
+
63
+ # supress warnings about raises in transactional callbacks on AR 4.2+
64
+ config.active_record.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING >= '4.2'
62
65
  end
63
66
  end
@@ -567,9 +567,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
567
567
 
568
568
  should 'track who made the change' do
569
569
  assert_equal 'Alice', @version.whodunnit
570
- assert_nil @version.originator
570
+ assert_nil @version.paper_trail_originator
571
571
  assert_equal 'Alice', @version.terminator
572
- assert_equal 'Alice', @widget.originator
572
+ assert_equal 'Alice', @widget.paper_trail_originator
573
573
  end
574
574
 
575
575
  context 'when a record is updated' do
@@ -581,9 +581,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
581
581
 
582
582
  should 'track who made the change' do
583
583
  assert_equal 'Bob', @version.whodunnit
584
- assert_equal 'Alice', @version.originator
584
+ assert_equal 'Alice', @version.paper_trail_originator
585
585
  assert_equal 'Bob', @version.terminator
586
- assert_equal 'Bob', @widget.originator
586
+ assert_equal 'Bob', @widget.paper_trail_originator
587
587
  end
588
588
 
589
589
  context 'when a record is destroyed' do
@@ -595,9 +595,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
595
595
 
596
596
  should 'track who made the change' do
597
597
  assert_equal 'Charlie', @version.whodunnit
598
- assert_equal 'Bob', @version.originator
598
+ assert_equal 'Bob', @version.paper_trail_originator
599
599
  assert_equal 'Charlie', @version.terminator
600
- assert_equal 'Charlie', @widget.originator
600
+ assert_equal 'Charlie', @widget.paper_trail_originator
601
601
  end
602
602
  end
603
603
  end
@@ -616,15 +616,18 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
616
616
  assert_not_nil @wotsit.versions.last.reify.updated_at
617
617
  end
618
618
 
619
- should 'not generate warning' do
620
- # Tests that it doesn't try to write created_on as an attribute just because a created_on
621
- # method exists.
622
- warnings = capture(:stderr) { # Deprecation warning in Rails 3.2
623
- assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4
624
- @wotsit.update_attributes! :name => 'changed'
619
+ # Currently the gem generates a bunch of deprecation warnings about serialized attributes on AR 4.2
620
+ if ActiveRecord::VERSION::STRING < '4.2'
621
+ should 'not generate warning' do
622
+ # Tests that it doesn't try to write created_on as an attribute just because a created_on
623
+ # method exists.
624
+ warnings = capture(:stderr) { # Deprecation warning in Rails 3.2
625
+ assert_nothing_raised { # ActiveModel::MissingAttributeError in Rails 4
626
+ @wotsit.update_attributes! :name => 'changed'
627
+ }
625
628
  }
626
- }
627
- assert_equal '', warnings
629
+ assert_equal '', warnings
630
+ end
628
631
  end
629
632
 
630
633
  end
@@ -646,7 +649,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
646
649
  should 'should return the correct originator' do
647
650
  PaperTrail.whodunnit = 'Ben'
648
651
  @foo.update_attribute(:name, 'Geoffrey')
649
- assert_equal PaperTrail.whodunnit, @foo.originator
652
+ assert_equal PaperTrail.whodunnit, @foo.paper_trail_originator
650
653
  end
651
654
 
652
655
  context 'when destroyed' do
@@ -1052,12 +1055,14 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1052
1055
  should 'version.object_changes attribute should have stored the value returned by the attribute serializer' do
1053
1056
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object_changes)]
1054
1057
  assert_equal [nil, 'Samoa'], as_stored_in_version[:time_zone]
1055
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].serialized_value, as_stored_in_version[:time_zone].last
1058
+ serialized_value = Person::TimeZoneSerializer.dump(@person.time_zone)
1059
+ assert_equal serialized_value, as_stored_in_version[:time_zone].last
1056
1060
  end
1057
1061
 
1058
1062
  # Tests for unserialization:
1059
1063
  should 'version.changeset should convert the attribute value back to its original, unserialized value' do
1060
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].unserialized_value, @person.versions.last.changeset[:time_zone].last
1064
+ unserialized_value = Person::TimeZoneSerializer.load(@person.time_zone)
1065
+ assert_equal unserialized_value, @person.versions.last.changeset[:time_zone].last
1061
1066
  end
1062
1067
  should "record.changes (before save) returns the original, unserialized values" do
1063
1068
  assert_equal [NilClass, ActiveSupport::TimeZone], @changes_before_save[:time_zone].map(&:class)
@@ -1069,7 +1074,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1069
1074
 
1070
1075
  context 'when that attribute is updated' do
1071
1076
  setup do
1072
- @attribute_value_before_change = @person.instance_variable_get(:@attributes)['time_zone']
1077
+ @attribute_value_before_change = @person.time_zone
1073
1078
  @person.assign_attributes({ :time_zone => 'Pacific Time (US & Canada)' })
1074
1079
  @changes_before_save = @person.changes.dup
1075
1080
  @person.save!
@@ -1078,7 +1083,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1078
1083
  # Tests for serialization:
1079
1084
  # Before the serialized attributes fix, the object/object_changes value that was stored was ridiculously long (58723).
1080
1085
  should 'version.object should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do
1081
- assert @person.versions.last.object. length < 105, "object length was #{@person.versions.last.object .length}"
1086
+ assert @person.versions.last.object.length < 105, "object length was #{@person.versions.last.object.length}"
1082
1087
  end
1083
1088
  # Need an additional clause to detect what version of ActiveRecord is being used for this test because AR4 injects the `updated_at` column into the changeset for updates to models
1084
1089
  should 'version.object_changes should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do
@@ -1088,20 +1093,24 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1088
1093
  should 'version.object attribute should have stored the value returned by the attribute serializer' do
1089
1094
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object)]
1090
1095
  assert_equal 'Samoa', as_stored_in_version[:time_zone]
1091
- assert_equal @attribute_value_before_change.serialized_value, as_stored_in_version[:time_zone]
1096
+ serialized_value = Person::TimeZoneSerializer.dump(@attribute_value_before_change)
1097
+ assert_equal serialized_value, as_stored_in_version[:time_zone]
1092
1098
  end
1093
1099
  should 'version.object_changes attribute should have stored the value returned by the attribute serializer' do
1094
1100
  as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object_changes)]
1095
1101
  assert_equal ['Samoa', 'Pacific Time (US & Canada)'], as_stored_in_version[:time_zone]
1096
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].serialized_value, as_stored_in_version[:time_zone].last
1102
+ serialized_value = Person::TimeZoneSerializer.dump(@person.time_zone)
1103
+ assert_equal serialized_value, as_stored_in_version[:time_zone].last
1097
1104
  end
1098
1105
 
1099
1106
  # Tests for unserialization:
1100
1107
  should 'version.reify should convert the attribute value back to its original, unserialized value' do
1101
- assert_equal @attribute_value_before_change.unserialized_value, @person.versions.last.reify.time_zone
1108
+ unserialized_value = Person::TimeZoneSerializer.load(@attribute_value_before_change)
1109
+ assert_equal unserialized_value, @person.versions.last.reify.time_zone
1102
1110
  end
1103
1111
  should 'version.changeset should convert the attribute value back to its original, unserialized value' do
1104
- assert_equal @person.instance_variable_get(:@attributes)['time_zone'].unserialized_value, @person.versions.last.changeset[:time_zone].last
1112
+ unserialized_value = Person::TimeZoneSerializer.load(@person.time_zone)
1113
+ assert_equal unserialized_value, @person.versions.last.changeset[:time_zone].last
1105
1114
  end
1106
1115
  should "record.changes (before save) returns the original, unserialized values" do
1107
1116
  assert_equal [ActiveSupport::TimeZone, ActiveSupport::TimeZone], @changes_before_save[:time_zone].map(&:class)
@@ -1165,6 +1174,21 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
1165
1174
  should 'return "overwritten" value on reified instance' do
1166
1175
  assert_equal 4, @song.versions.last.reify.length
1167
1176
  end
1177
+
1178
+ context 'Has a virtual attribute injected into the ActiveModel::Dirty changes' do
1179
+ setup do
1180
+ @song.name = 'Good Vibrations'
1181
+ @song.save
1182
+ @song.name = nil
1183
+ end
1184
+
1185
+ should 'return persist the changes on the live instance properly' do
1186
+ assert_equal nil, @song.name
1187
+ end
1188
+ should 'return "overwritten" virtual attribute on the reified instance' do
1189
+ assert_equal 'Good Vibrations', @song.versions.last.reify.name
1190
+ end
1191
+ end
1168
1192
  end
1169
1193
 
1170
1194