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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add validation and test for include_subprojects
Oliver Günthercb8fac1f14ed
diff --git a/app/models/query.rb b/app/models/query.rbindex 82e91ccb6de..d298dc512a5 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -45,6 +45,9 @@ class Query < ApplicationRecordpresence: true,length: { maximum: 255 }+ validates :include_subprojects,+ inclusion: [true, false]+validate :validate_work_package_filtersvalidate :validate_columnsvalidate :validate_sort_criteriadiff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rbindex 8690bb1a923..15604a5a2e7 100644--- a/spec/models/query_spec.rb+++ b/spec/models/query_spec.rb@@ -60,6 +60,28 @@ describe Query, type: :model doexpect(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.'+ endenddescribe 'hidden' dodiff --git a/spec/models/work_package/exporter/csv_integration_spec.rb b/spec/models/work_package/exporter/csv_integration_spec.rbindex 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 domember_with_permissions: %i(view_work_packages))endlet(: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)endend