Skip to content

Commit

Permalink
Merge pull request #18516 from djberg96/conversion_host_validations
Browse files Browse the repository at this point in the history
Default to resource name for conversion hosts
  • Loading branch information
agrare committed Mar 7, 2019
2 parents 2258269 + ec9b8d5 commit 297f4c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ConversionHost < ApplicationRecord

validate :resource_supports_conversion_host

before_validation :name, :default_name, :on => :create

include_concern 'Configurations'

after_create :tag_resource_as_enabled
Expand Down Expand Up @@ -227,4 +229,10 @@ def tag_resource_as_disabled
resource.tag_remove('v2v_transformation_method/vddk')
resource.tag_remove('v2v_transformation_method/ssh')
end

# Set the default name to the name of the associated resource.
#
def default_name
self.name ||= resource&.name
end
end
11 changes: 11 additions & 0 deletions spec/models/conversion_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,15 @@
expect(conversion_host.errors[:resource].first).to eql("can't be blank")
end
end

context "name validation" do
let(:ems) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone), :api_version => '4.2.4') }
let(:redhat_host) { FactoryBot.create(:host_redhat, :name => 'foo', :ext_management_system => ems) }

it "defaults to the associated resource name if no name is explicitly provided" do
conversion_host = ConversionHost.new(:resource => redhat_host)
expect(conversion_host.valid?).to be(true)
expect(conversion_host.name).to eql(redhat_host.name)
end
end
end

0 comments on commit 297f4c2

Please sign in to comment.