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.
125 lines
4.1 KiB
125 lines
4.1 KiB
10 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.
|
||
|
#++
|
||
|
|
||
|
require 'spec_helper'
|
||
10 years ago
|
require File.join(File.dirname(__FILE__), '..', 'support', 'custom_field_filter')
|
||
10 years ago
|
require File.join(File.dirname(__FILE__), '..', 'support', 'configuration_helper')
|
||
10 years ago
|
|
||
10 years ago
|
describe 'Custom field filter and group by caching', type: :request do
|
||
10 years ago
|
include OpenProject::Reporting::SpecHelper::CustomFieldFilterHelper
|
||
|
include OpenProject::Reporting::SpecHelper::ConfigurationHelper
|
||
|
|
||
7 years ago
|
let(:project) { FactoryBot.create(:valid_project) }
|
||
|
let(:user) { FactoryBot.create(:admin) }
|
||
|
let(:custom_field) { FactoryBot.build(:work_package_custom_field) }
|
||
|
let(:custom_field2) { FactoryBot.build(:work_package_custom_field) }
|
||
10 years ago
|
|
||
|
before do
|
||
|
allow(User).to receive(:current).and_return(user)
|
||
|
|
||
|
custom_field.save!
|
||
|
end
|
||
|
|
||
10 years ago
|
after do
|
||
|
CostQuery::Cache.reset!
|
||
|
end
|
||
|
|
||
10 years ago
|
def expect_group_by_all_to_include(custom_field)
|
||
|
expect(CostQuery::GroupBy.all).to include(group_by_class_name_string(custom_field).constantize)
|
||
|
end
|
||
|
|
||
|
def expect_filter_all_to_include(custom_field)
|
||
|
expect(CostQuery::Filter.all).to include(filter_class_name_string(custom_field).constantize)
|
||
|
end
|
||
|
|
||
|
def expect_group_by_all_to_not_exist(custom_field)
|
||
10 years ago
|
# can not check for whether the element is included in CostQuery::GroupBy.all if it does not exist
|
||
10 years ago
|
expect { group_by_class_name_string(custom_field).constantize }.to raise_error NameError
|
||
|
end
|
||
|
|
||
|
def expect_filter_all_to_not_exist(custom_field)
|
||
10 years ago
|
# can not check for whether the element is included in CostQuery::Filter.all if it does not exist
|
||
|
expect { filter_class_name_string(custom_field).constantize }.to raise_error NameError
|
||
10 years ago
|
end
|
||
|
|
||
|
def visit_cost_reports_index
|
||
7 years ago
|
header "Content-Type", "text/html"
|
||
|
header 'X-Requested-With', 'XMLHttpRequest'
|
||
9 years ago
|
get "/projects/#{project.id}/cost_reports"
|
||
10 years ago
|
end
|
||
|
|
||
10 years ago
|
it 'removes the filter/group_by if the custom field is removed' do
|
||
|
custom_field2.save!
|
||
|
|
||
10 years ago
|
visit_cost_reports_index
|
||
|
|
||
|
expect_group_by_all_to_include(custom_field)
|
||
|
expect_group_by_all_to_include(custom_field2)
|
||
10 years ago
|
|
||
10 years ago
|
expect_filter_all_to_include(custom_field)
|
||
|
expect_filter_all_to_include(custom_field2)
|
||
10 years ago
|
|
||
|
custom_field2.destroy
|
||
|
|
||
10 years ago
|
visit_cost_reports_index
|
||
10 years ago
|
|
||
10 years ago
|
expect_group_by_all_to_include(custom_field)
|
||
|
expect_group_by_all_to_not_exist(custom_field2)
|
||
|
|
||
|
expect_filter_all_to_include(custom_field)
|
||
|
expect_filter_all_to_not_exist(custom_field2)
|
||
10 years ago
|
end
|
||
|
|
||
|
it 'removes the filter/group_by if the last custom field is removed' do
|
||
10 years ago
|
visit_cost_reports_index
|
||
10 years ago
|
|
||
10 years ago
|
expect_group_by_all_to_include(custom_field)
|
||
|
expect_filter_all_to_include(custom_field)
|
||
10 years ago
|
|
||
|
custom_field.destroy
|
||
|
|
||
10 years ago
|
visit_cost_reports_index
|
||
10 years ago
|
|
||
10 years ago
|
expect_group_by_all_to_not_exist(custom_field)
|
||
|
expect_filter_all_to_not_exist(custom_field)
|
||
10 years ago
|
end
|
||
10 years ago
|
|
||
10 years ago
|
it 'allows for changing the db entries directly via SQL between requests \
|
||
|
if no caching is done (this could also mean switching dbs)' do
|
||
|
new_label = "our new label"
|
||
|
mock_cache_classes_setting_with(false)
|
||
10 years ago
|
|
||
10 years ago
|
visit_cost_reports_index
|
||
10 years ago
|
|
||
10 years ago
|
expect_group_by_all_to_include(custom_field)
|
||
|
expect_filter_all_to_include(custom_field)
|
||
10 years ago
|
|
||
8 years ago
|
CustomField.where(id: custom_field.id)
|
||
|
.update_all(name: new_label)
|
||
10 years ago
|
|
||
10 years ago
|
visit_cost_reports_index
|
||
10 years ago
|
|
||
10 years ago
|
expect_group_by_all_to_include(custom_field)
|
||
|
expect_filter_all_to_include(custom_field)
|
||
10 years ago
|
|
||
10 years ago
|
expect(group_by_class_name_string(custom_field).constantize.label).to eql(new_label)
|
||
|
expect(filter_class_name_string(custom_field).constantize.label).to eql(new_label)
|
||
10 years ago
|
end
|
||
10 years ago
|
end
|