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

validate presence of custom_field_section as suggested by @dombesz

Jonas Jabarifac00bb26342
diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb
index bf83af7b4b0..d1aa6fe6077 100644
--- a/app/models/project_custom_field.rb
+++ b/app/models/project_custom_field.rb
@@ -36,6 +36,8 @@ class ProjectCustomField < CustomField
after_save :activate_required_field_in_all_projects
+ validates :custom_field_section_id, presence: true
+
def type_name
:label_project_plural
end
diff --git a/spec/features/admin/project_custom_fields/create_spec.rb b/spec/features/admin/project_custom_fields/create_spec.rb
index 4f9b2fd5340..6e2e5e7bb27 100644
--- a/spec/features/admin/project_custom_fields/create_spec.rb
+++ b/spec/features/admin/project_custom_fields/create_spec.rb
@@ -102,5 +102,20 @@ RSpec.describe "Create project custom fields", :js do
expect(page).to have_no_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))
expect(page).to have_current_path(new_admin_settings_project_custom_field_path)
end
+
+ context "without any existing sections" do
+ before do
+ ProjectCustomFieldSection.destroy_all
+ visit new_admin_settings_project_custom_field_path
+ end
+
+ it "prevents creating a new project custom field with an empty name" do
+ fill_in("custom_field_name", with: "New custom field")
+
+ click_on("Save")
+
+ expect(page).to have_text("Section can't be blank.")
+ end
+ end
end
end