Commit ec555fbe authored by Sean McGivern's avatar Sean McGivern Committed by Bryce Johnson

Add specs for issues#service_desk action

parent 1b3bb52a
......@@ -10,6 +10,24 @@ module IssuableCollections
private
def set_issues_index
@collection_type = "Issue"
@issues = issues_collection
@issues = @issues.page(params[:page])
@issuable_meta_data = issuable_meta_data(@issues, @collection_type)
if @issues.out_of_range? && @issues.total_pages != 0
return redirect_to url_for(params.merge(page: @issues.total_pages, only_path: true))
end
if params[:label_name].present?
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute
end
@users = []
end
def issues_collection
issues_finder.execute.preload(:project, :author, :assignees, :labels, :milestone, project: :namespace)
end
......
......@@ -25,21 +25,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to :html
def index
@collection_type = "Issue"
@issues = issues_collection
@issues = @issues.page(params[:page])
@issuable_meta_data = issuable_meta_data(@issues, @collection_type)
if @issues.out_of_range? && @issues.total_pages != 0
return redirect_to url_for(params.merge(page: @issues.total_pages, only_path: true))
end
if params[:label_name].present?
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute
end
@users = []
set_issues_index
if params[:assignee_id].present?
assignee = User.find_by_id(params[:assignee_id])
......
......@@ -10,21 +10,7 @@ module EE
end
def service_desk
@collection_type = "Issue"
@issues = issues_collection
@issues = @issues.page(params[:page])
@issuable_meta_data = issuable_meta_data(@issues, @collection_type)
if @issues.out_of_range? && @issues.total_pages != 0
return redirect_to url_for(params.merge(page: @issues.total_pages, only_path: true))
end
if params[:label_name].present?
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute
end
@users = []
set_issues_index
if params[:assignee_id].present?
assignee = User.find_by_id(params[:assignee_id])
......@@ -54,7 +40,7 @@ module EE
params = super
params.reject! { |key| key == 'weight' } unless project.feature_available?(:issue_weights)
if action_name == 'service_desk'
if service_desk?
params.reject! { |key| key == 'author_username' || key == 'author_id' }
params[:author_id] = ::User.support_bot
end
......@@ -62,8 +48,8 @@ module EE
params
end
def self.skip_issue_actions
super + [:service_desk]
def service_desk?
action_name == 'service_desk'
end
end
end
......
require 'spec_helper'
describe Projects::IssuesController do
let(:project) { create(:project, :public) }
describe 'GET service_desk' do
def get_service_desk(extra_params = {})
get :service_desk, extra_params.merge(namespace_id: project.namespace, project_id: project)
end
context 'when Service Desk is available on the project' do
let(:support_bot) { User.support_bot }
let(:other_user) { create(:user) }
let!(:service_desk_issue_1) { create(:issue, project: project, author: support_bot) }
let!(:service_desk_issue_2) { create(:issue, project: project, author: support_bot, assignees: [other_user]) }
let!(:other_user_issue) { create(:issue, project: project, author: other_user) }
before do
stub_licensed_features(service_desk: true)
end
it 'adds an author filter for the support bot user' do
get_service_desk
expect(assigns(:issues)).to contain_exactly(service_desk_issue_1, service_desk_issue_2)
end
it 'does not allow any other author to be set' do
get_service_desk(author_username: other_user.username)
expect(assigns(:issues)).to contain_exactly(service_desk_issue_1, service_desk_issue_2)
end
it 'supports other filters' do
get_service_desk(assignee_username: other_user.username)
expect(assigns(:issues)).to contain_exactly(service_desk_issue_2)
end
end
context 'when Service Desk is not available on the project' do
before do
stub_licensed_features(service_desk: false)
end
it 'returns a 404' do
get_service_desk
expect(response).to have_http_status(404)
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