From 317c3883477c1af3db96fdbd7caeed46ceb67d72 Mon Sep 17 00:00:00 2001
From: Alex Sanford <alex.sanford1@gmail.com>
Date: Thu, 10 Nov 2016 20:04:28 -0400
Subject: [PATCH] Ensure labels are loaded on "show" methods of MR

Previously, they were only being loaded on the actual `show` action, but
not the actions representing the tabs (commits, builds, etc).
---
 .../projects/merge_requests_controller.rb     |  1 +
 .../24397-load-labels-on-mr-tabs.yml          |  4 +++
 .../merge_requests_controller_spec.rb         | 25 +++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100644 changelogs/unreleased/24397-load-labels-on-mr-tabs.yml

diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 9f104d903cc..dff0213411c 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -507,6 +507,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
       @merge_request.close
     end
 
+    labels
     define_pipelines_vars
   end
 
diff --git a/changelogs/unreleased/24397-load-labels-on-mr-tabs.yml b/changelogs/unreleased/24397-load-labels-on-mr-tabs.yml
new file mode 100644
index 00000000000..6bfa7fa1a49
--- /dev/null
+++ b/changelogs/unreleased/24397-load-labels-on-mr-tabs.yml
@@ -0,0 +1,4 @@
+---
+title: Fix issue causing Labels not to appear in sidebar on MR page
+merge_request: 7416
+author: Alex Sanford
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 49127aecc63..1d0750d1719 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -39,6 +39,17 @@ describe Projects::MergeRequestsController do
     end
   end
 
+  shared_examples "loads labels" do |action|
+    it "loads labels into the @labels variable" do
+      get action,
+          namespace_id: project.namespace.to_param,
+          project_id: project.to_param,
+          id: merge_request.iid,
+          format: 'html'
+      expect(assigns(:labels)).not_to be_nil
+    end
+  end
+
   describe "GET show" do
     shared_examples "export merge as" do |format|
       it "does generally work" do
@@ -51,6 +62,8 @@ describe Projects::MergeRequestsController do
         expect(response).to be_success
       end
 
+      it_behaves_like "loads labels", :show
+
       it "generates it" do
         expect_any_instance_of(MergeRequest).to receive(:"to_#{format}")
 
@@ -406,6 +419,8 @@ describe Projects::MergeRequestsController do
       get :diffs, params.merge(extra_params)
     end
 
+    it_behaves_like "loads labels", :diffs
+
     context 'with default params' do
       context 'as html' do
         before { go(format: 'html') }
@@ -612,6 +627,8 @@ describe Projects::MergeRequestsController do
           format: format
     end
 
+    it_behaves_like "loads labels", :commits
+
     context 'as html' do
       it 'renders the show template' do
         go
@@ -630,6 +647,14 @@ describe Projects::MergeRequestsController do
     end
   end
 
+  describe 'GET builds' do
+    it_behaves_like "loads labels", :builds
+  end
+
+  describe 'GET pipelines' do
+    it_behaves_like "loads labels", :pipelines
+  end
+
   describe 'GET conflicts' do
     let(:json_response) { JSON.parse(response.body) }
 
-- 
GitLab