paper_trail 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ NOTES
1
2
  test/debug.log
2
3
  test/paper_trail_plugin.sqlite3.db
3
4
  test/dummy/db/*.sqlite3
data/README.md CHANGED
@@ -717,6 +717,8 @@ Many thanks to:
717
717
  * [Nikita Cernovs](https://github.com/nikitachernov)
718
718
  * [Jason Noble](https://github.com/jasonnoble)
719
719
  * [Jared Mehle](https://github.com/jrmehle)
720
+ * [Eric Schwartz](https://github.com/emschwar)
721
+
720
722
 
721
723
 
722
724
  ## Inspirations
@@ -108,6 +108,12 @@ module PaperTrail
108
108
  v ? v.reify(reify_options) : self
109
109
  end
110
110
 
111
+ # Returns the objects (not Versions) as they were between the given times.
112
+ def versions_between(start_time, end_time, reify_options={})
113
+ versions = send(self.class.versions_association_name).between(start_time, end_time)
114
+ versions.collect { |version| version_at(version.send PaperTrail.timestamp_field) }
115
+ end
116
+
111
117
  # Returns the object (not a Version) as it was most recently.
112
118
  def previous_version
113
119
  preceding_version = source_version ? source_version.previous : send(self.class.versions_association_name).last
@@ -17,7 +17,13 @@ class Version < ActiveRecord::Base
17
17
 
18
18
  scope :following, lambda { |timestamp|
19
19
  # TODO: is this :order necessary, considering its presence on the has_many :versions association?
20
- where(["#{PaperTrail.timestamp_field} > ?", timestamp]).order("#{PaperTrail.timestamp_field} ASC, #{self.primary_key} ASC")
20
+ where(["#{PaperTrail.timestamp_field} > ?", timestamp]).
21
+ order("#{PaperTrail.timestamp_field} ASC, #{self.primary_key} ASC")
22
+ }
23
+
24
+ scope :between, lambda { |start_time, end_time|
25
+ where(["#{PaperTrail.timestamp_field} > ? AND #{PaperTrail.timestamp_field} < ?", start_time, end_time ]).
26
+ order("#{PaperTrail.timestamp_field} ASC, #{self.primary_key} ASC")
21
27
  }
22
28
 
23
29
  # Restore the item from this version.
@@ -1,3 +1,3 @@
1
1
  module PaperTrail
2
- VERSION = '2.6.1'
2
+ VERSION = '2.6.2'
3
3
  end
@@ -576,6 +576,24 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
576
576
  end
577
577
  end
578
578
 
579
+ context '.versions_between' do
580
+ setup do
581
+ @created = 30.days.ago
582
+ @first_update = 15.days.ago
583
+ @second_update = 1.day.ago
584
+ @widget.versions[0].update_attributes :created_at => @created
585
+ @widget.versions[1].update_attributes :created_at => @first_update
586
+ @widget.versions[2].update_attributes :created_at => @second_update
587
+ @widget.update_attribute :updated_at, @second_update
588
+ end
589
+
590
+ should 'return versions in the time period' do
591
+ assert_equal ['Fidget'], @widget.versions_between(20.days.ago, 10.days.ago).map(&:name)
592
+ assert_equal ['Widget', 'Fidget'], @widget.versions_between(45.days.ago, 10.days.ago).map(&:name)
593
+ assert_equal ['Fidget', 'Digit'], @widget.versions_between(16.days.ago, 1.minute.ago).map(&:name)
594
+ assert_equal [], @widget.versions_between(60.days.ago, 45.days.ago).map(&:name)
595
+ end
596
+ end
579
597
 
580
598
  context 'on the first version' do
581
599
  setup { @version = @widget.versions.first }
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class TimestampTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
- PaperTrail.config.timestamp_field = :custom_created_at
6
+ PaperTrail.timestamp_field = :custom_created_at
7
7
  change_schema
8
8
  Version.reset_column_information
9
9
 
@@ -16,6 +16,10 @@ class TimestampTest < ActiveSupport::TestCase
16
16
  @fluxor.update_attributes :name => 'Even more text.'
17
17
  end
18
18
 
19
+ teardown do
20
+ PaperTrail.timestamp_field = :created_at
21
+ end
22
+
19
23
  test 'versions works with custom timestamp field' do
20
24
  # Normal behaviour
21
25
  assert_equal 3, @fluxor.versions.length
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 6
9
- - 1
10
- version: 2.6.1
9
+ - 2
10
+ version: 2.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart