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 ...@@ -34,8 +34,11 @@ module Projects
private private
def issues_json def issues_json
jira_issues = finder.execute jira_issues = Kaminari.paginate_array(
jira_issues = Kaminari.paginate_array(jira_issues, limit: finder.per_page, total_count: finder.total_count) finder.execute,
limit: finder.per_page,
total_count: finder.total_count
)
::Integrations::Jira::IssueSerializer.new ::Integrations::Jira::IssueSerializer.new
.with_pagination(request, response) .with_pagination(request, response)
...@@ -43,11 +46,7 @@ module Projects ...@@ -43,11 +46,7 @@ module Projects
end end
def finder def finder
@finder ||= finder_type.new(project, finder_options) @finder ||= ::Projects::Integrations::Jira::IssuesFinder.new(project, finder_options)
end
def finder_type
::Projects::Integrations::Jira::IssuesFinder
end end
def finder_options def finder_options
...@@ -56,7 +55,7 @@ module Projects ...@@ -56,7 +55,7 @@ module Projects
# Used by view to highlight active option # Used by view to highlight active option
@sort = options[:sort] @sort = options[:sort]
params.permit(finder_type.valid_params).merge(options) params.permit(::Projects::Integrations::Jira::IssuesFinder.valid_params).merge(options)
end end
def default_state def default_state
...@@ -74,7 +73,7 @@ module Projects ...@@ -74,7 +73,7 @@ module Projects
protected protected
def check_feature_enabled! 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 end
# Return the informational message to the user # Return the informational message to the user
......
...@@ -5,30 +5,32 @@ require 'spec_helper' ...@@ -5,30 +5,32 @@ require 'spec_helper'
RSpec.describe Projects::Integrations::Jira::IssuesController do RSpec.describe Projects::Integrations::Jira::IssuesController do
include ProjectForksHelper include ProjectForksHelper
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { create(:user) } 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 before do
stub_licensed_features(jira_issues_integration: true) stub_licensed_features(jira_issues_integration: true)
sign_in(user)
end end
describe 'GET #index' do 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 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) stub_licensed_features(jira_issues_integration: false)
end
it 'returns 404 status' do
get :index, params: { namespace_id: project.namespace, project_id: project } get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
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 it 'renders the "index" template' do
get :index, params: { namespace_id: project.namespace, project_id: project } get :index, params: { namespace_id: project.namespace, project_id: project }
...@@ -48,7 +50,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -48,7 +50,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'redirects to the new issue tracker from the old one' do it 'redirects to the new issue tracker from the old one' do
get :index, params: { namespace_id: project.namespace, project_id: project } 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) expect(response).to have_gitlab_http_status(:moved_permanently)
end end
end end
...@@ -170,16 +172,4 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -170,16 +172,4 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
end end
end 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 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