close #365; VersionConcern#version_at should return nil if timestamp argument received is after the object was destroyed

This commit is contained in:
Ben Atkins 2014-06-18 11:01:38 -04:00
parent 8172c16c9c
commit 3323f21679
3 changed files with 19 additions and 1 deletions

View File

@ -4,6 +4,8 @@
- [#383](https://github.com/airblade/paper_trail/pull/383) - Make gem compatible with `ActiveRecord::Enum` (available in `ActiveRecord` 4.1+).
- [#373](https://github.com/airblade/paper_trail/pull/373) - Fix default sort order for the `versions` association in `ActiveRecord` 4.1.
- [#372](https://github.com/airblade/paper_trail/pull/372) - Use [Arel](https://github.com/rails/arel) for SQL construction.
- [#365](https://github.com/airblade/paper_trail/issues/365) - `VersionConcern#version_at` should return `nil` when receiving a timestamp
that occured after the object was destroyed.
- [#347](https://github.com/airblade/paper_trail/pull/347) - Autoload `ActiveRecord` models in via a `Rails::Engine` when
the gem is used with `Rails`.
- Expand `PaperTrail::VERSION` into a module, mimicking the form used by Rails to give it some additional modularity & versatility.

View File

@ -182,7 +182,8 @@ module PaperTrail
# Because a version stores how its object looked *before* the change,
# we need to look for the first version created *after* the timestamp.
v = send(self.class.versions_association_name).subsequent(timestamp, true).first
v ? v.reify(reify_options) : self
return v.reify(reify_options) if v
self unless self.destroyed?
end
# Returns the objects (not Versions) as they were between the given times.

View File

@ -105,6 +105,21 @@ describe Widget do
end
end
describe :version_at do
it { should respond_to(:version_at) }
context "Timestamp argument is AFTER object has been destroyed" do
before do
widget.update_attribute(:name, 'foobar')
widget.destroy
end
it "should return `nil`" do
widget.version_at(Time.now).should be_nil
end
end
end
describe :whodunnit do
it { should respond_to(:whodunnit) }