|
|
|
@ -60,22 +60,25 @@ describe Queries::Days::DayQuery, type: :model do |
|
|
|
|
instance.where('date', '<>d', date_range) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with dates within the default range' do |
|
|
|
|
shared_examples_for 'dates within the default range' do |working: nil| |
|
|
|
|
let(:from) { Time.zone.today } |
|
|
|
|
let(:to) { 5.days.from_now.to_date } |
|
|
|
|
let(:base_scope) { Day.from_range(from:, to:).reorder(date: :asc) } |
|
|
|
|
|
|
|
|
|
it 'is the same as handwriting the query' do |
|
|
|
|
# Expectation has to be weirdly specific to the logic of Queries::Operators::DateRangeClauses |
|
|
|
|
expected = base_scope.where("days.date > ? AND days.date <= ?", |
|
|
|
|
expected_scope = base_scope.where("days.date > ? AND days.date <= ?", |
|
|
|
|
(from - 1.day).end_of_day, |
|
|
|
|
to.end_of_day) |
|
|
|
|
|
|
|
|
|
expect(instance.results.to_sql).to eql expected.to_sql |
|
|
|
|
unless working.nil? |
|
|
|
|
expected_scope = expected_scope.where("days.working IN ('#{working}')") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
expect(instance.results.to_sql).to eql expected_scope.to_sql |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with dates out of the default range' do |
|
|
|
|
shared_examples_for 'dates out of the default range' do |
|
|
|
|
let(:from) { 5.days.from_now.to_date } |
|
|
|
|
let(:to) { 153.days.from_now.to_date } |
|
|
|
|
|
|
|
|
@ -101,5 +104,17 @@ describe Queries::Days::DayQuery, type: :model do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
include_examples 'dates within the default range' |
|
|
|
|
include_examples 'dates out of the default range' |
|
|
|
|
|
|
|
|
|
context 'when having a working filter too' do |
|
|
|
|
before do |
|
|
|
|
instance.where('working', '=', 't') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
include_examples 'dates within the default range', working: 't' |
|
|
|
|
include_examples 'dates out of the default range' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|