Skip to content

Commit

Permalink
Fixes #30339 - isolate LookupKey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezr-ondrej authored and Shira Maximov committed Jul 30, 2020
1 parent 0ebfc18 commit c4c097f
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 224 deletions.
10 changes: 10 additions & 0 deletions app/models/lookup_keys/lookup_key.rb
Expand Up @@ -28,6 +28,9 @@ class LookupKey < ApplicationRecord
validates_associated :lookup_values

before_validation :sanitize_path
before_validation :cast_default_value, :if => :override?
validate :validate_default_value, :disable_avoid_duplicates, :disable_merge_overrides, :disable_merge_default, :if => :override?
after_validation :reset_override_params, :if => ->(key) { key.override_changed? && !key.override? }
attr_name :key

def self.inherited(child)
Expand Down Expand Up @@ -141,6 +144,13 @@ def sorted_values

private

def reset_override_params
self.merge_overrides = false
self.avoid_duplicates = false
self.merge_default = false
true
end

def sanitize_path
self.path = path.tr("\s", "").downcase if path.present?
end
Expand Down
11 changes: 0 additions & 11 deletions app/models/lookup_keys/puppetclass_lookup_key.rb
Expand Up @@ -3,10 +3,7 @@ class PuppetclassLookupKey < LookupKey
has_many :environments, -> { distinct }, :through => :environment_classes
has_many :param_classes, :through => :environment_classes, :source => :puppetclass

before_validation :cast_default_value, :if => :override?
before_validation :check_override_selected, :if => -> { persisted? && @validation_context != :importer }
validate :validate_default_value, :disable_merge_overrides, :disable_avoid_duplicates, :disable_merge_default, :if => :override?
after_validation :reset_override_params, :if => ->(key) { key.override_changed? && !key.override? }

scoped_search :relation => :param_classes, :on => :name, :rename => :puppetclass, :aliases => [:puppetclass_name], :complete_value => true
scoped_search :relation => :environments, :on => :name, :rename => :environment, :complete_value => true, :only_explicit => true
Expand Down Expand Up @@ -47,14 +44,6 @@ def puppet?
true
end

def reset_override_params
self.merge_overrides = false
self.avoid_duplicates = false
self.merge_default = false

true
end

def check_override_selected
return if (changed - ['description', 'override']).empty?
return if override?
Expand Down
7 changes: 7 additions & 0 deletions test/factories/lookups.rb
Expand Up @@ -29,6 +29,11 @@
default_value { '[{"hostname": "test.example.com"}]' }
end

trait :hash do
key_type { 'hash' }
default_value { '{"hostname": "test.example.com"}' }
end

trait :with_omit do
omit { true }
end
Expand All @@ -47,6 +52,8 @@
'--- \nfoo: overridden\n'
when 'array'
'[{"overridden": "value"}]'
when 'hash'
'{"overridden": "value"}'
else
'overridden value'
end,
Expand Down

0 comments on commit c4c097f

Please sign in to comment.