Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add spec for changed subproject behavior

Oliver Günthere5b05b9fa0cf
diff --git a/app/models/query.rb b/app/models/query.rb
index 9fc48f8938e..82e91ccb6de 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -369,7 +369,7 @@ class Query < ApplicationRecord
subproject_filter = Queries::WorkPackages::Filter::SubprojectFilter.create!
subproject_filter.context = self
- subproject_filter.operator = if Setting.display_subprojects_work_packages?
+ subproject_filter.operator = if include_subprojects?
'*'
else
'!*'
diff --git a/spec/factories/query_factory.rb b/spec/factories/query_factory.rb
index e2ad6446398..6d44755050f 100644
--- a/spec/factories/query_factory.rb
+++ b/spec/factories/query_factory.rb
@@ -30,7 +30,7 @@ FactoryBot.define do
factory :query do
project
user factory: :user
- include_subprojects { true }
+ include_subprojects { Setting.display_subprojects_work_packages? }
sequence(:name) { |n| "Query #{n}" }
factory :public_query do
diff --git a/spec/models/query/results_subproject_filter_integration_spec.rb b/spec/models/query/results_subproject_filter_integration_spec.rb
index 52adc6bb80c..5b9330e0529 100644
--- a/spec/models/query/results_subproject_filter_integration_spec.rb
+++ b/spec/models/query/results_subproject_filter_integration_spec.rb
@@ -58,34 +58,112 @@ describe ::Query::Results, 'Subproject filter integration', type: :model, with_m
login_as user
end
- context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do
- it 'shows the sub work packages' do
- expect(query_results.work_packages).to match_array [parent_wp, child_wp]
+ describe 'new default query' do
+ context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do
+ it 'shows the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp, child_wp]
+ end
+ end
+
+ context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do
+ it 'does not show the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp]
+ end
+
+ context 'when subproject filter added manually' do
+ before do
+ query.add_filter('subproject_id', '=', [child_project.id])
+ end
+
+ it 'shows the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp, child_wp]
+ end
+ end
+
+ context 'when only subproject filter added manually' do
+ before do
+ query.add_filter('only_subproject_id', '=', [child_project.id])
+ end
+
+ it 'shows only the sub work packages' do
+ expect(query_results.work_packages).to match_array [child_wp]
+ end
+ end
end
end
- context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do
- it 'does not show the sub work packages' do
- expect(query_results.work_packages).to match_array [parent_wp]
+ describe 'query with overriden include_subprojects = true' do
+ before do
+ query.include_subprojects = true
end
- context 'when subproject filter added manually' do
- before do
- query.add_filter('subproject_id', '=', [child_project.id])
+ context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do
+ it 'shows the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp, child_wp]
end
+ end
+ context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do
it 'shows the sub work packages' do
expect(query_results.work_packages).to match_array [parent_wp, child_wp]
end
+
+ context 'when subproject filter added manually' do
+ before do
+ query.add_filter('subproject_id', '=', [child_project.id])
+ end
+
+ it 'shows the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp, child_wp]
+ end
+ end
+
+ context 'when only subproject filter added manually' do
+ before do
+ query.add_filter('only_subproject_id', '=', [child_project.id])
+ end
+
+ it 'shows only the sub work packages' do
+ expect(query_results.work_packages).to match_array [child_wp]
+ end
+ end
+ end
+ end
+
+ describe 'query with overriden include_subprojects = false' do
+ before do
+ query.include_subprojects = false
end
- context 'when only subproject filter added manually' do
- before do
- query.add_filter('only_subproject_id', '=', [child_project.id])
+ context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do
+ it 'does not show the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp]
end
+ end
+
+ context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do
+ it 'does not show the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp]
+ end
+
+ context 'when subproject filter added manually' do
+ before do
+ query.add_filter('subproject_id', '=', [child_project.id])
+ end
+
+ it 'shows the sub work packages' do
+ expect(query_results.work_packages).to match_array [parent_wp, child_wp]
+ end
+ end
+
+ context 'when only subproject filter added manually' do
+ before do
+ query.add_filter('only_subproject_id', '=', [child_project.id])
+ end
- it 'shows only the sub work packages' do
- expect(query_results.work_packages).to match_array [child_wp]
+ it 'shows only the sub work packages' do
+ expect(query_results.work_packages).to match_array [child_wp]
+ end
end
end
end