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-03-24 21:07:55 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-24 21:07:55 +0300
commit603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc (patch)
tree907f5b8ee1b6f5aad396e95e3327a08400b9e8ea /spec/models
parent120f4aaedc8fe830a3f572491d240d8ee6addefb (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/job_artifact_spec.rb12
-rw-r--r--spec/models/concerns/milestoneish_spec.rb19
-rw-r--r--spec/models/service_spec.rb51
3 files changed, 80 insertions, 2 deletions
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index de93c3c1675..6f6ff3704b4 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -140,6 +140,18 @@ describe Ci::JobArtifact do
end
end
+ describe '.for_job_name' do
+ it 'returns job artifacts for a given job name' do
+ first_job = create(:ci_build, name: 'first')
+ second_job = create(:ci_build, name: 'second')
+ first_artifact = create(:ci_job_artifact, job: first_job)
+ second_artifact = create(:ci_job_artifact, job: second_job)
+
+ expect(described_class.for_job_name(first_job.name)).to eq([first_artifact])
+ expect(described_class.for_job_name(second_job.name)).to eq([second_artifact])
+ end
+ end
+
describe 'callbacks' do
subject { create(:ci_job_artifact, :archive) }
diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb
index cff607a4731..5808d6e37e5 100644
--- a/spec/models/concerns/milestoneish_spec.rb
+++ b/spec/models/concerns/milestoneish_spec.rb
@@ -33,17 +33,34 @@ describe Milestone, 'Milestoneish' do
end
describe '#sorted_issues' do
- it 'sorts issues by label priority' do
+ before do
issue.labels << label_1
security_issue_1.labels << label_2
closed_issue_1.labels << label_3
+ end
+ it 'sorts issues by label priority' do
issues = milestone.sorted_issues(member)
expect(issues.first).to eq(issue)
expect(issues.second).to eq(security_issue_1)
expect(issues.third).not_to eq(closed_issue_1)
end
+
+ it 'limits issue count and keeps the ordering' do
+ stub_const('Milestoneish::DISPLAY_ISSUES_LIMIT', 4)
+
+ issues = milestone.sorted_issues(member)
+ # Cannot use issues.count here because it is sorting
+ # by a virtual column 'highest_priority' and it will break
+ # the query.
+ total_issues_count = issues.opened.unassigned.length + issues.opened.assigned.length + issues.closed.length
+ expect(issues.length).to eq(4)
+ expect(total_issues_count).to eq(4)
+ expect(issues.first).to eq(issue)
+ expect(issues.second).to eq(security_issue_1)
+ expect(issues.third).not_to eq(closed_issue_1)
+ end
end
context 'attributes visibility' do
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index 7c80b5231d1..cecd4f76fc5 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -149,9 +149,58 @@ describe Service do
end
end
- describe "Template" do
+ describe 'template' do
let(:project) { create(:project) }
+ shared_examples 'retrieves service templates' do
+ it 'returns the available service templates' do
+ expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types)
+ end
+ end
+
+ describe '.find_or_create_templates' do
+ it 'creates service templates' do
+ expect { Service.find_or_create_templates }.to change { Service.count }.from(0).to(Service.available_services_names.size)
+ end
+
+ it_behaves_like 'retrieves service templates'
+
+ context 'with all existing templates' do
+ before do
+ Service.insert_all(
+ Service.available_services_types.map { |type| { template: true, type: type } }
+ )
+ end
+
+ it 'does not create service templates' do
+ expect { Service.find_or_create_templates }.to change { Service.count }.by(0)
+ end
+
+ it_behaves_like 'retrieves service templates'
+
+ context 'with a previous existing service (Previous) and a new service (Asana)' do
+ before do
+ Service.insert(type: 'PreviousService', template: true)
+ Service.delete_by(type: 'AsanaService', template: true)
+ end
+
+ it_behaves_like 'retrieves service templates'
+ end
+ end
+
+ context 'with a few existing templates' do
+ before do
+ create(:jira_service, :template)
+ end
+
+ it 'creates the rest of the service templates' do
+ expect { Service.find_or_create_templates }.to change { Service.count }.from(1).to(Service.available_services_names.size)
+ end
+
+ it_behaves_like 'retrieves service templates'
+ end
+ end
+
describe '.build_from_template' do
context 'when template is invalid' do
it 'sets service template to inactive when template is invalid' do