From 97786d33de2e335e52a34e6f8e772f4ef2f3daa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Tue, 12 Dec 2017 15:22:58 +0100 Subject: [PATCH] Name the tags on the topology screens based on its classifications https://bugzilla.redhat.com/show_bug.cgi?id=1467805 --- app/services/topology_service.rb | 11 ++++++++++- spec/services/topology_service_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/services/topology_service.rb b/app/services/topology_service.rb index dc11fb80b6a7..02537d586aa2 100644 --- a/app/services/topology_service.rb +++ b/app/services/topology_service.rb @@ -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, diff --git a/spec/services/topology_service_spec.rb b/spec/services/topology_service_spec.rb index ab3beb1f5391..930b840bcc38 100644 --- a/spec/services/topology_service_spec.rb +++ b/spec/services/topology_service_spec.rb @@ -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