Commit 1370189e authored by Stan Hu's avatar Stan Hu

Merge branch '294155-improve-issues-controller' into 'master'

Improve jira issues controller and specs

See merge request gitlab-org/gitlab!51581
parents c38014d1 b420f4d7
......@@ -34,8 +34,11 @@ module Projects
private
def issues_json
jira_issues = finder.execute
jira_issues = Kaminari.paginate_array(jira_issues, limit: finder.per_page, total_count: finder.total_count)
jira_issues = Kaminari.paginate_array(
finder.execute,
limit: finder.per_page,
total_count: finder.total_count
)
::Integrations::Jira::IssueSerializer.new
.with_pagination(request, response)
......@@ -43,11 +46,7 @@ module Projects
end
def finder
@finder ||= finder_type.new(project, finder_options)
end
def finder_type
::Projects::Integrations::Jira::IssuesFinder
@finder ||= ::Projects::Integrations::Jira::IssuesFinder.new(project, finder_options)
end
def finder_options
......@@ -56,7 +55,7 @@ module Projects
# Used by view to highlight active option
@sort = options[:sort]
params.permit(finder_type.valid_params).merge(options)
params.permit(::Projects::Integrations::Jira::IssuesFinder.valid_params).merge(options)
end
def default_state
......@@ -74,7 +73,7 @@ module Projects
protected
def check_feature_enabled!
return render_404 unless project.jira_issues_integration_available? && project.external_issue_tracker
return render_404 unless project.jira_issues_integration_available? && project.jira_service.issues_enabled
end
# Return the informational message to the user
......
......@@ -5,30 +5,32 @@ require 'spec_helper'
RSpec.describe Projects::Integrations::Jira::IssuesController do
include ProjectForksHelper
let(:project) { create(:project) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
let_it_be(:jira) { create(:jira_service, project: project, issues_enabled: true, project_key: 'TEST') }
before do
stub_licensed_features(jira_issues_integration: true)
sign_in(user)
end
describe 'GET #index' do
before do
sign_in(user)
project.add_developer(user)
create(:jira_service, project: project)
end
context 'when jira_issues_integration licensed feature is not available' do
it 'returns 404 status' do
before do
stub_licensed_features(jira_issues_integration: false)
end
it 'returns 404 status' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
end
end
it_behaves_like 'unauthorized when external service denies access' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
end
it 'renders the "index" template' do
get :index, params: { namespace_id: project.namespace, project_id: project }
......@@ -48,7 +50,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'redirects to the new issue tracker from the old one' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to(project_integrations_jira_issues_path(new_project))
expect(response).to redirect_to(Gitlab::Routing.url_helpers.project_integrations_jira_issues_path(new_project))
expect(response).to have_gitlab_http_status(:moved_permanently)
end
end
......@@ -170,16 +172,4 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
end
end
end
context 'external authorization' do
before do
sign_in user
project.add_developer(user)
create(:jira_service, project: project)
end
it_behaves_like 'unauthorized when external service denies access' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
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