kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.8 KiB
106 lines
3.8 KiB
11 years ago
|
#-- copyright
|
||
|
# OpenProject Reporting Plugin
|
||
|
#
|
||
|
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# version 3.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#++
|
||
|
|
||
15 years ago
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||
|
|
||
10 years ago
|
describe CostQuery, type: :model, reporting_query_helper: true do
|
||
14 years ago
|
minimal_query
|
||
15 years ago
|
|
||
7 years ago
|
let!(:project1){ FactoryBot.create(:project_with_types) }
|
||
|
let!(:work_package1) { FactoryBot.create(:work_package, project: project1) }
|
||
|
let!(:time_entry1) { FactoryBot.create(:time_entry, work_package: work_package1, project: project1) }
|
||
|
let!(:time_entry2) { FactoryBot.create(:time_entry, work_package: work_package1, project: project1) }
|
||
12 years ago
|
|
||
7 years ago
|
let!(:project2) { FactoryBot.create(:project_with_types) }
|
||
|
let!(:work_package2) { FactoryBot.create(:work_package, project: project2) }
|
||
|
let!(:time_entry3) { FactoryBot.create(:time_entry, work_package: work_package2, project: project2) }
|
||
|
let!(:time_entry4) { FactoryBot.create(:time_entry, work_package: work_package2, project: project2) }
|
||
12 years ago
|
|
||
|
before do
|
||
7 years ago
|
FactoryBot.create(:admin)
|
||
12 years ago
|
end
|
||
15 years ago
|
|
||
15 years ago
|
describe "the reporting system" do
|
||
15 years ago
|
it "should compute group_by and a filter" do
|
||
|
@query.group_by :project_id
|
||
10 years ago
|
@query.filter :status_id, operator: 'o'
|
||
15 years ago
|
sql_result = @query.result
|
||
|
|
||
11 years ago
|
expect(sql_result.size).to eq(2)
|
||
15 years ago
|
#for each project the number of entries should be correct
|
||
|
sql_count = []
|
||
|
sql_result.each do |sub_result|
|
||
|
#project should be the outmost group_by
|
||
11 years ago
|
expect(sub_result.fields).to include(:project_id)
|
||
15 years ago
|
sql_count.push sub_result.count
|
||
|
end
|
||
11 years ago
|
expect(sql_count.sort).to eq([2, 2])
|
||
15 years ago
|
end
|
||
|
|
||
|
it "should apply two filter and a group_by correctly" do
|
||
10 years ago
|
@query.filter :project_id, operator: '=', value: [project1.id]
|
||
15 years ago
|
@query.group_by :user_id
|
||
10 years ago
|
@query.filter :overridden_costs, operator: 'n'
|
||
15 years ago
|
|
||
|
sql_result = @query.result
|
||
11 years ago
|
expect(sql_result.size).to eq(2)
|
||
15 years ago
|
#for each user the number of entries should be correct
|
||
|
sql_count = []
|
||
|
sql_result.each do |sub_result|
|
||
|
#project should be the outmost group_by
|
||
11 years ago
|
expect(sub_result.fields).to include(:user_id)
|
||
15 years ago
|
sql_count.push sub_result.count
|
||
|
end
|
||
11 years ago
|
expect(sql_count.sort).to eq([1, 1])
|
||
15 years ago
|
end
|
||
|
|
||
12 years ago
|
it "should apply two different filters on the same field" do
|
||
10 years ago
|
@query.filter :project_id, operator: '=', value: [project1.id, project2.id]
|
||
|
@query.filter :project_id, operator: '!', value: [project2.id]
|
||
15 years ago
|
|
||
|
sql_result = @query.result
|
||
11 years ago
|
expect(sql_result.count).to eq(2)
|
||
15 years ago
|
end
|
||
15 years ago
|
|
||
9 years ago
|
it 'should process only _one_ SQL query for any operations on a valid CostQuery' do
|
||
|
number_of_sql_queries = 0
|
||
|
expect_any_instance_of(CostQuery::SqlStatement).to receive(:to_s) do |*_|
|
||
|
number_of_sql_queries += 1 unless caller.third.include? 'sql_statement.rb'
|
||
15 years ago
|
|
||
9 years ago
|
# Apparently, we have to return a valid SQL query
|
||
15 years ago
|
|
||
9 years ago
|
'SELECT 1=1'
|
||
15 years ago
|
end
|
||
9 years ago
|
|
||
15 years ago
|
# create a random query
|
||
12 years ago
|
@query.group_by :work_package_id
|
||
15 years ago
|
@query.column :tweek
|
||
|
@query.row :project_id
|
||
|
@query.row :user_id
|
||
9 years ago
|
# count how often a sql query was created
|
||
15 years ago
|
number_of_sql_queries = 0
|
||
|
# do some random things on it
|
||
15 years ago
|
walker = @query.transformer
|
||
15 years ago
|
walker.row_first
|
||
|
walker.column_first
|
||
15 years ago
|
# TODO - to do something
|
||
15 years ago
|
end
|
||
15 years ago
|
end
|
||
12 years ago
|
end
|