summaryrefslogtreecommitdiff
path: root/spec/services/releases
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/releases')
-rw-r--r--spec/services/releases/create_service_spec.rb71
-rw-r--r--spec/services/releases/update_service_spec.rb77
2 files changed, 115 insertions, 33 deletions
diff --git a/spec/services/releases/create_service_spec.rb b/spec/services/releases/create_service_spec.rb
index 5f49eed3e77..9768ceb12e8 100644
--- a/spec/services/releases/create_service_spec.rb
+++ b/spec/services/releases/create_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Releases::CreateService do
+RSpec.describe Releases::CreateService, feature_category: :continuous_integration do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:tag_name) { project.repository.tag_names.first }
@@ -132,6 +132,15 @@ RSpec.describe Releases::CreateService do
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Milestone(s) not found: #{inexistent_milestone_tag}")
end
+
+ it 'raises an error saying the milestone id is inexistent' do
+ inexistent_milestone_id = non_existing_record_id
+ service = described_class.new(project, user, params.merge!({ milestone_ids: [inexistent_milestone_id] }))
+ result = service.execute
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq("Milestone id(s) not found: #{inexistent_milestone_id}")
+ end
end
context 'when existing milestone is passed in' do
@@ -140,15 +149,27 @@ RSpec.describe Releases::CreateService do
let(:params_with_milestone) { params.merge!({ milestones: [title] }) }
let(:service) { described_class.new(milestone.project, user, params_with_milestone) }
- it 'creates a release and ties this milestone to it' do
- result = service.execute
+ shared_examples 'creates release' do
+ it 'creates a release and ties this milestone to it' do
+ result = service.execute
- expect(project.releases.count).to eq(1)
- expect(result[:status]).to eq(:success)
+ expect(project.releases.count).to eq(1)
+ expect(result[:status]).to eq(:success)
+
+ release = project.releases.last
+
+ expect(release.milestones).to match_array([milestone])
+ end
+ end
- release = project.releases.last
+ context 'by title' do
+ it_behaves_like 'creates release'
+ end
+
+ context 'by ids' do
+ let(:params_with_milestone) { params.merge!({ milestone_ids: [milestone.id] }) }
- expect(release.milestones).to match_array([milestone])
+ it_behaves_like 'creates release'
end
context 'when another release was previously created with that same milestone linked' do
@@ -164,18 +185,31 @@ RSpec.describe Releases::CreateService do
end
end
- context 'when multiple existing milestone titles are passed in' do
+ context 'when multiple existing milestones are passed in' do
let(:title_1) { 'v1.0' }
let(:title_2) { 'v1.0-rc' }
let!(:milestone_1) { create(:milestone, :active, project: project, title: title_1) }
let!(:milestone_2) { create(:milestone, :active, project: project, title: title_2) }
- let!(:params_with_milestones) { params.merge!({ milestones: [title_1, title_2] }) }
- it 'creates a release and ties it to these milestones' do
- described_class.new(project, user, params_with_milestones).execute
- release = project.releases.last
+ shared_examples 'creates multiple releases' do
+ it 'creates a release and ties it to these milestones' do
+ described_class.new(project, user, params_with_milestones).execute
+ release = project.releases.last
+
+ expect(release.milestones.map(&:title)).to include(title_1, title_2)
+ end
+ end
+
+ context 'by title' do
+ let!(:params_with_milestones) { params.merge!({ milestones: [title_1, title_2] }) }
+
+ it_behaves_like 'creates multiple releases'
+ end
+
+ context 'by ids' do
+ let!(:params_with_milestones) { params.merge!({ milestone_ids: [milestone_1.id, milestone_2.id] }) }
- expect(release.milestones.map(&:title)).to include(title_1, title_2)
+ it_behaves_like 'creates multiple releases'
end
end
@@ -198,6 +232,17 @@ RSpec.describe Releases::CreateService do
service.execute
end.not_to change(Release, :count)
end
+
+ context 'with milestones as ids' do
+ let!(:params_with_milestones) { params.merge!({ milestone_ids: [milestone.id, non_existing_record_id] }) }
+
+ it 'raises an error' do
+ result = service.execute
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq("Milestone id(s) not found: #{non_existing_record_id}")
+ end
+ end
end
context 'no milestone association behavior' do
diff --git a/spec/services/releases/update_service_spec.rb b/spec/services/releases/update_service_spec.rb
index 7461470a844..6bddea48251 100644
--- a/spec/services/releases/update_service_spec.rb
+++ b/spec/services/releases/update_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Releases::UpdateService do
+RSpec.describe Releases::UpdateService, feature_category: :continuous_integration do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:new_name) { 'A new name' }
@@ -60,18 +60,22 @@ RSpec.describe Releases::UpdateService do
release.milestones << milestone
end
- context 'a different milestone' do
- let(:new_title) { 'v2.0' }
-
+ shared_examples 'updates milestones' do
it 'updates the related milestone accordingly' do
- result = service.execute
release.reload
+ result = service.execute
expect(release.milestones.first.title).to eq(new_title)
expect(result[:milestones_updated]).to be_truthy
end
end
+ context 'a different milestone' do
+ let(:new_title) { 'v2.0' }
+
+ it_behaves_like 'updates milestones'
+ end
+
context 'an identical milestone' do
let(:new_title) { 'v1.0' }
@@ -79,11 +83,17 @@ RSpec.describe Releases::UpdateService do
expect { service.execute }.to raise_error(ActiveRecord::RecordInvalid)
end
end
+
+ context 'by ids' do
+ let(:new_title) { 'v2.0' }
+ let(:params_with_milestone) { params.merge!({ milestone_ids: [new_milestone.id] }) }
+
+ it_behaves_like 'updates milestones'
+ end
end
context "when an 'empty' milestone is passed in" do
let(:milestone) { create(:milestone, project: project, title: 'v1.0') }
- let(:params_with_empty_milestone) { params.merge!({ milestones: [] }) }
before do
release.milestones << milestone
@@ -91,12 +101,26 @@ RSpec.describe Releases::UpdateService do
service.params = params_with_empty_milestone
end
- it 'removes the old milestone and does not associate any new milestone' do
- result = service.execute
- release.reload
+ shared_examples 'removes milestones' do
+ it 'removes the old milestone and does not associate any new milestone' do
+ result = service.execute
+ release.reload
+
+ expect(release.milestones).not_to be_present
+ expect(result[:milestones_updated]).to be_truthy
+ end
+ end
- expect(release.milestones).not_to be_present
- expect(result[:milestones_updated]).to be_truthy
+ context 'by title' do
+ let(:params_with_empty_milestone) { params.merge!({ milestones: [] }) }
+
+ it_behaves_like 'removes milestones'
+ end
+
+ context 'by id' do
+ let(:params_with_empty_milestone) { params.merge!({ milestone_ids: [] }) }
+
+ it_behaves_like 'removes milestones'
end
end
@@ -104,22 +128,35 @@ RSpec.describe Releases::UpdateService do
let(:new_title_1) { 'v2.0' }
let(:new_title_2) { 'v2.0-rc' }
let(:milestone) { create(:milestone, project: project, title: 'v1.0') }
- let(:params_with_milestones) { params.merge!({ milestones: [new_title_1, new_title_2] }) }
let(:service) { described_class.new(project, user, params_with_milestones) }
+ let!(:new_milestone_1) { create(:milestone, project: project, title: new_title_1) }
+ let!(:new_milestone_2) { create(:milestone, project: project, title: new_title_2) }
before do
- create(:milestone, project: project, title: new_title_1)
- create(:milestone, project: project, title: new_title_2)
release.milestones << milestone
end
- it 'removes the old milestone and update the release with the new ones' do
- result = service.execute
- release.reload
+ shared_examples 'updates multiple milestones' do
+ it 'removes the old milestone and update the release with the new ones' do
+ result = service.execute
+ release.reload
+
+ milestone_titles = release.milestones.map(&:title)
+ expect(milestone_titles).to match_array([new_title_1, new_title_2])
+ expect(result[:milestones_updated]).to be_truthy
+ end
+ end
+
+ context 'by title' do
+ let(:params_with_milestones) { params.merge!({ milestones: [new_title_1, new_title_2] }) }
+
+ it_behaves_like 'updates multiple milestones'
+ end
+
+ context 'by id' do
+ let(:params_with_milestones) { params.merge!({ milestone_ids: [new_milestone_1.id, new_milestone_2.id] }) }
- milestone_titles = release.milestones.map(&:title)
- expect(milestone_titles).to match_array([new_title_1, new_title_2])
- expect(result[:milestones_updated]).to be_truthy
+ it_behaves_like 'updates multiple milestones'
end
end
end