From 7a525004a7c9fa7b5a4d11ec5f8bf7854519178c Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 25 Oct 2018 18:12:12 +0200 Subject: [PATCH] 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. --- app/services/resource_events/merge_into_notes_service.rb | 2 +- .../unreleased/bvl-preload-user-status-for-events.yml | 5 +++++ spec/features/issues/resource_label_events_spec.rb | 7 +++++++ .../resource_events/merge_into_notes_service_spec.rb | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/bvl-preload-user-status-for-events.yml diff --git a/app/services/resource_events/merge_into_notes_service.rb b/app/services/resource_events/merge_into_notes_service.rb index 596c0105ea0..7504773a002 100644 --- a/app/services/resource_events/merge_into_notes_service.rb +++ b/app/services/resource_events/merge_into_notes_service.rb @@ -34,7 +34,7 @@ module ResourceEvents def label_events_by_discussion_id 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.group_by { |event| event.discussion_id } diff --git a/changelogs/unreleased/bvl-preload-user-status-for-events.yml b/changelogs/unreleased/bvl-preload-user-status-for-events.yml new file mode 100644 index 00000000000..e13b19b19c1 --- /dev/null +++ b/changelogs/unreleased/bvl-preload-user-status-for-events.yml @@ -0,0 +1,5 @@ +--- +title: Show user status for label events in system notes +merge_request: 22609 +author: +type: fixed diff --git a/spec/features/issues/resource_label_events_spec.rb b/spec/features/issues/resource_label_events_spec.rb index 40c452c991a..b0764db7751 100644 --- a/spec/features/issues/resource_label_events_spec.rb +++ b/spec/features/issues/resource_label_events_spec.rb @@ -7,6 +7,7 @@ describe 'List issue resource label events', :js do let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project, author: user) } let!(:label) { create(:label, project: project, title: 'foo') } + let!(:user_status) { create(:user_status, user: user) } context 'when user displays the issue' do 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 expect(find("#note_#{event.discussion_id}")).to have_content 'added foo label' 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 context 'when user adds label to the issue' do diff --git a/spec/services/resource_events/merge_into_notes_service_spec.rb b/spec/services/resource_events/merge_into_notes_service_spec.rb index 0d333d541c9..c76f6e6f77e 100644 --- a/spec/services/resource_events/merge_into_notes_service_spec.rb +++ b/spec/services/resource_events/merge_into_notes_service_spec.rb @@ -66,5 +66,14 @@ describe ResourceEvents::MergeIntoNotesService do expect(notes.count).to eq 1 expect(notes.first.discussion_id).to eq event.discussion_id 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