diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/models/release_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-13.9.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/models/release_spec.rb')
-rw-r--r-- | spec/models/release_spec.rb | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index b436c2e1088..209ac471210 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Release do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public, :repository) } - let_it_be(:release) { create(:release, project: project, author: user) } + let(:release) { create(:release, project: project, author: user) } it { expect(release).to be_valid } @@ -89,6 +89,61 @@ RSpec.describe Release do end end + describe '#update' do + subject { release.update(params) } + + context 'when links do not exist' do + context 'when params are specified for creation' do + let(:params) do + { links_attributes: [{ name: 'test', url: 'https://www.google.com/' }] } + end + + it 'creates a link successfuly' do + is_expected.to eq(true) + + expect(release.links.count).to eq(1) + expect(release.links.first.name).to eq('test') + expect(release.links.first.url).to eq('https://www.google.com/') + end + end + end + + context 'when a link exists' do + let!(:link1) { create(:release_link, release: release, name: 'test1', url: 'https://www.google1.com/') } + let!(:link2) { create(:release_link, release: release, name: 'test2', url: 'https://www.google2.com/') } + + before do + release.reload + end + + context 'when params are specified for update' do + let(:params) do + { links_attributes: [{ id: link1.id, name: 'new' }] } + end + + it 'updates the link successfully' do + is_expected.to eq(true) + + expect(release.links.count).to eq(2) + expect(release.links.first.name).to eq('new') + end + end + + context 'when params are specified for deletion' do + let(:params) do + { links_attributes: [{ id: link1.id, _destroy: true }] } + end + + it 'removes the link successfuly' do + is_expected.to eq(true) + + expect(release.links.count).to eq(1) + expect(release.links.first.name).to eq(link2.name) + end + end + end + end + describe '#sources' do subject { release.sources } |