Commit 3bf36298 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix duplicate author showing up in autocomplete

The author was already turned into a hash before calling uniq so the
duplicates weren't filtered out.

This also adds the status preloading to the author so that it's included
when we batch load user statuses.
parent ba7126ef
......@@ -13,7 +13,9 @@ module Users
def noteable_owner
return [] unless noteable && noteable.author.present?
[user_as_hash(noteable.author)]
[noteable.author].tap do |users|
preload_status(users)
end
end
def participants_in_noteable
......
......@@ -4,17 +4,20 @@ require 'spec_helper'
RSpec.describe Projects::ParticipantsService do
describe '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:noteable) { create(:issue, project: project) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:noteable) { create(:issue, project: project) }
before_all do
project.add_developer(user)
end
def run_service
described_class.new(project, user).execute(noteable)
end
context 'N+1 checks' do
before do
project.add_developer(user)
run_service # warmup, runs table cache queries and create queries
BatchLoader::Executor.clear_current
end
......@@ -44,6 +47,13 @@ RSpec.describe Projects::ParticipantsService do
expect { run_service }.not_to exceed_query_limit(control_count)
end
end
it 'does not return duplicate author' do
participants = run_service
expect(participants.count { |p| p[:username] == noteable.author.username }).to eq 1
end
describe 'group items' do
subject(:group_items) { run_service.select { |hash| hash[:type].eql?('Group') } }
......
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