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 specs

Dombi Attila486ce0c96bc5
diff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rb
index 43e84daa00b..836361c992d 100644
--- a/lib/custom_field_form_builder.rb
+++ b/lib/custom_field_form_builder.rb
@@ -96,7 +96,11 @@ class CustomFieldFormBuilder < TabularFormBuilder
selected_options = Array(selected).map(&:value)
if custom_field.version?
- template.grouped_options_for_select(options.group_by(&:last).to_a, selected_options)
+ grouped_options = Hash.new { |hsh, key| hsh[key] = [] }
+ options.each do |label, value, group_key|
+ grouped_options[group_key] << [label, value]
+ end
+ template.grouped_options_for_select(grouped_options, selected_options)
else
template.options_for_select(options, selected_options)
end
diff --git a/spec/lib/custom_field_form_builder_spec.rb b/spec/lib/custom_field_form_builder_spec.rb
index f5563b63efa..4eac6fc9a78 100644
--- a/spec/lib/custom_field_form_builder_spec.rb
+++ b/spec/lib/custom_field_form_builder_spec.rb
@@ -339,7 +339,7 @@ RSpec.describe CustomFieldFormBuilder do
.and_return(scope)
allow(scope)
- .to receive(:includes)
+ .to receive(:references)
.and_return([version1, version2])
end
end
@@ -355,8 +355,12 @@ RSpec.describe CustomFieldFormBuilder do
name="user[#{custom_field.id}]"
no_label="true">
<option value="" label=" "></option>
- <option value="#{version1.id}">#{version1.name}</option>
- <option value="#{version2.id}">#{version2.name}</option>
+ <optgroup label="#{version1.project.name}">
+ <option value="#{version1.id}">#{version1.name}</option>
+ </optgroup>
+ <optgroup label="#{version2.project.name}">
+ <option value="#{version2.id}">#{version2.name}</option>
+ </optgroup>
</select>
}).at_path("select")
end
@@ -373,8 +377,12 @@ RSpec.describe CustomFieldFormBuilder do
name="user[#{custom_field.id}]"
no_label="true">
<option value="">--- Please select ---</option>
- <option value="#{version1.id}">#{version1.name}</option>
- <option value="#{version2.id}">#{version2.name}</option>
+ <optgroup label="#{version1.project.name}">
+ <option value="#{version1.id}">#{version1.name}</option>
+ </optgroup>
+ <optgroup label="#{version2.project.name}">
+ <option value="#{version2.id}">#{version2.name}</option>
+ </optgroup>
</select>
}).at_path("select")
end
diff --git a/spec/models/custom_actions/actions/custom_field_spec.rb b/spec/models/custom_actions/actions/custom_field_spec.rb
index 04ec6aaf8ce..644856e5988 100644
--- a/spec/models/custom_actions/actions/custom_field_spec.rb
+++ b/spec/models/custom_actions/actions/custom_field_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -110,7 +112,7 @@ RSpec.describe CustomActions::Actions::CustomField do
expect(described_class.all.map(&:custom_field))
.to match_array(custom_fields)
- described_class.all.each do |subclass|
+ described_class.find_each do |subclass|
expect(subclass.ancestors).to include(described_class)
end
end
@@ -408,7 +410,8 @@ RSpec.describe CustomActions::Actions::CustomField do
before do
allow(scope)
- .to receive(:includes)
+ .to receive(:references)
+ .with(:project)
.and_return(versions)
allow(Version)
@@ -555,7 +558,8 @@ RSpec.describe CustomActions::Actions::CustomField do
before do
allow(scope)
- .to receive(:includes)
+ .to receive(:references)
+ .with(:project)
.and_return(versions)
allow(Version)
@@ -577,8 +581,8 @@ RSpec.describe CustomActions::Actions::CustomField do
it_behaves_like "bool custom action validations" do
let(:allowed_values) do
[
- { true: OpenProject::Database::DB_VALUE_TRUE },
- { false: OpenProject::Database::DB_VALUE_FALSE }
+ { true => OpenProject::Database::DB_VALUE_TRUE },
+ { false => OpenProject::Database::DB_VALUE_FALSE }
]
end
end
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index 51b4e378f5b..56dde15fad2 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -156,7 +158,7 @@ RSpec.describe CustomField do
it "is not valid" do
expect(field)
- .to be_invalid
+ .not_to be_valid
end
end
@@ -295,7 +297,7 @@ RSpec.describe CustomField do
before do
field.field_format = "version"
allow(shared_versions_scope)
- .to receive(:includes)
+ .to receive(:references)
.with(:project)
.and_return(versions)
end