From eb01ca30c6892c3676b6387831dae2e199aa32ad Mon Sep 17 00:00:00 2001 From: Ben Atkins Date: Thu, 17 Oct 2013 14:46:06 -0400 Subject: [PATCH] Change all scope declarations to use class method syntax on the Version class. close #288 --- CHANGELOG.md | 2 ++ lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version.rb | 13 +++++++------ test/dummy/config/environments/development.rb | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9c8d74e..af8ebfef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 7c9da076..50fb1ef1 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -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 diff --git a/lib/paper_trail/version.rb b/lib/paper_trail/version.rb index 95b5b624..913b7a6b 100644 --- a/lib/paper_trail/version.rb +++ b/lib/paper_trail/version.rb @@ -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. # diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index aaa51205..d39f834e 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -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