diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/release_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/create_release_service_spec.rb | 23 | ||||
-rw-r--r-- | spec/services/update_release_service_spec.rb | 8 |
3 files changed, 34 insertions, 11 deletions
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index 92ba2d82f58..914fa4e2553 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -16,4 +16,18 @@ RSpec.describe Release do it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:description) } end + + describe '.by_tag' do + let(:tag) { release.tag } + + subject { described_class.by_tag(project, tag) } + + it { is_expected.to eq(release) } + + context 'when no releases exists' do + let(:tag) { 'not-existing' } + + it { is_expected.to be_nil } + end + end end diff --git a/spec/services/create_release_service_spec.rb b/spec/services/create_release_service_spec.rb index d7ec6d4815a..1dd74a1bcdb 100644 --- a/spec/services/create_release_service_spec.rb +++ b/spec/services/create_release_service_spec.rb @@ -6,12 +6,17 @@ describe CreateReleaseService do let(:tag_name) { project.repository.tag_names.first } let(:name) { 'Bionic Beaver'} let(:description) { 'Awesome release!' } - let(:service) { described_class.new(project, user) } + let(:params) { { tag: tag_name, name: name, description: description } } + let(:service) { described_class.new(project, user, params) } let(:ref) { nil } + before do + project.add_maintainer(user) + end + shared_examples 'a successful release creation' do it 'creates a new release' do - result = service.execute(tag_name, description, name: name, ref: ref) + result = service.execute(ref) expect(result[:status]).to eq(:success) release = project.releases.find_by(tag: tag_name) expect(release).not_to be_nil @@ -24,14 +29,16 @@ describe CreateReleaseService do it_behaves_like 'a successful release creation' it 'raises an error if the tag does not exist' do - result = service.execute("foobar", description) + service.params[:tag] = 'foobar' + + result = service.execute expect(result[:status]).to eq(:error) end it 'keeps track of the commit sha' do tag = project.repository.find_tag(tag_name) sha = tag.dereferenced_target.sha - result = service.execute(tag_name, description, name: name) + result = service.execute expect(result[:status]).to eq(:success) expect(project.releases.find_by(tag: tag_name).sha).to eq(sha) @@ -46,7 +53,7 @@ describe CreateReleaseService do it 'creates a tag if the tag does not exist' do expect(project.repository.ref_exists?("refs/tags/#{tag_name}")).to be_falsey - result = service.execute(tag_name, description, name: name, ref: ref) + result = service.execute(ref) expect(result[:status]).to eq(:success) expect(project.repository.ref_exists?("refs/tags/#{tag_name}")).to be_truthy @@ -57,11 +64,13 @@ describe CreateReleaseService do context 'there already exists a release on a tag' do before do - service.execute(tag_name, description) + service.execute end it 'raises an error and does not update the release' do - result = service.execute(tag_name, 'The best release!') + service.params[:description] = 'The best release!' + + result = service.execute expect(result[:status]).to eq(:error) expect(project.releases.find_by(tag: tag_name).description).to eq(description) end diff --git a/spec/services/update_release_service_spec.rb b/spec/services/update_release_service_spec.rb index a24dcabfc2e..4378d5d072a 100644 --- a/spec/services/update_release_service_spec.rb +++ b/spec/services/update_release_service_spec.rb @@ -7,12 +7,12 @@ describe UpdateReleaseService do let(:description) { 'Awesome release!' } let(:new_name) { 'A new name' } let(:new_description) { 'The best release!' } - let(:params) { { name: new_name, description: new_description } } - let(:service) { described_class.new(project, user, tag_name, params) } - let(:create_service) { CreateReleaseService.new(project, user) } + let(:params) { { name: new_name, description: new_description, tag: tag_name } } + let(:service) { described_class.new(project, user, params) } + let(:create_service) { CreateReleaseService.new(project, user, tag: tag_name, description: description) } before do - create_service.execute(tag_name, description) + create_service.execute end shared_examples 'a failed update' do |