Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 18:08:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 18:08:44 +0300
commitbcc77054ee9aefd1e332e04a4189390fd5a3112e (patch)
treee6e1908c310e4733038794e932196cae0d66ba9a /spec/models
parent05b5c609cb8c260b10c2eb1b92b711dc82d32c3f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/container_expiration_policy_spec.rb4
-rw-r--r--spec/models/incident_management/project_incident_management_setting_spec.rb111
2 files changed, 113 insertions, 2 deletions
diff --git a/spec/models/container_expiration_policy_spec.rb b/spec/models/container_expiration_policy_spec.rb
index 1bce4c3b20a..c22362ed5d4 100644
--- a/spec/models/container_expiration_policy_spec.rb
+++ b/spec/models/container_expiration_policy_spec.rb
@@ -49,9 +49,9 @@ RSpec.describe ContainerExpirationPolicy, type: :model do
it 'preloads the associations' do
subject
- query = ActiveRecord::QueryRecorder.new { subject.each(&:project) }
+ query = ActiveRecord::QueryRecorder.new { subject.map(&:project).map(&:full_path) }
- expect(query.count).to eq(2)
+ expect(query.count).to eq(3)
end
end
diff --git a/spec/models/incident_management/project_incident_management_setting_spec.rb b/spec/models/incident_management/project_incident_management_setting_spec.rb
new file mode 100644
index 00000000000..ac3f97e2d89
--- /dev/null
+++ b/spec/models/incident_management/project_incident_management_setting_spec.rb
@@ -0,0 +1,111 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe IncidentManagement::ProjectIncidentManagementSetting do
+ let_it_be(:project) { create(:project, :repository, create_templates: :issue) }
+
+ describe 'Associations' do
+ it { is_expected.to belong_to(:project) }
+ end
+
+ describe 'Validations' do
+ describe 'validate issue_template_exists' do
+ subject { build(:project_incident_management_setting, project: project) }
+
+ context 'with create_issue enabled' do
+ before do
+ subject.create_issue = true
+ end
+
+ context 'with valid issue_template_key' do
+ before do
+ subject.issue_template_key = 'bug'
+ end
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'with empty issue_template_key' do
+ before do
+ subject.issue_template_key = ''
+ end
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'with nil issue_template_key' do
+ before do
+ subject.issue_template_key = nil
+ end
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'with invalid issue_template_key' do
+ before do
+ subject.issue_template_key = 'unknown'
+ end
+
+ it { is_expected.to be_invalid }
+
+ it 'returns error' do
+ subject.valid?
+
+ expect(subject.errors[:issue_template_key]).to eq(['not found'])
+ end
+ end
+ end
+
+ context 'with create_issue disabled' do
+ before do
+ subject.create_issue = false
+ end
+
+ context 'with unknown issue_template_key' do
+ before do
+ subject.issue_template_key = 'unknown'
+ end
+
+ it { is_expected.to be_valid }
+ end
+ end
+ end
+ end
+
+ describe '#issue_template_content' do
+ subject { build(:project_incident_management_setting, project: project) }
+
+ shared_examples 'no content' do
+ it 'returns no content' do
+ expect(subject.issue_template_content).to be_nil
+ end
+ end
+
+ context 'with valid issue_template_key' do
+ before do
+ subject.issue_template_key = 'bug'
+ end
+
+ it 'returns issue content' do
+ expect(subject.issue_template_content).to eq('something valid')
+ end
+ end
+
+ context 'with unknown issue_template_key' do
+ before do
+ subject.issue_template_key = 'unknown'
+ end
+
+ it_behaves_like 'no content'
+ end
+
+ context 'without issue_template_key' do
+ before do
+ subject.issue_template_key = nil
+ end
+
+ it_behaves_like 'no content'
+ end
+ end
+end