Commit 7a525004 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Preload user status for label events

This makes sure the user_status for the user of a label event is
preloaded. Otherwise it would not be rendered in the fake system note.
parent 9e6098a6
...@@ -34,7 +34,7 @@ module ResourceEvents ...@@ -34,7 +34,7 @@ module ResourceEvents
def label_events_by_discussion_id def label_events_by_discussion_id
return [] unless resource.respond_to?(:resource_label_events) return [] unless resource.respond_to?(:resource_label_events)
events = resource.resource_label_events.includes(:label, :user) events = resource.resource_label_events.includes(:label, user: :status)
events = since_fetch_at(events) events = since_fetch_at(events)
events.group_by { |event| event.discussion_id } events.group_by { |event| event.discussion_id }
......
---
title: Show user status for label events in system notes
merge_request: 22609
author:
type: fixed
...@@ -7,6 +7,7 @@ describe 'List issue resource label events', :js do ...@@ -7,6 +7,7 @@ describe 'List issue resource label events', :js do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project, author: user) } let(:issue) { create(:issue, project: project, author: user) }
let!(:label) { create(:label, project: project, title: 'foo') } let!(:label) { create(:label, project: project, title: 'foo') }
let!(:user_status) { create(:user_status, user: user) }
context 'when user displays the issue' do context 'when user displays the issue' do
let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue, note: 'some note') } let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue, note: 'some note') }
...@@ -23,6 +24,12 @@ describe 'List issue resource label events', :js do ...@@ -23,6 +24,12 @@ describe 'List issue resource label events', :js do
expect(find("#note_#{event.discussion_id}")).to have_content 'added foo label' expect(find("#note_#{event.discussion_id}")).to have_content 'added foo label'
end end
end end
it 'shows the user status on the system note for the label' do
page.within("#note_#{event.discussion_id}") do
expect(page).to show_user_status user_status
end
end
end end
context 'when user adds label to the issue' do context 'when user adds label to the issue' do
......
...@@ -66,5 +66,14 @@ describe ResourceEvents::MergeIntoNotesService do ...@@ -66,5 +66,14 @@ describe ResourceEvents::MergeIntoNotesService do
expect(notes.count).to eq 1 expect(notes.count).to eq 1
expect(notes.first.discussion_id).to eq event.discussion_id expect(notes.first.discussion_id).to eq event.discussion_id
end end
it "preloads the note author's status" do
event = create_event(created_at: time)
create(:user_status, user: event.user)
notes = described_class.new(resource, user).execute
expect(notes.first.author.association(:status)).to be_loaded
end
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