-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
between_times one-sided and Array args (#63)
* - Support Array argument to between_times - Cleanup specs * `#between_times` now accepts one-sided arguments, e.g. `Time, nil` or `nil, Time`.
- Loading branch information
1 parent
f6970cf
commit 85c3867
Showing
13 changed files
with
188 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
|
||
shared_examples_for 'between_times' do | ||
|
||
describe '#between_times' do | ||
subject { Post.between_times(Time.zone.parse('2014-01-01'), Time.zone.parse('2014-01-06')) } | ||
|
||
if testing_active_record? | ||
it { is_expected.to be_a(ActiveRecord::Relation) } | ||
else testing_mongoid? | ||
it { is_expected.to be_a(Mongoid::Criteria) } | ||
end | ||
|
||
it { expect(subject.count).to eql(3) } | ||
|
||
context 'one-sided query' do | ||
|
||
context 'point query' do | ||
|
||
context 'only start time' do | ||
subject { Post.between_times(Time.zone.parse('2014-01-01'), nil) } | ||
it { expect(subject.count).to eql(12) } | ||
end | ||
|
||
context 'only end time' do | ||
subject { Post.between_times(nil, Time.zone.parse('2014-01-01')) } | ||
it { expect(subject.count).to eql(10) } | ||
end | ||
end | ||
|
||
context 'timespan loose query' do | ||
|
||
context 'only start time' do | ||
subject { Event.between_times(Time.zone.parse('2014-01-01'), nil, strict: false) } | ||
it { expect(subject.count).to eql(9) } | ||
end | ||
|
||
context 'only end time' do | ||
subject { Event.between_times(nil, Time.zone.parse('2014-01-01'), strict: false) } | ||
it { expect(subject.count).to eql(13) } | ||
end | ||
end | ||
|
||
context 'timespan strict query' do | ||
|
||
context 'only start time' do | ||
subject { Event.between_times(Time.zone.parse('2014-01-01'), nil) } | ||
it { expect(subject.count).to eql(9) } | ||
end | ||
|
||
context 'only end time' do | ||
subject { Event.between_times(nil, Time.zone.parse('2014-01-01')) } | ||
it { expect(subject.count).to eql(13) } | ||
end | ||
end | ||
end | ||
end | ||
|
||
if testing_mongoid? | ||
describe '#between' do | ||
it 'should not override Mongoid between method' do | ||
posts = Post.between(created_at: Time.zone.parse('2014-01-01')..Time.zone.parse('2014-01-06')) | ||
expect(posts.count).to eql(3) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
It would be handy if the
!start_time && !end_time
case were handled here too, withscope
returned unaltered in this case.