Skip to content

Commit

Permalink
Merge pull request #17662 from kbrock/miq_server_zone_description
Browse files Browse the repository at this point in the history
Miq server zone description
  • Loading branch information
bdunne authored Jul 5, 2018
2 parents ce4d2b5 + 545e771 commit d9b0f6c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MiqServer < ApplicationRecord
acts_as_miq_taggable
include RelationshipMixin

alias_attribute :description, :name

belongs_to :vm, :inverse_of => :miq_server
belongs_to :zone
has_many :messages, :as => :handler, :class_name => 'MiqQueue'
Expand All @@ -29,14 +31,12 @@ class MiqServer < ApplicationRecord
before_destroy :validate_is_deleteable
after_destroy :destroy_linked_events_queue

virtual_column :zone_description, :type => :string

default_value_for(:name, "EVM")
default_value_for(:zone) { Zone.default_zone }

scope :active_miq_servers, -> { where(:status => STATUSES_ACTIVE) }
scope :with_zone_id, ->(zone_id) { where(:zone_id => zone_id) }
delegate :description, :to => :zone, :prefix => true
virtual_delegate :description, :to => :zone, :prefix => true

STATUS_STARTING = 'starting'.freeze
STATUS_STARTED = 'started'.freeze
Expand Down
14 changes: 14 additions & 0 deletions spec/models/miq_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,18 @@
expect(described_class.new(:status => "stopped").active?).to be_falsey
end
end

describe "#zone_description" do
it "delegates to zone" do
_, miq_server, zone = EvmSpecHelper.create_guid_miq_server_zone
expect(miq_server.zone_description).to eq(zone.description)
end
end

describe "#description" do
it "doesnt blowup" do
s = described_class.new(:name => "name")
expect(s.description).to eq(s.name)
end
end
end

0 comments on commit d9b0f6c

Please sign in to comment.