From e0aad7836c649dc1d7d97a27d080cd0e659b57c7 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 30 Jun 2020 08:50:44 -0400 Subject: [PATCH] Add specs for create_from_params and edit_with_params --- .../foreman/configuration_manager_spec.rb | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/spec/models/manageiq/providers/foreman/configuration_manager_spec.rb b/spec/models/manageiq/providers/foreman/configuration_manager_spec.rb index 24ef530..d560ef9 100644 --- a/spec/models/manageiq/providers/foreman/configuration_manager_spec.rb +++ b/spec/models/manageiq/providers/foreman/configuration_manager_spec.rb @@ -1,13 +1,48 @@ describe ManageIQ::Providers::Foreman::ConfigurationManager do - let(:provider) { configuration_manager.provider } - let(:configuration_manager) do - FactoryBot.build(:configuration_manager_foreman) - end - describe "#connect" do + let(:provider) { configuration_manager.provider } + let(:configuration_manager) do + FactoryBot.build(:configuration_manager_foreman) + end + it "delegates to the provider" do expect(provider).to receive(:connect) configuration_manager.connect end end + + describe ".create_from_params" do + it "delegates endpoints, zone, name to provider" do + params = {:zone => FactoryBot.create(:zone), :name => "Foreman"} + endpoints = [{"role"=>"default", "url"=>"https://foreman", "verify_ssl"=>0}] + authentications = [{"authtype"=>"default", "userid"=>"admin", "password"=>"smartvm"}] + + config_manager = described_class.create_from_params(params, endpoints, authentications) + + expect(config_manager.provider.name).to eq("Foreman") + expect(config_manager.provider.endpoints.count).to eq(1) + end + end + + describe "#edit_with_params" do + let(:configuration_manager) do + FactoryBot.build(:configuration_manager_foreman, :name => "Foreman", :url => "https://localhost") + end + + it "updates the provider" do + params = {:zone => FactoryBot.create(:zone), :name => "Foreman 2"} + endpoints = [{"role"=>"default", "url"=>"https://foreman", "verify_ssl"=>0}] + authentications = [{"authtype"=>"default", "userid"=>"admin", "password"=>"smartvm"}] + + provider = configuration_manager.provider + expect(provider.name).to eq("Foreman") + expect(provider.url).to eq("https://localhost") + + configuration_manager.edit_with_params(params, endpoints, authentications) + + provider.reload + expect(provider.name).to eq("Foreman 2") + expect(provider.url).to eq("https://foreman") + end + end end