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
[#64347] project custom fields index spec
Tobias Dillmannac6e6155b2db
diff --git a/lib/open_project/custom_field_format.rb b/lib/open_project/custom_field_format.rbindex 295c2d89697..0ce379e26ff 100644--- a/lib/open_project/custom_field_format.rb+++ b/lib/open_project/custom_field_format.rb@@ -90,8 +90,6 @@ module OpenProjectenddef find_by(name:)- return nil if name.to_s == "calculated_value" && !OpenProject::FeatureDecisions.calculated_value_project_attribute_active?-registered[name.to_s]enddiff --git a/spec/features/admin/custom_fields/projects/index_spec.rb b/spec/features/admin/custom_fields/projects/index_spec.rbindex 556cba513f3..f6c4eec10b7 100644--- a/spec/features/admin/custom_fields/projects/index_spec.rb+++ b/spec/features/admin/custom_fields/projects/index_spec.rb@@ -129,6 +129,55 @@ RSpec.describe "List project custom fields", :js doenddescribe "managing project custom fields" do+ context "with calculated value feature flag active", with_flag: { calculated_value_project_attribute: true } do+ it "offers the type for creation" do+ cf_index_page.expect_having_create_item("Calculated value")+ end++ context "with fields of type calculated value" do+ let!(:calculated_value_project_custom_field) do+ create(:calculated_value_project_custom_field,+ name: "Calculated value field",+ project_custom_field_section: section_for_input_fields)+ end++ before do+ login_as(admin)+ cf_index_page.visit!+ end++ it "lists the calculated value custom field" do+ within_project_custom_field_section_container(section_for_input_fields) do+ containers = page.all(".op-project-custom-field-container")++ expect(containers.last.text).to include(calculated_value_project_custom_field.name)+ end+ end++ it "does not list calculated values if the feature flag is deactivated later" do+ # This spec tests that calculated values are no longer shown after the feature flag is deactivated.+ # First, a custom field of type calculated value is created. This must be done while the feature flag is active,+ # or else the model validation will fail.+ # Next, we simulate that the feature flag is off:+ allow(OpenProject::FeatureDecisions).to receive(:calculated_value_project_attribute_active?).and_return(false)++ # Revisit the page and check that the field is no longer listed:+ cf_index_page.visit!+ within_project_custom_field_section_container(section_for_input_fields) do+ containers = page.all(".op-project-custom-field-container")++ expect(containers.last.text).not_to include(calculated_value_project_custom_field.name)+ end+ end+ end+ end++ context "without calculated value feature flag active" do+ it "does not offer the type for creation" do+ cf_index_page.expect_not_having_create_item("Calculated value")+ end+ end+it "shows all custom fields in the correct order within their section and allows reordering via menu or drag and drop" dowithin_project_custom_field_section_container(section_for_input_fields) docontainers = page.all(".op-project-custom-field-container")@@ -253,7 +302,7 @@ RSpec.describe "List project custom fields", :js dowithin_project_custom_field_section_menu(section) doclick_on(action)end- sleep 0.5 # quick fix: allow the brower to process the action+ sleep 0.5 # quick fix: allow the browser to process the actionenddef within_project_custom_field_container(custom_field, &)diff --git a/spec/lib/open_project/custom_field_format_spec.rb b/spec/lib/open_project/custom_field_format_spec.rbindex b1e45393c1b..928d5c12ff3 100644--- a/spec/lib/open_project/custom_field_format_spec.rb+++ b/spec/lib/open_project/custom_field_format_spec.rb@@ -41,47 +41,55 @@ RSpec.describe OpenProject::CustomFieldFormat doendcontext "for a 'Project' class" do- it_behaves_like "custom field formats",- "Project",- ["bool", "date", "float", "int", "link", "list", "string", "text", "user", "version"]+ context "with calculated values feature flag enabled", with_flag: { calculated_value_project_attribute: true } do+ it_behaves_like "custom field formats",+ "Project",+ %w[bool calculated_value date float int link list string text user version]+ end++ context "with calculated values feature flag disabled" do+ it_behaves_like "custom field formats",+ "Project",+ %w[bool date float int link list string text user version]+ endendcontext "for a 'WorkPackage' class" docontext "with a custom_field_hierarchies ee", with_ee: [:custom_field_hierarchies] doit_behaves_like "custom field formats","WorkPackage",- ["bool", "date", "float", "int", "link", "list", "string", "text", "user", "version", "hierarchy"]+ %w[bool date float int link list string text user version hierarchy]endcontext "without a custom_field_hierarchies ee" doit_behaves_like "custom field formats","WorkPackage",- ["bool", "date", "float", "int", "link", "list", "string", "text", "user", "version"]+ %w[bool date float int link list string text user version]endendcontext "for a 'Version' class" doit_behaves_like "custom field formats","Version",- ["bool", "date", "float", "int", "list", "string", "text", "user", "version"]+ %w[bool date float int list string text user version]endcontext "for a 'TimeEntry' class" doit_behaves_like "custom field formats","TimeEntry",- ["bool", "date", "float", "int", "list", "string", "text", "user", "version"]+ %w[bool date float int list string text user version]endcontext "for a 'User' class" doit_behaves_like "custom field formats","User",- ["bool", "date", "float", "int", "list", "string", "text"]+ %w[bool date float int list string text]endcontext "for a 'Group' class" doit_behaves_like "custom field formats","Group",- ["bool", "date", "float", "int", "list", "string", "text"]+ %w[bool date float int list string text]endend@@ -93,6 +101,15 @@ RSpec.describe OpenProject::CustomFieldFormat do.to contain_exactly("bool", "date", "float", "int", "link", "list", "string", "text", "user","version", "hierarchy", "empty")end++ context "with calculated values feature flag enabled", with_flag: { calculated_value_project_attribute: true } do+ it "returns all custom field formats including calculated values" do+ formats = described_class.available_formats+ expect(formats)+ .to contain_exactly("bool", "calculated_value", "date", "float", "int", "link", "list", "string", "text",+ "user", "version", "hierarchy", "empty")+ end+ endendcontext "without a custom_field_hierarchies ee" do@@ -102,6 +119,15 @@ RSpec.describe OpenProject::CustomFieldFormat do.to contain_exactly("bool", "date", "float", "int", "link", "list", "string", "text", "user","version", "empty")end++ context "with calculated values feature flag enabled", with_flag: { calculated_value_project_attribute: true } do+ it "returns all custom field formats including calculated values" do+ formats = described_class.available_formats+ expect(formats)+ .to contain_exactly("bool", "calculated_value", "date", "float", "int", "link", "list", "string", "text",+ "user", "version", "empty")+ end+ endendendenddiff --git a/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb b/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rbindex 92e9e18b48e..08a26e93352 100644--- a/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb+++ b/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb@@ -48,6 +48,26 @@ module Pagesclick_on typeend++ def expect_having_create_item(type)+ wait_for_network_idle++ click_button "Add"++ click_button "Project attribute"++ expect(page).to have_link(type)+ end++ def expect_not_having_create_item(type)+ wait_for_network_idle++ click_button "Add"++ click_button "Project attribute"++ expect(page).to have_no_link(type)+ endendendend