Fix validation method for Gitlab::GithubImport::PullRequestFormatter

parent 795a7ca8
...@@ -15,6 +15,10 @@ module Gitlab ...@@ -15,6 +15,10 @@ module Gitlab
repo.present? repo.present?
end end
def valid?
repo.present?
end
private private
def short_id def short_id
......
...@@ -29,7 +29,7 @@ module Gitlab ...@@ -29,7 +29,7 @@ module Gitlab
end end
def valid? def valid?
!cross_project? source_branch.valid? && target_branch.valid? && !cross_project?
end end
def source_branch def source_branch
...@@ -65,7 +65,6 @@ module Gitlab ...@@ -65,7 +65,6 @@ module Gitlab
end end
def cross_project? def cross_project?
source_branch_repo.present? && target_branch_repo.present? &&
source_branch_repo.id != target_branch_repo.id source_branch_repo.id != target_branch_repo.id
end end
......
...@@ -54,4 +54,18 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do ...@@ -54,4 +54,18 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
expect(branch.sha).to eq '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b' expect(branch.sha).to eq '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
end end
end end
describe '#valid?' do
it 'returns true when repository exists' do
branch = described_class.new(project, double(raw))
expect(branch.valid?).to eq true
end
it 'returns false when repository does not exist' do
branch = described_class.new(project, double(raw.merge(repo: nil)))
expect(branch.valid?).to eq false
end
end
end end
...@@ -173,7 +173,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -173,7 +173,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end end
context 'when source repo is a fork' do context 'when source repo is a fork' do
let(:source_repo) { double(id: 2, fork: true) } let(:source_repo) { double(id: 2) }
let(:raw_data) { double(base_data) } let(:raw_data) { double(base_data) }
it 'returns false' do it 'returns false' do
...@@ -182,7 +182,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -182,7 +182,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end end
context 'when target repo is a fork' do context 'when target repo is a fork' do
let(:target_repo) { double(id: 2, fork: true) } let(:target_repo) { double(id: 2) }
let(:raw_data) { double(base_data) } let(:raw_data) { double(base_data) }
it 'returns false' do it 'returns false' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment