summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2018-12-12 10:56:43 +0100
committerAlessio Caiazza <acaiazza@gitlab.com>2018-12-13 12:15:21 +0100
commitb782ba1113970728989eebdf4c8fc44f8091c8d8 (patch)
treed78c36b3c216f0cf627ab3177da22c8717f390a2 /spec
parentdd62164d118c8bb741026abcab3db62aaedd18d5 (diff)
downloadgitlab-ce-b782ba1113970728989eebdf4c8fc44f8091c8d8.tar.gz
Add name, author and sha to releases
This commit adds a name to each release, defaulting it to tag name, keeps track of the SHA when a new release is created and tracks the current user as release author.
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/releases.rb1
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml1
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml3
-rw-r--r--spec/migrations/backfill_releases_name_with_tag_name_spec.rb23
-rw-r--r--spec/models/release_spec.rb1
-rw-r--r--spec/models/user_spec.rb1
-rw-r--r--spec/services/create_release_service_spec.rb5
7 files changed, 35 insertions, 0 deletions
diff --git a/spec/factories/releases.rb b/spec/factories/releases.rb
index d80c65cf8bb..18047c74a5d 100644
--- a/spec/factories/releases.rb
+++ b/spec/factories/releases.rb
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :release do
tag "v1.1.0"
+ name { tag }
description "Awesome release"
project
end
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index bae5b21c26f..b5f63630e8d 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -63,6 +63,7 @@ snippets:
- award_emoji
- user_agent_detail
releases:
+- author
- project
project_members:
- created_by
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index d3bfde181bc..24b1f2d995b 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -112,8 +112,11 @@ ProjectSnippet:
- visibility_level
Release:
- id
+- name
- tag
+- sha
- description
+- author_id
- project_id
- created_at
- updated_at
diff --git a/spec/migrations/backfill_releases_name_with_tag_name_spec.rb b/spec/migrations/backfill_releases_name_with_tag_name_spec.rb
new file mode 100644
index 00000000000..6f436de84b7
--- /dev/null
+++ b/spec/migrations/backfill_releases_name_with_tag_name_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20181212104941_backfill_releases_name_with_tag_name.rb')
+
+describe BackfillReleasesNameWithTagName, :migration do
+ let(:releases) { table(:releases) }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+
+ let(:namespace) { namespaces.create(name: 'foo', path: 'foo') }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+ let(:release) { releases.create!(project_id: project.id, tag: 'v1.0.0') }
+
+ it 'defaults name to tag value' do
+ expect(release.tag).to be_present
+
+ migrate!
+
+ release.reload
+ expect(release.name).to eq(release.tag)
+ end
+end
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb
index 3f86347c3ae..51725eeacac 100644
--- a/spec/models/release_spec.rb
+++ b/spec/models/release_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Release do
describe 'associations' do
it { is_expected.to belong_to(:project) }
+ it { is_expected.to belong_to(:author).class_name('User') }
end
describe 'validation' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index ff075e65c76..8b3021113bc 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -45,6 +45,7 @@ describe User do
it { is_expected.to have_many(:uploads) }
it { is_expected.to have_many(:reported_abuse_reports).dependent(:destroy).class_name('AbuseReport') }
it { is_expected.to have_many(:custom_attributes).class_name('UserCustomAttribute') }
+ it { is_expected.to have_many(:releases).dependent(:nullify) }
describe "#abuse_report" do
let(:current_user) { create(:user) }
diff --git a/spec/services/create_release_service_spec.rb b/spec/services/create_release_service_spec.rb
index ac0a0458f56..1a2dd0b39ee 100644
--- a/spec/services/create_release_service_spec.rb
+++ b/spec/services/create_release_service_spec.rb
@@ -6,6 +6,8 @@ describe CreateReleaseService do
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
let(:service) { described_class.new(project, user) }
+ let(:tag) { project.repository.find_tag(tag_name) }
+ let(:sha) { tag.dereferenced_target.sha }
it 'creates a new release' do
result = service.execute(tag_name, description)
@@ -13,6 +15,9 @@ describe CreateReleaseService do
release = project.releases.find_by(tag: tag_name)
expect(release).not_to be_nil
expect(release.description).to eq(description)
+ expect(release.name).to eq(tag_name)
+ expect(release.sha).to eq(sha)
+ expect(release.author).to eq(user)
end
it 'raises an error if the tag does not exist' do