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 validation and test for include_subprojects

Oliver Günthercb8fac1f14ed
diff --git a/app/models/query.rb b/app/models/query.rb
index 82e91ccb6de..d298dc512a5 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -45,6 +45,9 @@ class Query < ApplicationRecord
presence: true,
length: { maximum: 255 }
+ validates :include_subprojects,
+ inclusion: [true, false]
+
validate :validate_work_package_filters
validate :validate_columns
validate :validate_sort_criteria
diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rb
index 8690bb1a923..15604a5a2e7 100644
--- a/spec/models/query_spec.rb
+++ b/spec/models/query_spec.rb
@@ -60,6 +60,28 @@ describe Query, type: :model do
expect(query.sort_criteria)
.to match_array([['id', 'asc']])
end
+
+ context 'with global subprojects include', with_settings: { display_subprojects_work_packages: true } do
+ it 'sets the include subprojects' do
+ expect(query.include_subprojects).to eq true
+ end
+ end
+
+ context 'with global subprojects include', with_settings: { display_subprojects_work_packages: false } do
+ it 'sets the include subprojects' do
+ expect(query.include_subprojects).to eq false
+ end
+ end
+ end
+
+ describe 'include_subprojects' do
+ let(:query) { Query.new name: 'foo' }
+
+ it 'is required' do
+ expect(query).not_to be_valid
+
+ expect(query.errors[:include_subprojects]).to include 'is not set to one of the allowed values.'
+ end
end
describe 'hidden' do
diff --git a/spec/models/work_package/exporter/csv_integration_spec.rb b/spec/models/work_package/exporter/csv_integration_spec.rb
index 4055bc28ebc..b121be559ce 100644
--- a/spec/models/work_package/exporter/csv_integration_spec.rb
+++ b/spec/models/work_package/exporter/csv_integration_spec.rb
@@ -41,7 +41,7 @@ describe WorkPackage::Exports::CSV, 'integration', type: :model do
member_with_permissions: %i(view_work_packages))
end
let(:query) do
- Query.new(name: '_').tap do |query|
+ Query.new_default(name: '_').tap do |query|
query.column_names = %i(subject assigned_to updated_at estimated_hours)
end
end