|
|
@ -22,8 +22,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') |
|
|
|
describe CostQuery, type: :model, reporting_query_helper: true do |
|
|
|
describe CostQuery, type: :model, reporting_query_helper: true do |
|
|
|
minimal_query |
|
|
|
minimal_query |
|
|
|
|
|
|
|
|
|
|
|
let!(:project1) { FactoryBot.create(:project, name: "project1", created_on: 5.minutes.ago) } |
|
|
|
let!(:project1) { FactoryBot.create(:project, name: "project1", created_at: 5.minutes.ago) } |
|
|
|
let!(:project2) { FactoryBot.create(:project, name: "project2", created_on: 6.minutes.ago) } |
|
|
|
let!(:project2) { FactoryBot.create(:project, name: "project2", created_at: 6.minutes.ago) } |
|
|
|
|
|
|
|
|
|
|
|
describe CostQuery::Operator do |
|
|
|
describe CostQuery::Operator do |
|
|
|
def query(table, field, operator, *values) |
|
|
|
def query(table, field, operator, *values) |
|
|
@ -110,69 +110,69 @@ describe CostQuery, type: :model, reporting_query_helper: true do |
|
|
|
|
|
|
|
|
|
|
|
it "does w (this week)" do |
|
|
|
it "does w (this week)" do |
|
|
|
#somehow this test doesn't work on sundays |
|
|
|
#somehow this test doesn't work on sundays |
|
|
|
n = query('projects', 'created_on', 'w').size |
|
|
|
n = query('projects', 'created_at', 'w').size |
|
|
|
day_in_this_week = Time.now.at_beginning_of_week + 1.day |
|
|
|
day_in_this_week = Time.now.at_beginning_of_week + 1.day |
|
|
|
FactoryBot.create(:project, created_on: day_in_this_week) |
|
|
|
FactoryBot.create(:project, created_at: day_in_this_week) |
|
|
|
expect(query('projects', 'created_on', 'w').size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 'w').size).to eq(n + 1) |
|
|
|
FactoryBot.create(:project, created_on: day_in_this_week + 7.days) |
|
|
|
FactoryBot.create(:project, created_at: day_in_this_week + 7.days) |
|
|
|
FactoryBot.create(:project, created_on: day_in_this_week - 7.days) |
|
|
|
FactoryBot.create(:project, created_at: day_in_this_week - 7.days) |
|
|
|
expect(query('projects', 'created_on', 'w').size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 'w').size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does t (today)" do |
|
|
|
it "does t (today)" do |
|
|
|
s = query('projects', 'created_on', 't').size |
|
|
|
s = query('projects', 'created_at', 't').size |
|
|
|
FactoryBot.create(:project, created_on: Date.yesterday) |
|
|
|
FactoryBot.create(:project, created_at: Date.yesterday) |
|
|
|
expect(query('projects', 'created_on', 't').size).to eq(s) |
|
|
|
expect(query('projects', 'created_at', 't').size).to eq(s) |
|
|
|
FactoryBot.create(:project, created_on: Time.now) |
|
|
|
FactoryBot.create(:project, created_at: Time.now) |
|
|
|
expect(query('projects', 'created_on', 't').size).to eq(s + 1) |
|
|
|
expect(query('projects', 'created_at', 't').size).to eq(s + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does <t+ (before the day which is n days in the future)" do |
|
|
|
it "does <t+ (before the day which is n days in the future)" do |
|
|
|
n = query('projects', 'created_on', '<t+', 2).size |
|
|
|
n = query('projects', 'created_at', '<t+', 2).size |
|
|
|
FactoryBot.create(:project, created_on: Date.tomorrow + 1) |
|
|
|
FactoryBot.create(:project, created_at: Date.tomorrow + 1) |
|
|
|
expect(query('projects', 'created_on', '<t+', 2).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '<t+', 2).size).to eq(n + 1) |
|
|
|
FactoryBot.create(:project, created_on: Date.tomorrow + 2) |
|
|
|
FactoryBot.create(:project, created_at: Date.tomorrow + 2) |
|
|
|
expect(query('projects', 'created_on', '<t+', 2).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '<t+', 2).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does t+ (n days in the future)" do |
|
|
|
it "does t+ (n days in the future)" do |
|
|
|
n = query('projects', 'created_on', 't+', 1).size |
|
|
|
n = query('projects', 'created_at', 't+', 1).size |
|
|
|
FactoryBot.create(:project, created_on: Date.tomorrow) |
|
|
|
FactoryBot.create(:project, created_at: Date.tomorrow) |
|
|
|
expect(query('projects', 'created_on', 't+', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 't+', 1).size).to eq(n + 1) |
|
|
|
FactoryBot.create(:project, created_on: Date.tomorrow + 2) |
|
|
|
FactoryBot.create(:project, created_at: Date.tomorrow + 2) |
|
|
|
expect(query('projects', 'created_on', 't+', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 't+', 1).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does >t+ (after the day which is n days in the furure)" do |
|
|
|
it "does >t+ (after the day which is n days in the furure)" do |
|
|
|
n = query('projects', 'created_on', '>t+', 1).size |
|
|
|
n = query('projects', 'created_at', '>t+', 1).size |
|
|
|
FactoryBot.create(:project, created_on: Time.now) |
|
|
|
FactoryBot.create(:project, created_at: Time.now) |
|
|
|
expect(query('projects', 'created_on', '>t+', 1).size).to eq(n) |
|
|
|
expect(query('projects', 'created_at', '>t+', 1).size).to eq(n) |
|
|
|
FactoryBot.create(:project, created_on: Date.tomorrow + 1) |
|
|
|
FactoryBot.create(:project, created_at: Date.tomorrow + 1) |
|
|
|
expect(query('projects', 'created_on', '>t+', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '>t+', 1).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does >t- (after the day which is n days ago)" do |
|
|
|
it "does >t- (after the day which is n days ago)" do |
|
|
|
n = query('projects', 'created_on', '>t-', 1).size |
|
|
|
n = query('projects', 'created_at', '>t-', 1).size |
|
|
|
FactoryBot.create(:project, created_on: Date.today) |
|
|
|
FactoryBot.create(:project, created_at: Date.today) |
|
|
|
expect(query('projects', 'created_on', '>t-', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '>t-', 1).size).to eq(n + 1) |
|
|
|
FactoryBot.create(:project, created_on: Date.yesterday - 1) |
|
|
|
FactoryBot.create(:project, created_at: Date.yesterday - 1) |
|
|
|
expect(query('projects', 'created_on', '>t-', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '>t-', 1).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does t- (n days ago)" do |
|
|
|
it "does t- (n days ago)" do |
|
|
|
n = query('projects', 'created_on', 't-', 1).size |
|
|
|
n = query('projects', 'created_at', 't-', 1).size |
|
|
|
FactoryBot.create(:project, created_on: Date.yesterday) |
|
|
|
FactoryBot.create(:project, created_at: Date.yesterday) |
|
|
|
expect(query('projects', 'created_on', 't-', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 't-', 1).size).to eq(n + 1) |
|
|
|
FactoryBot.create(:project, created_on: Date.yesterday - 2) |
|
|
|
FactoryBot.create(:project, created_at: Date.yesterday - 2) |
|
|
|
expect(query('projects', 'created_on', 't-', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', 't-', 1).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does <t- (before the day which is n days ago)" do |
|
|
|
it "does <t- (before the day which is n days ago)" do |
|
|
|
n = query('projects', 'created_on', '<t-', 1).size |
|
|
|
n = query('projects', 'created_at', '<t-', 1).size |
|
|
|
FactoryBot.create(:project, created_on: Date.today) |
|
|
|
FactoryBot.create(:project, created_at: Date.today) |
|
|
|
expect(query('projects', 'created_on', '<t-', 1).size).to eq(n) |
|
|
|
expect(query('projects', 'created_at', '<t-', 1).size).to eq(n) |
|
|
|
FactoryBot.create(:project, created_on: Date.yesterday - 1) |
|
|
|
FactoryBot.create(:project, created_at: Date.yesterday - 1) |
|
|
|
expect(query('projects', 'created_on', '<t-', 1).size).to eq(n + 1) |
|
|
|
expect(query('projects', 'created_at', '<t-', 1).size).to eq(n + 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
#Our own operators |
|
|
|
#Our own operators |
|
|
@ -240,20 +240,20 @@ describe CostQuery, type: :model, reporting_query_helper: true do |
|
|
|
|
|
|
|
|
|
|
|
it "does =d" do |
|
|
|
it "does =d" do |
|
|
|
#assuming that there aren't more than one project created at the same time |
|
|
|
#assuming that there aren't more than one project created at the same time |
|
|
|
expect(query('projects', 'created_on', '=d', Project.order(Arel.sql('id ASC')).first.created_on).size).to eq(1) |
|
|
|
expect(query('projects', 'created_at', '=d', Project.order(Arel.sql('id ASC')).first.created_at).size).to eq(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does <d" do |
|
|
|
it "does <d" do |
|
|
|
expect(query('projects', 'created_on', '<d', Time.now).size).to eq(Project.count) |
|
|
|
expect(query('projects', 'created_at', '<d', Time.now).size).to eq(Project.count) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does <>d" do |
|
|
|
it "does <>d" do |
|
|
|
expect(query('projects', 'created_on', '<>d', Time.now, 5.minutes.from_now).size).to eq(0) |
|
|
|
expect(query('projects', 'created_at', '<>d', Time.now, 5.minutes.from_now).size).to eq(0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does >d" do |
|
|
|
it "does >d" do |
|
|
|
#assuming that all projects were created in the past |
|
|
|
#assuming that all projects were created in the past |
|
|
|
expect(query('projects', 'created_on', '>d', Time.now).size).to eq(0) |
|
|
|
expect(query('projects', 'created_at', '>d', Time.now).size).to eq(0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe 'arity' do |
|
|
|
describe 'arity' do |
|
|
@ -262,6 +262,5 @@ describe CostQuery, type: :model, reporting_query_helper: true do |
|
|
|
it("#{o} should take #{a} values") { expect(o.to_operator.arity).to eq(a) } |
|
|
|
it("#{o} should take #{a} values") { expect(o.to_operator.arity).to eq(a) } |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|