From b278d886ba65e2d3d438352b6243cd33b1ba4636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 9 Nov 2018 22:17:43 +0100 Subject: Support both ref and ref-name in protected_for? --- spec/models/project_spec.rb | 68 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1c85411dc3b..a519435322c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2520,6 +2520,10 @@ describe Project do end context 'when the ref is not protected' do + before do + allow(project).to receive(:protected_for?).with('ref').and_return(false) + end + it 'contains only the CI variables' do is_expected.to contain_exactly(ci_variable) end @@ -2563,7 +2567,13 @@ describe Project do subject { project.protected_for?('ref') } + before do + allow(project).to receive(:resolve_ref).and_return(ref) + end + context 'when the ref is not protected' do + let(:ref) { 'refs/heads/ref' } + before do stub_application_setting( default_branch_protection: Gitlab::Access::PROTECTION_NONE) @@ -2575,9 +2585,9 @@ describe Project do end context 'when the ref is a protected branch' do + let(:ref) { 'refs/heads/ref' } + before do - allow(project).to receive(:repository).and_call_original - allow(project).to receive_message_chain(:repository, :branch_exists?).and_return(true) create(:protected_branch, name: 'ref', project: project) end @@ -2587,9 +2597,9 @@ describe Project do end context 'when the ref is a protected tag' do + let(:ref) { 'refs/tags/ref' } + before do - allow(project).to receive_message_chain(:repository, :branch_exists?).and_return(false) - allow(project).to receive_message_chain(:repository, :tag_exists?).and_return(true) create(:protected_tag, name: 'ref', project: project) end @@ -2778,6 +2788,56 @@ describe Project do end end + describe '#resolve_ref' do + let(:project) { create(:project) } + + subject { project.resolve_ref(ref) } + + context 'when ref is full ref' do + let(:ref) { 'refs/heads/master' } + + it 'returns the unchanged ref' do + is_expected.to eq(ref) + end + end + + context 'when ref is a tag or branch name' do + let(:ref) { 'ref' } + + before do + allow(project.repository).to receive(:tag_exists?).and_return(tag_exists) + allow(project.repository).to receive(:branch_exists?).and_return(branch_exists) + end + + context 'when ref is ambiguous' do + let(:tag_exists) { true } + let(:branch_exists) { true } + + it 'raises an error' do + expect { subject }.to raise_error(described_class::AmbiguousRef) + end + end + + context 'when ref is tag name' do + let(:tag_exists) { true } + let(:branch_exists) { false } + + it 'returns full tag ref path' do + is_expected.to eq('refs/tags/ref') + end + end + + context 'when ref is branch name' do + let(:tag_exists) { false } + let(:branch_exists) { true } + + it 'returns full branch ref path' do + is_expected.to eq('refs/heads/ref') + end + end + end + end + describe '#http_url_to_repo' do let(:project) { create(:project) } -- cgit v1.2.1 From 855e7c32b9f3541fec085726d338802c8ca9b9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 15 Nov 2018 22:54:21 +0100 Subject: Use Gitlab::Git::Ref in Project#resolve_ref Reworks Project#resolve_ref to return Gitlab::Git::Branch, Gitlab::Git::Tag or raise an AmbiguousRef error. --- spec/models/project_spec.rb | 55 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a519435322c..e2e8a76ab72 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2563,7 +2563,7 @@ describe Project do end describe '#protected_for?' do - let(:project) { create(:project) } + let(:project) { create(:project, :repository) } subject { project.protected_for?('ref') } @@ -2572,7 +2572,7 @@ describe Project do end context 'when the ref is not protected' do - let(:ref) { 'refs/heads/ref' } + let(:ref) { project.repository.find_branch('master') } before do stub_application_setting( @@ -2585,10 +2585,10 @@ describe Project do end context 'when the ref is a protected branch' do - let(:ref) { 'refs/heads/ref' } + let(:ref) { project.repository.find_branch('master') } before do - create(:protected_branch, name: 'ref', project: project) + create(:protected_branch, name: 'master', project: project) end it 'returns true' do @@ -2597,10 +2597,10 @@ describe Project do end context 'when the ref is a protected tag' do - let(:ref) { 'refs/tags/ref' } + let(:ref) { project.repository.find_tag('v1.0.0') } before do - create(:protected_tag, name: 'ref', project: project) + create(:protected_tag, name: 'v1.0.0', project: project) end it 'returns true' do @@ -2789,29 +2789,36 @@ describe Project do end describe '#resolve_ref' do - let(:project) { create(:project) } + let(:project) { create(:project, :repository) } subject { project.resolve_ref(ref) } context 'when ref is full ref' do - let(:ref) { 'refs/heads/master' } + context 'when ref exists' do + let(:ref) { 'refs/heads/master' } + + it 'returns the ref' do + is_expected.to be_a(Gitlab::Git::Ref) + end + end + + context 'when ref does not exist' do + let(:ref) { 'refs/tags/doesnotexist' } - it 'returns the unchanged ref' do - is_expected.to eq(ref) + it 'returns nil' do + is_expected.to eq(nil) + end end end context 'when ref is a tag or branch name' do let(:ref) { 'ref' } - before do - allow(project.repository).to receive(:tag_exists?).and_return(tag_exists) - allow(project.repository).to receive(:branch_exists?).and_return(branch_exists) - end - context 'when ref is ambiguous' do - let(:tag_exists) { true } - let(:branch_exists) { true } + before do + project.repository.add_tag(project.creator, ref, 'master') + project.repository.add_branch(project.creator, ref, 'master') + end it 'raises an error' do expect { subject }.to raise_error(described_class::AmbiguousRef) @@ -2819,20 +2826,22 @@ describe Project do end context 'when ref is tag name' do - let(:tag_exists) { true } - let(:branch_exists) { false } + before do + project.repository.add_tag(project.creator, ref, 'master') + end it 'returns full tag ref path' do - is_expected.to eq('refs/tags/ref') + is_expected.to be_a(Gitlab::Git::Tag) end end context 'when ref is branch name' do - let(:tag_exists) { false } - let(:branch_exists) { true } + before do + project.repository.add_branch(project.creator, ref, 'master') + end it 'returns full branch ref path' do - is_expected.to eq('refs/heads/ref') + is_expected.to be_a(Gitlab::Git::Branch) end end end -- cgit v1.2.1 From b0b5924eb418851ddfab848ab16b6acac27d42e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 15 Nov 2018 23:31:02 +0100 Subject: Use nil instead of raising AmbiguousRef --- spec/models/project_spec.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e2e8a76ab72..48cf693b678 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2571,6 +2571,14 @@ describe Project do allow(project).to receive(:resolve_ref).and_return(ref) end + context 'when ref is ambiguous' do + let(:ref) { nil } + + it 'returns false' do + is_expected.to be_falsey + end + end + context 'when the ref is not protected' do let(:ref) { project.repository.find_branch('master') } @@ -2820,8 +2828,8 @@ describe Project do project.repository.add_branch(project.creator, ref, 'master') end - it 'raises an error' do - expect { subject }.to raise_error(described_class::AmbiguousRef) + it 'returns nil' do + is_expected.to eq(nil) end end -- cgit v1.2.1 From 2b4883e05e59eff08088e378bf3061d9d8da13dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 16 Nov 2018 00:27:11 +0100 Subject: Check for Tag/Branch corectness --- spec/models/project_spec.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 48cf693b678..204d611796b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2805,7 +2805,7 @@ describe Project do context 'when ref exists' do let(:ref) { 'refs/heads/master' } - it 'returns the ref' do + it 'returns a ref' do is_expected.to be_a(Gitlab::Git::Ref) end end @@ -2838,9 +2838,13 @@ describe Project do project.repository.add_tag(project.creator, ref, 'master') end - it 'returns full tag ref path' do + it 'returns a tag' do is_expected.to be_a(Gitlab::Git::Tag) end + + it 'returns the correct tag' do + expect(subject.name).to eq(ref) + end end context 'when ref is branch name' do @@ -2848,9 +2852,13 @@ describe Project do project.repository.add_branch(project.creator, ref, 'master') end - it 'returns full branch ref path' do + it 'returns a branch' do is_expected.to be_a(Gitlab::Git::Branch) end + + it 'returns the correct branch' do + expect(subject.name).to eq(ref) + end end end end -- cgit v1.2.1 From 96a0a8cfb62d9ea66ee2a22e09a116d64f333703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 16 Nov 2018 21:03:21 +0100 Subject: Use strings instead of Gitlab::Git::Ref --- spec/models/project_spec.rb | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 204d611796b..cbc242308e8 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2580,7 +2580,7 @@ describe Project do end context 'when the ref is not protected' do - let(:ref) { project.repository.find_branch('master') } + let(:ref) { 'refs/heads/master' } before do stub_application_setting( @@ -2593,7 +2593,7 @@ describe Project do end context 'when the ref is a protected branch' do - let(:ref) { project.repository.find_branch('master') } + let(:ref) { 'refs/heads/master' } before do create(:protected_branch, name: 'master', project: project) @@ -2605,7 +2605,7 @@ describe Project do end context 'when the ref is a protected tag' do - let(:ref) { project.repository.find_tag('v1.0.0') } + let(:ref) { 'refs/tags/v1.0.0' } before do create(:protected_tag, name: 'v1.0.0', project: project) @@ -2802,20 +2802,10 @@ describe Project do subject { project.resolve_ref(ref) } context 'when ref is full ref' do - context 'when ref exists' do - let(:ref) { 'refs/heads/master' } + let(:ref) { 'refs/heads/master' } - it 'returns a ref' do - is_expected.to be_a(Gitlab::Git::Ref) - end - end - - context 'when ref does not exist' do - let(:ref) { 'refs/tags/doesnotexist' } - - it 'returns nil' do - is_expected.to eq(nil) - end + it 'returns the ref' do + is_expected.to eq(ref) end end @@ -2838,12 +2828,8 @@ describe Project do project.repository.add_tag(project.creator, ref, 'master') end - it 'returns a tag' do - is_expected.to be_a(Gitlab::Git::Tag) - end - - it 'returns the correct tag' do - expect(subject.name).to eq(ref) + it 'returns the tag ref' do + is_expected.to eq("refs/tags/#{ref}") end end @@ -2852,12 +2838,8 @@ describe Project do project.repository.add_branch(project.creator, ref, 'master') end - it 'returns a branch' do - is_expected.to be_a(Gitlab::Git::Branch) - end - - it 'returns the correct branch' do - expect(subject.name).to eq(ref) + it 'returns the branch ref' do + is_expected.to eq("refs/heads/#{ref}") end end end -- cgit v1.2.1 From 24d682254a0ae68dfc605fc077c6a7610b97994a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 20 Nov 2018 15:07:25 +0100 Subject: Move Project#resolve_ref to Repository --- spec/models/project_spec.rb | 51 +-------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index cbc242308e8..25560ddea8d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2568,7 +2568,7 @@ describe Project do subject { project.protected_for?('ref') } before do - allow(project).to receive(:resolve_ref).and_return(ref) + allow(project.repository).to receive(:resolve_ref).and_return(ref) end context 'when ref is ambiguous' do @@ -2796,55 +2796,6 @@ describe Project do end end - describe '#resolve_ref' do - let(:project) { create(:project, :repository) } - - subject { project.resolve_ref(ref) } - - context 'when ref is full ref' do - let(:ref) { 'refs/heads/master' } - - it 'returns the ref' do - is_expected.to eq(ref) - end - end - - context 'when ref is a tag or branch name' do - let(:ref) { 'ref' } - - context 'when ref is ambiguous' do - before do - project.repository.add_tag(project.creator, ref, 'master') - project.repository.add_branch(project.creator, ref, 'master') - end - - it 'returns nil' do - is_expected.to eq(nil) - end - end - - context 'when ref is tag name' do - before do - project.repository.add_tag(project.creator, ref, 'master') - end - - it 'returns the tag ref' do - is_expected.to eq("refs/tags/#{ref}") - end - end - - context 'when ref is branch name' do - before do - project.repository.add_branch(project.creator, ref, 'master') - end - - it 'returns the branch ref' do - is_expected.to eq("refs/heads/#{ref}") - end - end - end - end - describe '#http_url_to_repo' do let(:project) { create(:project) } -- cgit v1.2.1 From 350ea9c55ab6b980ac5ec74d2a34b9cbac915e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 23 Nov 2018 00:11:42 +0100 Subject: Implement Repository#ambiguous_ref? This implements Repository#ambiguous_ref? and checks if a ref is ambiguous before trying to resolve the ref in Project#protected_for? --- spec/models/project_spec.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 25560ddea8d..18ad69a1bda 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2565,14 +2565,23 @@ describe Project do describe '#protected_for?' do let(:project) { create(:project, :repository) } - subject { project.protected_for?('ref') } + subject { project.protected_for?(ref) } - before do - allow(project.repository).to receive(:resolve_ref).and_return(ref) + context 'when ref is nil' do + let(:ref) { nil } + + it 'returns false' do + is_expected.to be_falsey + end end context 'when ref is ambiguous' do - let(:ref) { nil } + let(:ref) { 'ref' } + + before do + project.repository.add_branch(project.creator, ref, 'master') + project.repository.add_tag(project.creator, ref, 'master') + end it 'returns false' do is_expected.to be_falsey @@ -2580,7 +2589,7 @@ describe Project do end context 'when the ref is not protected' do - let(:ref) { 'refs/heads/master' } + let(:ref) { 'master' } before do stub_application_setting( @@ -2593,7 +2602,7 @@ describe Project do end context 'when the ref is a protected branch' do - let(:ref) { 'refs/heads/master' } + let(:ref) { 'master' } before do create(:protected_branch, name: 'master', project: project) @@ -2605,7 +2614,7 @@ describe Project do end context 'when the ref is a protected tag' do - let(:ref) { 'refs/tags/v1.0.0' } + let(:ref) { 'v1.0.0' } before do create(:protected_tag, name: 'v1.0.0', project: project) -- cgit v1.2.1 From 08942de9b6a3ad361cbae8a83a8e8b7c7e4768ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Wed, 28 Nov 2018 15:43:58 +0100 Subject: Raise an error on ambiguous refs --- spec/models/project_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 18ad69a1bda..a106642c3e5 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2583,8 +2583,8 @@ describe Project do project.repository.add_tag(project.creator, ref, 'master') end - it 'returns false' do - is_expected.to be_falsey + it 'raises an error' do + expect { subject }.to raise_error(Repository::AmbiguousRefError) end end -- cgit v1.2.1 From 0f00c7818bf09e800c4ac6652077fffe7976ed6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 11:34:59 +0100 Subject: Remove resolving conditional from protected_for --- spec/models/project_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a106642c3e5..75f1f779bb0 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2624,6 +2624,28 @@ describe Project do is_expected.to be_truthy end end + + context 'when ref name is a full branch ref' do + let(:ref) { 'refs/tags/something' } + + before do + project.repository.add_branch(project.creator, ref, 'master') + end + + it 'returns false' do + is_expected.to be_falsey + end + + context 'when ref is a protected branch' do + before do + create(:protected_branch, name: 'refs/tags/something', project: project) + end + + it 'returns true' do + is_expected.to be_truthy + end + end + end end describe '#update_project_statistics' do -- cgit v1.2.1 From 93d3c61eca258369bda0c28c5519cb14e4ff1457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 12:18:53 +0100 Subject: Add specs when full ref is passed to protected_for --- spec/models/project_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 75f1f779bb0..33bce0c0823 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2625,7 +2625,27 @@ describe Project do end end - context 'when ref name is a full branch ref' do + context 'when ref is a full ref' do + let(:ref) { 'refs/heads/master' } + + context 'when ref is not protected' do + it 'returns false' do + is_expected.to be_falsey + end + end + + context 'when ref is protected' do + before do + create(:protected_branch, name: 'master', project: project) + end + + it 'returns true' do + is_expected.to be_truthy + end + end + end + + context 'when ref name is a full tag ref' do let(:ref) { 'refs/tags/something' } before do -- cgit v1.2.1 From 86c0558c1c473e26df0a1cd5ea4b647175e8b857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 12:36:46 +0100 Subject: Refactor Project#protected_for? specs This refactors the Project#protected_for? specs to separate them into two contexts: when the ref is a full ref and when the ref is a ref name. --- spec/models/project_spec.rb | 118 +++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 51 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 33bce0c0823..b4b9d921ba4 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2567,30 +2567,7 @@ describe Project do subject { project.protected_for?(ref) } - context 'when ref is nil' do - let(:ref) { nil } - - it 'returns false' do - is_expected.to be_falsey - end - end - - context 'when ref is ambiguous' do - let(:ref) { 'ref' } - - before do - project.repository.add_branch(project.creator, ref, 'master') - project.repository.add_tag(project.creator, ref, 'master') - end - - it 'raises an error' do - expect { subject }.to raise_error(Repository::AmbiguousRefError) - end - end - - context 'when the ref is not protected' do - let(:ref) { 'master' } - + shared_examples 'ref is not protected' do before do stub_application_setting( default_branch_protection: Gitlab::Access::PROTECTION_NONE) @@ -2601,9 +2578,7 @@ describe Project do end end - context 'when the ref is a protected branch' do - let(:ref) { 'master' } - + shared_examples 'ref is protected branch' do before do create(:protected_branch, name: 'master', project: project) end @@ -2613,9 +2588,7 @@ describe Project do end end - context 'when the ref is a protected tag' do - let(:ref) { 'v1.0.0' } - + shared_examples 'ref is protected tag' do before do create(:protected_tag, name: 'v1.0.0', project: project) end @@ -2625,44 +2598,87 @@ describe Project do end end - context 'when ref is a full ref' do - let(:ref) { 'refs/heads/master' } + context 'when ref is nil' do + let(:ref) { nil } - context 'when ref is not protected' do - it 'returns false' do - is_expected.to be_falsey - end + it 'returns false' do + is_expected.to be_falsey end + end + + context 'when ref is ref name' do + context 'when ref is ambiguous' do + let(:ref) { 'ref' } - context 'when ref is protected' do before do - create(:protected_branch, name: 'master', project: project) + project.repository.add_branch(project.creator, 'ref', 'master') + project.repository.add_tag(project.creator, 'ref', 'master') end - it 'returns true' do - is_expected.to be_truthy + it 'raises an error' do + expect { subject }.to raise_error(Repository::AmbiguousRefError) end end + + context 'when the ref is not protected' do + let(:ref) { 'master' } + + it_behaves_like 'ref is not protected' + end + + context 'when the ref is a protected branch' do + let(:ref) { 'master' } + + it_behaves_like 'ref is protected branch' + end + + context 'when the ref is a protected tag' do + let(:ref) { 'v1.0.0' } + + it_behaves_like 'ref is protected tag' + end end - context 'when ref name is a full tag ref' do - let(:ref) { 'refs/tags/something' } + context 'when ref is full ref' do + context 'when the ref is not protected' do + let(:ref) { 'refs/heads/master' } - before do - project.repository.add_branch(project.creator, ref, 'master') + it_behaves_like 'ref is not protected' end - it 'returns false' do - is_expected.to be_falsey + context 'when the ref is a protected branch' do + let(:ref) { 'refs/heads/master' } + + it_behaves_like 'ref is protected branch' end - context 'when ref is a protected branch' do + context 'when the ref is a protected tag' do + let(:ref) { 'refs/tags/v1.0.0' } + + it_behaves_like 'ref is protected tag' + end + + context 'when branch ref name is a full tag ref' do + let(:ref) { 'refs/tags/something' } + before do - create(:protected_branch, name: 'refs/tags/something', project: project) + project.repository.add_branch(project.creator, ref, 'master') end - it 'returns true' do - is_expected.to be_truthy + context 'when ref is not protected' do + it 'returns false' do + is_expected.to be_falsey + end + end + + context 'when ref is a protected branch' do + before do + create(:protected_branch, name: 'refs/tags/something', project: project) + end + + it 'returns true' do + is_expected.to be_truthy + end end end end @@ -2883,7 +2899,7 @@ describe Project do it 'shows full error updating an invalid MR' do error_message = 'Failed to replace merge_requests because one or more of the new records could not be saved.'\ - ' Validate fork Source project is not a fork of the target project' + ' Validate fork Source project is not a fork of the target project' expect { project.append_or_update_attribute(:merge_requests, [create(:merge_request)]) } .to raise_error(ActiveRecord::RecordNotSaved, error_message) -- cgit v1.2.1 From 9b4e45c35253a397f3ff79207736280293848bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 3 Dec 2018 14:06:07 +0100 Subject: Check for explicit true or false in specs --- spec/models/project_spec.rb | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index b4b9d921ba4..606636e9d58 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2574,7 +2574,7 @@ describe Project do end it 'returns false' do - is_expected.to be_falsey + is_expected.to be false end end @@ -2584,7 +2584,7 @@ describe Project do end it 'returns true' do - is_expected.to be_truthy + is_expected.to be true end end @@ -2594,7 +2594,7 @@ describe Project do end it 'returns true' do - is_expected.to be_truthy + is_expected.to be true end end @@ -2602,7 +2602,7 @@ describe Project do let(:ref) { nil } it 'returns false' do - is_expected.to be_falsey + is_expected.to be false end end @@ -2637,6 +2637,14 @@ describe Project do it_behaves_like 'ref is protected tag' end + + context 'when ref does not exist' do + let(:ref) { 'something' } + + it 'returns false' do + is_expected.to be false + end + end end context 'when ref is full ref' do @@ -2667,7 +2675,7 @@ describe Project do context 'when ref is not protected' do it 'returns false' do - is_expected.to be_falsey + is_expected.to be false end end @@ -2677,10 +2685,18 @@ describe Project do end it 'returns true' do - is_expected.to be_truthy + is_expected.to be true end end end + + context 'when ref does not exist' do + let(:ref) { 'refs/heads/something' } + + it 'returns false' do + is_expected.to be false + end + end end end -- cgit v1.2.1 From 63c48f73803cf1c68d6c9af408f877ea61781118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Mon, 10 Dec 2018 17:23:52 +0100 Subject: Replaced UrlValidator with PublicUrlValidator for import_url and remote mirror urls --- spec/models/project_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/models/project_spec.rb') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9e5b06b745a..a9624b6a00e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -314,6 +314,13 @@ describe Project do expect(project.errors[:import_url].first).to include('Requests to localhost are not allowed') end + it 'does not allow import_url pointing to the local network' do + project = build(:project, import_url: 'https://192.168.1.1') + + expect(project).to be_invalid + expect(project.errors[:import_url].first).to include('Requests to the local network are not allowed') + end + it "does not allow import_url with invalid ports for new projects" do project = build(:project, import_url: 'http://github.com:25/t.git') -- cgit v1.2.1