Skip to content

Commit

Permalink
Merge pull request #16529 from elad661/default-name-to-description
Browse files Browse the repository at this point in the history
Default name to description for MiqAlertSet and MiqPolicySet
  • Loading branch information
gtanzillo authored Dec 11, 2017
2 parents 5729359 + 6db0e72 commit 7ada04e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion app/models/miq_alert_set.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MiqAlertSet < ApplicationRecord
acts_as_miq_set

before_validation :default_name_to_guid, :on => :create
before_validation :default_name_to_description, :on => :create

include AssignmentMixin

Expand Down Expand Up @@ -48,4 +48,10 @@ def self.seed
return unless File.exist?(fixture_file)
File.open(fixture_file) { |fd| MiqAlertSet.import_from_yaml(fd, :save => true) }
end

private

def default_name_to_description
self.name ||= description
end
end
8 changes: 7 additions & 1 deletion app/models/miq_policy_set.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MiqPolicySet < ApplicationRecord
acts_as_miq_set

before_validation :default_name_to_guid, :on => :create
before_validation :default_name_to_description, :on => :create
before_destroy :destroy_policy_tags

attr_accessor :reserved
Expand Down Expand Up @@ -84,4 +84,10 @@ def self.seed
end
end
end

private

def default_name_to_description
self.name ||= description
end
end # class MiqPolicySet
8 changes: 4 additions & 4 deletions spec/models/miq_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# calling conditions.

before(:each) do
@ps = FactoryGirl.create(:miq_policy_set)
@ps = FactoryGirl.create(:miq_policy_set, :name => "ps")
@p = FactoryGirl.create(:miq_policy)
@ps.add_member(@p)

@ps2 = FactoryGirl.create(:miq_policy_set)
@ps2 = FactoryGirl.create(:miq_policy_set, :name => "ps2")
@p2 = FactoryGirl.create(:miq_policy)
end

Expand Down Expand Up @@ -159,8 +159,8 @@

let(:profiles) do
[
FactoryGirl.create(:miq_policy_set).tap { |pf| pf.add_member(policies[0]) },
FactoryGirl.create(:miq_policy_set).tap { |pf| pf.add_member(policies[1]) },
FactoryGirl.create(:miq_policy_set, :name => "ps3").tap { |pf| pf.add_member(policies[0]) },
FactoryGirl.create(:miq_policy_set, :name => "ps4").tap { |pf| pf.add_member(policies[1]) },
]
end

Expand Down

0 comments on commit 7ada04e

Please sign in to comment.