Commit 2ea5e00f authored by Stan Hu's avatar Stan Hu

Merge branch 'namespace-has-parent' into 'master'

Optimize namespace.has_parent?

See merge request gitlab-org/gitlab!17749
parents b96a8fba f8625a98
......@@ -256,7 +256,7 @@ class Namespace < ApplicationRecord
end
def has_parent?
parent.present?
parent_id.present? || parent.present?
end
def root_ancestor
......
......@@ -880,22 +880,6 @@ describe Group do
end
end
describe '#has_parent?' do
context 'when the group has a parent' do
it 'is truthy' do
group = create(:group, :nested)
expect(group.has_parent?).to be_truthy
end
end
context 'when the group has no parent' do
it 'is falsy' do
group = create(:group, parent: nil)
expect(group.has_parent?).to be_falsy
end
end
end
context 'with uploads' do
it_behaves_like 'model with uploads', true do
let(:model_object) { create(:group, :with_avatar) }
......
......@@ -933,4 +933,25 @@ describe Namespace do
end
end
end
describe '#has_parent?' do
it 'returns true when the group has a parent' do
group = create(:group, :nested)
expect(group.has_parent?).to be_truthy
end
it 'returns true when the group has an unsaved parent' do
parent = build(:group)
group = build(:group, parent: parent)
expect(group.has_parent?).to be_truthy
end
it 'returns false when the group has no parent' do
group = create(:group, parent: nil)
expect(group.has_parent?).to be_falsy
end
end
end
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