-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16762 from opf/bug/57577-broken-ordering-by-multi…
…-value-custom-fields Bug/57577 broken ordering by multi value custom fields
- Loading branch information
Showing
4 changed files
with
241 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,21 +58,26 @@ def project_without_cf_value | |
|
||
before { projects } | ||
|
||
project_attributes = ->(project) do | ||
{ | ||
id: project.id, | ||
values: project.custom_values.map(&:value).sort | ||
} | ||
end | ||
|
||
context "in ascending order" do | ||
let(:direction) { :asc } | ||
|
||
it "returns the correctly sorted result" do | ||
expect(query_results.map(&:id)) | ||
.to eq projects.map(&:id) | ||
expect(query_results).to eq_array(projects, &project_attributes) | ||
end | ||
end | ||
|
||
context "in descending order" do | ||
let(:direction) { :desc } | ||
|
||
it "returns the correctly sorted result" do | ||
expect(query_results.map(&:id)) | ||
.to eq projects_desc.map(&:id) | ||
expect(query_results).to eq_array(projects_desc, &project_attributes) | ||
end | ||
end | ||
end | ||
|
@@ -188,28 +193,39 @@ def project_without_cf_value | |
|
||
let(:projects) do | ||
[ | ||
project_without_cf_value, | ||
# TODO: sorting is done by values sorted by position and joined by `.`, why? | ||
project_with_cf_value(*id_by_value.fetch_values("100")), # => 100 | ||
project_with_cf_value(*id_by_value.fetch_values("20", "100")), # => 100.20 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "100")), # => 100.3 | ||
project_with_cf_value(*id_by_value.fetch_values("100", "3", "20")), # => 100.3.20 | ||
project_with_cf_value(*id_by_value.fetch_values("20")), # => 20 | ||
project_with_cf_value(*id_by_value.fetch_values("3")), # => 3 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "20")) # => 3.20 | ||
project_with_cf_value(*id_by_value.fetch_values("100")), # 100 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "100")), # 100, 3 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "20", "100")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "100", "20")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("20", "3", "100")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("20", "100", "3")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("100", "3", "20")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("100", "20", "3")), # 100, 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("20", "100")), # 100, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("3")), # 3 | ||
project_with_cf_value(*id_by_value.fetch_values("3", "20")), # 3, 20 | ||
project_with_cf_value(*id_by_value.fetch_values("20")), # 20 | ||
project_without_cf_value # TODO: decide on order of absent values | ||
] | ||
end | ||
|
||
let(:projects_desc) do | ||
indexes = projects.each_index.to_a | ||
# order of values for a work package is ignored, so ordered by falling back on id asc | ||
indexes[2...8] = indexes[2...8].reverse | ||
projects.values_at(*indexes.reverse) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "for user format" do | ||
shared_let(:users) do | ||
[ | ||
create(:user, lastname: "B", firstname: "B", login: "bb1"), | ||
create(:user, lastname: "B", firstname: "B", login: "bb2"), | ||
create(:user, lastname: "B", firstname: "A", login: "ba"), | ||
create(:user, lastname: "A", firstname: "X", login: "ax") | ||
create(:user, lastname: "B", firstname: "B", login: "bb1", mail: "[email protected]"), | ||
create(:user, lastname: "B", firstname: "B", login: "bb2", mail: "[email protected]"), | ||
create(:user, lastname: "B", firstname: "A", login: "ba", mail: "[email protected]"), | ||
create(:user, lastname: "A", firstname: "X", login: "ax", mail: "[email protected]") | ||
] | ||
end | ||
shared_let(:id_by_login) { users.to_h { [_1.login, _1.id] } } | ||
|
@@ -256,11 +272,12 @@ def project_without_cf_value | |
|
||
let(:custom_field_values) do | ||
[ | ||
id_by_login.fetch_values("ax"), | ||
id_by_login.fetch_values("ba"), | ||
# TODO: second user is ignored | ||
id_by_login.fetch_values("bb1", "ba"), | ||
id_by_login.fetch_values("bb1", "ax"), | ||
id_by_login.fetch_values("ax"), # ax | ||
id_by_login.fetch_values("bb1", "ax"), # ax, bb1 | ||
id_by_login.fetch_values("ax", "bb1"), # ax, bb1 | ||
id_by_login.fetch_values("ba"), # ba | ||
id_by_login.fetch_values("bb1", "ba"), # ba, bb1 | ||
id_by_login.fetch_values("ba", "bb2"), # ba, bb2 | ||
[] # TODO: should be at index 0 | ||
] | ||
end | ||
|
@@ -271,8 +288,12 @@ def project_without_cf_value | |
end | ||
end | ||
|
||
# TODO: second user is ignored, so order due to falling back on id asc | ||
let(:projects_desc) { projects.values_at(4, 2, 3, 1, 0) } | ||
let(:projects_desc) do | ||
indexes = projects.each_index.to_a | ||
# order of values for a work package is ignored, so ordered by falling back on id asc | ||
indexes[1...3] = indexes[1...3].reverse | ||
projects.values_at(*indexes.reverse) | ||
end | ||
end | ||
end | ||
end | ||
|
@@ -311,17 +332,22 @@ def project_without_cf_value | |
|
||
let(:projects) do | ||
[ | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.10")), | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.2")), | ||
# TODO: second version is ignored | ||
project_with_cf_value(*id_by_name.fetch_values("9", "10.10.2")), | ||
project_with_cf_value(*id_by_name.fetch_values("9", "10.10.10")), | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.10")), # 10.10.10 | ||
project_with_cf_value(*id_by_name.fetch_values("9", "10.10.10")), # 10.10.10, 9 | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.10", "9")), # 10.10.10, 9 | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.2")), # 10.10.2 | ||
project_with_cf_value(*id_by_name.fetch_values("10.2", "10.10.2")), # 10.10.2, 10.2 | ||
project_with_cf_value(*id_by_name.fetch_values("10.10.2", "9")), # 10.10.2, 9 | ||
project # TODO: should be at index 0 | ||
] | ||
end | ||
|
||
# TODO: second version is ignored, so order due to falling back on id asc | ||
let(:projects_desc) { projects.values_at(4, 2, 3, 1, 0) } | ||
let(:projects_desc) do | ||
indexes = projects.each_index.to_a | ||
# order of values for a work package is ignored, so ordered by falling back on id asc | ||
indexes[1...3] = indexes[1...3].reverse | ||
projects.values_at(*indexes.reverse) | ||
end | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.