Commit d806230f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add parents method to Namespace

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5c06875c
...@@ -163,6 +163,7 @@ class Namespace < ActiveRecord::Base ...@@ -163,6 +163,7 @@ class Namespace < ActiveRecord::Base
end end
def full_name def full_name
@full_name ||=
if parent if parent
parent.full_name + ' / ' + name parent.full_name + ' / ' + name
else else
...@@ -170,6 +171,20 @@ class Namespace < ActiveRecord::Base ...@@ -170,6 +171,20 @@ class Namespace < ActiveRecord::Base
end end
end end
def parents
@parents ||=
begin
parents = []
if parent
parents << parent
parents += parent.parents
end
parents
end
end
private private
def repository_storage_paths def repository_storage_paths
......
...@@ -132,4 +132,12 @@ describe Namespace, models: true do ...@@ -132,4 +132,12 @@ describe Namespace, models: true do
it { expect(group.full_path).to eq(group.path) } it { expect(group.full_path).to eq(group.path) }
it { expect(nested_group.full_path).to eq("#{group.path}/#{nested_group.path}") } it { expect(nested_group.full_path).to eq("#{group.path}/#{nested_group.path}") }
end end
describe '#parents' do
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
it { expect(deep_nested_group.parents).to eq([nested_group, group]) }
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