Skip to content

Commit

Permalink
Merge pull request #16411 from Ladas/log_name_instead_of_manager_ref
Browse files Browse the repository at this point in the history
Print name instead of manager ref
  • Loading branch information
agrare authored Nov 7, 2017
2 parents 9b2bb25 + 802a935 commit 543bf24
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/manager_refresh/target_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def name

# @return [String] A String containing an id of each target in the TargetCollection
def id
"Collection of targets with id: #{targets.collect(&:manager_ref)}"
"Collection of targets with id: #{targets.collect(&:name)}"
end

# Returns targets in a format:
Expand Down
53 changes: 44 additions & 9 deletions spec/models/manager_refresh/target_collection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
describe ManagerRefresh::TargetCollection do
before(:each) do
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_cloud, :zone => @zone)
@ems_event = FactoryGirl.create(:ems_event)
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_cloud, :zone => @zone, :name => "ems_name")
@ems_physical_infra = FactoryGirl.create(:ems_physical_infra, :zone => @zone)
@ems_event = FactoryGirl.create(:ems_event)

@vm_1 = FactoryGirl.create(
:vm_cloud,
:ext_management_system => @ems,
:ems_ref => "vm_1"
:ems_ref => "vm_1",
:name => "vm_1_name"
)

@vm_2 = FactoryGirl.create(
:vm_cloud,
:ext_management_system => @ems,
:ems_ref => "vm_2"
)

@host = FactoryGirl.create(
:host,
:ext_management_system => @ems,
:name => "host_1"
)

@physical_server = FactoryGirl.create(
:physical_server,
:ext_management_system => @ems_physical_infra,
:name => "physical_server_1"
)
end

context ".add_target" do
Expand Down Expand Up @@ -95,8 +109,17 @@
end

context ".name" do
it "prints names of all targets" do
target_collection = ManagerRefresh::TargetCollection.new(:manager_id => @ems.id, :event => @ems_event)
it "prints summary of all targets" do
target_collection = ManagerRefresh::TargetCollection.new(
:manager_id => @ems.id,
:event => @ems_event,
:targets => [
@vm_1,
@host,
@physical_server,
@ems
]
)

target_collection.add_target(
:association => :vms,
Expand All @@ -110,14 +133,22 @@
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)

expect(target_collection.name).to eq "Collection of 2 targets"
expect(target_collection.id).to eq "Collection of targets with id: [{:ems_ref=>\"vm_1\"}, {:ems_ref=>\"vm_2\"}]"
expect(target_collection.name).to eq "Collection of 6 targets"
end
end

context ".id" do
it "prints ids of all targets" do
target_collection = ManagerRefresh::TargetCollection.new(:manager_id => @ems.id, :event => @ems_event)
target_collection = ManagerRefresh::TargetCollection.new(
:manager_id => @ems.id,
:event => @ems_event,
:targets => [
@vm_1,
@host,
@physical_server,
@ems
]
)

target_collection.add_target(
:association => :vms,
Expand All @@ -133,6 +164,10 @@

expect(target_collection.id).to include ":ems_ref=>\"vm_1\""
expect(target_collection.id).to include ":ems_ref=>\"vm_2\""
expect(target_collection.id).to include "\"vm_1_name\""
expect(target_collection.id).to include "\"host_1\""
expect(target_collection.id).to include "\"physical_server_1\""
expect(target_collection.id).to include "\"ems_name\""
end
end

Expand Down

0 comments on commit 543bf24

Please sign in to comment.