Skip to content

Commit

Permalink
Name the tags on the topology screens based on its classifications
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Dec 12, 2017
1 parent 37e15d2 commit 97786d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/services/topology_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ def entity_id(entity)
entity_type(entity) + entity.compressed_id.to_s
end

def entity_name(entity)
if entity.kind_of?(Tag)
cls = entity.classification
[cls.parent, cls].map(&:description).join(': ')
else
entity.name
end
end

def build_base_entity_data(entity)
{
:name => entity.name,
:name => entity_name(entity),
:kind => entity_type(entity),
:model => entity.class.to_s,
:miq_id => entity.id,
Expand Down
22 changes: 22 additions & 0 deletions spec/services/topology_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,26 @@
end
end
end

describe '#entity_name' do
let(:name) { subject.send(:entity_name, entity) }

context 'entity is not a tag' do
let(:entity) { FactoryGirl.create(:vm_vmware) }

it 'returns with the name of the entity' do
expect(name).to eq(entity.name)
end
end

context 'entity is a tag' do
let(:parent_cls) { FactoryGirl.create(:classification, :description => 'foo') }
let(:cls) { FactoryGirl.create(:classification, :parent => parent_cls, :description => 'bar') }
let(:entity) { FactoryGirl.create(:tag, :classification => cls) }

it 'returns with the parent and the child classification description' do
expect(name).to eq('foo: bar')
end
end
end
end

0 comments on commit 97786d3

Please sign in to comment.