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

Fix flaky spec

Christophe Bliard2ac9ac9e9b81
diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rb
index 9ea6044bdf6..266e669d5e2 100644
--- a/spec/services/work_packages/update_service_integration_spec.rb
+++ b/spec/services/work_packages/update_service_integration_spec.rb
@@ -64,7 +64,7 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model do
set_factory_default(:user, user)
end
- shared_let(:work_package, refind: true, reload: false) do
+ let(:work_package) do
create(:work_package,
subject: "work_package")
end
diff --git a/spec/support/table_helpers/table_data.rb b/spec/support/table_helpers/table_data.rb
index e30841aa879..409c50f4ff7 100644
--- a/spec/support/table_helpers/table_data.rb
+++ b/spec/support/table_helpers/table_data.rb
@@ -143,6 +143,7 @@ module TableHelpers
end
def create
+ warn_for_existing_work_packages_with_same_identifier
table_data.work_package_identifiers.each do |identifier|
create_work_package(identifier)
end
@@ -153,6 +154,18 @@ module TableHelpers
[work_packages_by_identifier, relations]
end
+ def warn_for_existing_work_packages_with_same_identifier
+ existing_identifiers = WorkPackage.pluck(:subject).map { |subject| to_identifier(subject) }
+ identical_identifiers = existing_identifiers & table_data.work_package_identifiers
+ if identical_identifiers.any?
+ puts <<~MESSAGE
+ [let_work_packages] Warning: existing work packages with identical identifiers found: #{identical_identifiers.map(&:inspect).join(', ')}
+ [let_work_packages] This can cause failures when checking work package with `expect_work_packages(WorkPackage.all)`."
+ [let_work_packages] Current example is #{RSpec.current_example.description.inspect} at #{RSpec.current_example.location}
+ MESSAGE
+ end
+ end
+
def create_work_package(identifier)
@work_packages_by_identifier[identifier] ||= begin
attributes = work_package_attributes(identifier)