Skip to content

Commit 37c5c89

Browse files
committed
Ensure :autoconvert is initialized before :value for rabbitmq_parameter
1 parent f70f22c commit 37c5c89

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/puppet/type/rabbitmq_parameter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
[self[:name].split('@')[1]]
8383
end
8484

85+
def set_parameters(hash) # rubocop:disable Style/AccessorMethodName
86+
# Hack to ensure :autoconvert is initialized before :value
87+
self[:autoconvert] = hash[:autoconvert] if hash.key?(:autoconvert)
88+
super
89+
end
90+
8591
def validate_component_name(value)
8692
raise ArgumentError, 'component_name must be defined' if value.empty?
8793
end
@@ -96,7 +102,7 @@ def validate_value(value)
96102
end
97103

98104
def munge_value(value)
99-
return value if self[:autoconvert] == :false
105+
return value if value(:autoconvert) == :false
100106
value.each do |k, v|
101107
value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z}
102108
end

spec/unit/puppet/type/rabbitmq_parameter_spec.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@
8383
expect(parameter[:value]['myparameter']).to eq(1_800_000)
8484
end
8585

86-
it 'does not convert numeric string to integer when autoconvert is set to false' do
87-
parameter[:autoconvert] = false
88-
value = { 'myparameter' => '1800000' }
89-
parameter[:value] = value
90-
expect(parameter[:value]['myparameter']).to eq('1800000')
91-
expect(parameter[:value]['myparameter']).to be_kind_of(String)
86+
context 'autoconvert is set to false' do
87+
let(:parameter) do
88+
Puppet::Type.type(:rabbitmq_parameter).new(
89+
name: 'documentumShovel@/',
90+
component_name: 'shovel',
91+
autoconvert: false,
92+
value: { 'myparameter' => '1800000' }
93+
)
94+
end
95+
96+
it 'does not convert numeric string to integer' do
97+
expect(parameter[:value]['myparameter']).to eq('1800000')
98+
expect(parameter[:value]['myparameter']).to be_kind_of(String)
99+
end
92100
end
93101
end

0 commit comments

Comments
 (0)