Commit b17ae7fd authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by ayufanpl

Use root_ancestor of Namespace (and move it from EE)

parent 7d2ea9aa
...@@ -213,6 +213,10 @@ class Namespace < ActiveRecord::Base ...@@ -213,6 +213,10 @@ class Namespace < ActiveRecord::Base
parent.present? parent.present?
end end
def root_ancestor
ancestors.reorder(nil).find_by(parent_id: nil)
end
def subgroup? def subgroup?
has_parent? has_parent?
end end
......
...@@ -501,7 +501,11 @@ class Project < ActiveRecord::Base ...@@ -501,7 +501,11 @@ class Project < ActiveRecord::Base
end end
def root_namespace def root_namespace
@root_namespace ||= Gitlab::GroupHierarchy.new(Namespace.where(id: namespace_id)).roots.take if namespace.has_parent?
namespace.root_ancestor
else
namespace
end
end end
def lfs_enabled? def lfs_enabled?
......
...@@ -43,10 +43,6 @@ module EE ...@@ -43,10 +43,6 @@ module EE
end end
end end
def root_ancestor
ancestors.reorder(nil).find_by(parent_id: nil)
end
def move_dir def move_dir
raise NotImplementedError unless defined?(super) raise NotImplementedError unless defined?(super)
......
...@@ -363,19 +363,6 @@ describe Namespace do ...@@ -363,19 +363,6 @@ describe Namespace do
end end
end end
describe '#root_ancestor' do
it 'returns the top most ancestor', :nested_groups do
root_group = create(:group)
nested_group = create(:group, parent: root_group)
deep_nested_group = create(:group, parent: nested_group)
very_deep_nested_group = create(:group, parent: deep_nested_group)
expect(nested_group.root_ancestor).to eq(root_group)
expect(deep_nested_group.root_ancestor).to eq(root_group)
expect(very_deep_nested_group.root_ancestor).to eq(root_group)
end
end
describe '#actual_plan' do describe '#actual_plan' do
context 'when namespace has a plan associated' do context 'when namespace has a plan associated' do
before do before do
......
...@@ -675,4 +675,17 @@ describe Namespace do ...@@ -675,4 +675,17 @@ describe Namespace do
expect(other_namespace.find_fork_of(project)).to eq(other_fork) expect(other_namespace.find_fork_of(project)).to eq(other_fork)
end end
end end
describe '#root_ancestor' do
it 'returns the top most ancestor', :nested_groups do
root_group = create(:group)
nested_group = create(:group, parent: root_group)
deep_nested_group = create(:group, parent: nested_group)
very_deep_nested_group = create(:group, parent: deep_nested_group)
expect(nested_group.root_ancestor).to eq(root_group)
expect(deep_nested_group.root_ancestor).to eq(root_group)
expect(very_deep_nested_group.root_ancestor).to eq(root_group)
end
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