Skip to content

Commit 31b0b39

Browse files
committed
Sort roles/groups (numerically by id) with space separator
1 parent 94eb81f commit 31b0b39

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

app/helpers/report_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def visibility_options(widget)
3030
if values.first == "_ALL_"
3131
_("To All Users")
3232
else
33-
display_values = widget.visibility_values.join(',')
33+
display_values = widget.visibility_values.sort.join(', ')
3434
_("By %{typ}: %{values}") % {:typ => typ.to_s.titleize, :values => display_values}
3535
end
3636
end

spec/helpers/report_helper_spec.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,36 @@ def create_and_generate_report_for_user(report_name, user)
7575
expect(helper.visibility_options(widget)).to eq('To All Users')
7676
end
7777

78-
it 'converts role IDs to role names for display' do
78+
it 'converts role IDs to role names and sorts alphabetically by name' do
7979
widget = FactoryBot.create(:miq_widget, :visibility => {:roles => [role1.id, role2.id]})
8080
result = helper.visibility_options(widget)
81-
expect(result).to include('EvmRole-auditor')
82-
expect(result).to include('EvmRole-desktop')
83-
expect(result).to include('By Roles:')
81+
expect(result).to eq('By Roles: EvmRole-auditor, EvmRole-desktop')
8482
end
8583

86-
it 'converts group IDs to group descriptions for display' do
84+
it 'sorts role names alphabetically regardless of ID order' do
85+
role3 = FactoryBot.create(:miq_user_role, :name => 'EvmRole-zebra')
86+
role4 = FactoryBot.create(:miq_user_role, :name => 'EvmRole-alpha')
87+
widget = FactoryBot.create(:miq_widget, :visibility => {:roles => [role3.id, role4.id]})
88+
result = helper.visibility_options(widget)
89+
# IDs are in order [zebra, alpha] but output should be alphabetically sorted
90+
expect(result).to eq('By Roles: EvmRole-alpha, EvmRole-zebra')
91+
end
92+
93+
it 'converts group IDs to group descriptions and sorts alphabetically by description' do
8794
group1 = FactoryBot.create(:miq_group, :description => 'Group1')
8895
group2 = FactoryBot.create(:miq_group, :description => 'Group2')
8996
widget = FactoryBot.create(:miq_widget, :visibility => {:groups => [group1.id, group2.id]})
9097
result = helper.visibility_options(widget)
91-
expect(result).to include('Group1')
92-
expect(result).to include('Group2')
93-
expect(result).to include('By Groups:')
98+
expect(result).to eq('By Groups: Group1, Group2')
99+
end
100+
101+
it 'sorts group descriptions alphabetically regardless of ID order' do
102+
group3 = FactoryBot.create(:miq_group, :description => 'Zebra Group')
103+
group4 = FactoryBot.create(:miq_group, :description => 'Alpha Group')
104+
widget = FactoryBot.create(:miq_widget, :visibility => {:groups => [group3.id, group4.id]})
105+
result = helper.visibility_options(widget)
106+
# IDs are in order [Zebra, Alpha] but output should be alphabetically sorted
107+
expect(result).to eq('By Groups: Alpha Group, Zebra Group')
94108
end
95109
end
96110
end

0 commit comments

Comments
 (0)