Commit 79e06e39 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch '228634-validate-project-key-presence-if-issues-enabled' into 'master'

Validate project key presence if Jira issues enabled

See merge request gitlab-org/gitlab!36717
parents 2c8d304e 5b22e2d8
......@@ -440,3 +440,5 @@ class JiraService < IssueTrackerService
end
end
end
JiraService.prepend_if_ee('EE::JiraService')
# frozen_string_literal: true
module EE
module JiraService
extend ActiveSupport::Concern
prepended do
validates :project_key, presence: true, if: :issues_enabled
end
end
end
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'Jira issues list' do
let_it_be(:project, refind: true) { create(:project) }
let_it_be(:jira_integration) { create(:jira_service, project: project, issues_enabled: true) }
let_it_be(:jira_integration) { create(:jira_service, project: project, issues_enabled: true, project_key: 'GL') }
let(:user) { create(:user) }
before do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraService do
let(:jira_service) { build(:jira_service) }
describe 'validations' do
it 'validates presence of project_key if issues_enabled' do
jira_service.project_key = ''
jira_service.issues_enabled = true
expect(jira_service).to be_invalid
end
end
end
......@@ -77,13 +77,16 @@ FactoryBot.define do
username { 'jira_username' }
password { 'jira_password' }
jira_issue_transition_id { '56-1' }
issues_enabled { false }
project_key { nil }
end
after(:build) do |service, evaluator|
if evaluator.create_data
create(:jira_tracker_data, service: service,
url: evaluator.url, api_url: evaluator.api_url, jira_issue_transition_id: evaluator.jira_issue_transition_id,
username: evaluator.username, password: evaluator.password
username: evaluator.username, password: evaluator.password, issues_enabled: evaluator.issues_enabled,
project_key: evaluator.project_key
)
end
end
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe JiraTrackerData do
let(:service) { create(:jira_service, active: false) }
let(:service) { build(:jira_service) }
describe 'Associations' do
it { is_expected.to belong_to(:service) }
......
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