Skip to content

Commit

Permalink
Addressed code climate error
Browse files Browse the repository at this point in the history
Added spec test to verify that `fetch_playook_details` sets data for tabs correctly.
  • Loading branch information
h-kataria committed Mar 23, 2017
1 parent 3ce463c commit 60938b1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
19 changes: 9 additions & 10 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1797,11 +1797,7 @@ def fetch_playbook_details
playbook_details[:provisioning][:machine_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential.find_by(:id => provision[:credential_id]).name
playbook_details[:provisioning][:network_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential.find_by(:id => provision[:network_credential_id]).name if provision[:network_credential_id]
playbook_details[:provisioning][:cloud_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential.find_by(:id => provision[:cloud_credential_id]).name if provision[:cloud_credential_id]
if provision[:dialog_id]
dialog = Dialog.find_by(:id => provision[:dialog_id])
playbook_details[:provisioning][:dialog] = dialog.name
playbook_details[:provisioning][:dialog_id] = dialog.id
end
fetch_dialog(playbook_details, provision[:dialog_id], :provisioning)

if @record.config_info[:retirement]
retirement = @record.config_info[:retirement]
Expand All @@ -1813,16 +1809,19 @@ def fetch_playbook_details
playbook_details[:retirement][:machine_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential.find_by(:id => retirement[:credential_id]).name
playbook_details[:retirement][:network_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential.find_by(:id => retirement[:network_credential_id]).name if retirement[:network_credential_id]
playbook_details[:retirement][:cloud_credential] = ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential.find_by(:id => retirement[:cloud_credential_id]).name if retirement[:cloud_credential_id]
if retirement[:dialog_id]
dialog = Dialog.find_by(:id => retirement[:dialog_id])
playbook_details[:retirement][:dialog] = dialog.name
playbook_details[:retirement][:dialog_id] = dialog.id
end
fetch_dialog(playbook_details, retirement[:dialog_id], :retirement)
end
end
playbook_details
end

def fetch_dialog(playbook_details, dialog_id, key)
return nil if dialog_id.nil?
dialog = Dialog.find_by(:id => dialog_id)
playbook_details[key][:dialog] = dialog.name
playbook_details[key][:dialog_id] = dialog.id
end

def open_parent_nodes(record)
existing_node = nil # Init var

Expand Down
63 changes: 63 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,67 @@
expect(assigns(:edit)[:new][:available_resources].count).to eq(2)
end
end

context "#fetch_playbook_details" do
let(:auth) { FactoryGirl.create(:authentication, :name => "machine_cred", :manager_ref => 6, :type => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential") }
let(:repository) { FactoryGirl.create(:configuration_script_source, :manager => ems, :type => "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource") }
let(:inventory_root_group) { FactoryGirl.create(:inventory_root_group, :name => 'Demo Inventory') }
let(:ems) do
FactoryGirl.create(:automation_manager_ansible_tower, :inventory_root_groups => [inventory_root_group], :provider => FactoryGirl.create(:provider_embedded_ansible))
end
let(:dialog) { FactoryGirl.create(:dialog, :label => "Some Label") }
let(:playbook) do
FactoryGirl.create(:embedded_playbook,
:configuration_script_source => repository,
:manager => ems,
:inventory_root_group => inventory_root_group)
end

it "returns playbook service template details for provision & retirement tabs for summary screen" do
options = {
:name => 'test_ansible_catalog_item',
:description => 'test ansible',
:display => true,
:config_info => {
:provision => {
:new_dialog_name => 'test_dialog',
:hosts => 'many',
:credential_id => auth.id,
:repository_id => repository.id,
:playbook_id => playbook.id,
:dialog_id => dialog.id
},
:retirement => {
:new_dialog_name => 'test_dialog',
:hosts => 'many',
:credential_id => auth.id,
:repository_id => repository.id,
:playbook_id => playbook.id,
:dialog_id => dialog.id
}
}
}
service_template = double("ServiceTemplateAnsiblePlaybook", options)
controller.instance_variable_set(:@record, service_template)
playbook_details = controller.send(:fetch_playbook_details)
st_details = {
:provisioning => {
:repository => repository.name,
:playbook => playbook.name,
:machine_credential => auth.name,
:dialog => "Some Label",
:dialog_id => dialog.id
},
:retirement => {
:remove_resources => nil,
:repository => repository.name,
:playbook => playbook.name,
:machine_credential => auth.name,
:dialog => "Some Label",
:dialog_id => dialog.id
}
}
expect(playbook_details).to eq(st_details)
end
end
end

0 comments on commit 60938b1

Please sign in to comment.