Change all scope declarations to use class method syntax on the Version class. close #288

This commit is contained in:
Ben Atkins 2013-10-17 14:46:06 -04:00
parent a7e11f6fe9
commit eb01ca30c6
4 changed files with 11 additions and 8 deletions

View File

@ -1,5 +1,7 @@
## 3.0.0 (Unreleased)
- [#288](https://github.com/airblade/paper_trail/issues/288) - Change all scope declarations to class methods on the `PaperTrail::Version`
class. Fixes usability when `PaperTrail::Version.abstract_class? == true`.
- [#281](https://github.com/airblade/paper_trail/issues/281) - `Rails::Controller` helper will return `false` for the
`paper_trail_enabled_for_controller` method if `PaperTrail.enabled? == false`.
- [#280](https://github.com/airblade/paper_trail/pull/280) - Don't track virtual timestamp attributes.

View File

@ -69,7 +69,7 @@ module PaperTrail
:class_name => self.version_class_name, :as => :item
else
has_many self.versions_association_name,
:class_name => version_class_name,
:class_name => self.version_class_name,
:as => :item,
:order => "#{PaperTrail.timestamp_field} ASC"
end

View File

@ -27,19 +27,20 @@ module PaperTrail
end
# These methods accept a timestamp or a version and returns other versions that come before or after
scope :subsequent, lambda { |obj|
def self.subsequent(obj)
obj = obj.send(PaperTrail.timestamp_field) if obj.is_a?(self)
where("#{PaperTrail.timestamp_field} > ?", obj).order("#{PaperTrail.timestamp_field} ASC")
}
scope :preceding, lambda { |obj|
end
def self.preceding(obj)
obj = obj.send(PaperTrail.timestamp_field) if obj.is_a?(self)
where("#{PaperTrail.timestamp_field} < ?", obj).order("#{PaperTrail.timestamp_field} DESC")
}
end
scope :between, lambda { |start_time, end_time|
def self.between(start_time, end_time)
where("#{PaperTrail.timestamp_field} > ? AND #{PaperTrail.timestamp_field} < ?", start_time, end_time).
order("#{PaperTrail.timestamp_field} ASC")
}
end
# Restore the item from this version.
#

View File

@ -27,7 +27,7 @@ Dummy::Application.configure do
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false