Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Adding a 'between' scope to Version #126

Merged
merged 2 commits into from Mar 12, 2012

Conversation

Projects
None yet
5 participants
Contributor

emschwar commented Jan 23, 2012

The 'following' scope is only partially useful to us; we also need to know if a change existed during a given period of time. Hence this scope.

I wanted to add tests, but I wasn't sure where you wanted them, since I didn't see a test for 'following'; if you need a test before accepting this, just let me know where to put it.

Owner

airblade commented Feb 7, 2012

Many thanks for this, and sorry for the delay in getting back to you.

It would be great if you were able to add a test. The following scope is implicitly exercised in the tests for version_at; that might be a good place to add a test for between. See here.

Contributor

emschwar commented Feb 8, 2012

Thanks for the pointer; I'll add a test shortly.

Eric Schwartz and others added some commits Jan 23, 2012

Eric Schwartz Adding a between scope to Version to see if any changes happened duri…
…ng a period
a14cea6
Angelo Lakra & Jason Noble Add versions_between method and test coverage
Usage:
   @widget.versions_between(60.days.ago, 45.days.ago)
      Returns an array of @widget instances as they were
      during that time period
2074590

Updated Eric's commit with test coverage and adding a versions_between instance method on Versions.

@airblade airblade merged commit 2074590 into airblade:master Mar 12, 2012

Owner

airblade commented Mar 12, 2012

Thanks for this. It's in v2.6.2.

@tra tra commented on the diff May 10, 2012

lib/paper_trail/version.rb
@@ -20,6 +20,10 @@ def self.with_item_keys(item_type, item_id)
where(['created_at > ?', timestamp]).order("created_at ASC, #{self.primary_key} ASC")
}
+ scope :between, lambda { |start_time, end_time|
+ where(['created_at > ? AND created_at < ?', start_time, end_time ]).order("created_at ASC, #{self.primary_key} ASC")
@tra

tra May 10, 2012

Shouldn't this be more like the SQL between operator which is inclusive? Or maybe you just use between like this:

where(['created_at between ? AND ?', start_time, end_time ]).order("created_at ASC, #{self.primary_key} ASC")
@TylerRick

TylerRick Jul 25, 2012

Contributor

Yeah, I would think so. That would be my expectation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment