BigW Consortium Gitlab

Commit 4fbbb8e7 by Jack Davison

Truncates 9-10 users with current user in front

* If the current user is not in the list output will have 1-9 users * If the current user is in the list output will be "me, " + 0-9 users
parent bcdc3694
...@@ -114,10 +114,14 @@ module IssuesHelper ...@@ -114,10 +114,14 @@ module IssuesHelper
end end
def award_user_list(awards, current_user) def award_user_list(awards, current_user)
names = awards.first(10).map do |award| names = awards.map do |award|
award.user == current_user ? 'me' : award.user.name award.user == current_user ? 'me' : award.user.name
end end
# Take first 9 OR current user + first 9
current_user_name = names.delete('me')
names = names.first(9).insert(0, current_user_name).compact
names << "and #{awards.size - names.size} more." if awards.size > names.size names << "and #{awards.size - names.size} more." if awards.size > names.size
names.join(', ') names.join(', ')
......
...@@ -65,16 +65,26 @@ describe IssuesHelper do ...@@ -65,16 +65,26 @@ describe IssuesHelper do
describe '#award_user_list' do describe '#award_user_list' do
let!(:awards) { build_list(:award_emoji, 15) } let!(:awards) { build_list(:award_emoji, 15) }
it "returns a comma seperated list of 1-10 users" do it "returns a comma seperated list of 1-9 users" do
expect(award_user_list(awards.first(10), nil)).to eq(awards.first(10).map { |a| a.user.name }.join(', ')) expect(award_user_list(awards.first(9), nil)).to eq(awards.first(9).map { |a| a.user.name }.join(', '))
end end
it "displays the current user's name as 'me'" do it "displays the current user's name as 'me'" do
expect(award_user_list(awards.first(1), awards[0].user)).to eq('me') expect(award_user_list(awards.first(1), awards[0].user)).to eq('me')
end end
it "truncates lists of larger than 10 users" do it "truncates lists of larger than 9 users" do
expect(award_user_list(awards, nil)).to eq(awards.first(10).map { |a| a.user.name }.join(', ') + ", and 5 more.") expect(award_user_list(awards, nil)).to eq(awards.first(9).map { |a| a.user.name }.join(', ') + ", and 6 more.")
end
it "displays the current user in front of 0-9 other users" do
expect(award_user_list(awards, awards[0].user)).
to eq("me, " + awards[1..9].map { |a| a.user.name }.join(', ') + ", and 5 more.")
end
it "displays the current user in front regardless of position in the list" do
expect(award_user_list(awards, awards[12].user)).
to eq("me, " + awards[0..8].map { |a| a.user.name }.join(', ') + ", and 5 more.")
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment