Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Integer to print_recursive #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions spec/classes/prosody_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
end

context 'with custom options' do
let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux' } } }
let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux', 'int' => 42 } } }

it {
is_expected.to contain_file('/etc/prosody/prosody.cfg.lua'). \
with_content(%r{^foo = "bar"$}, %r{^baz = "quux"$})
with_content(%r{^foo = "bar"$}, %r{^baz = "quux"$}).\
with_content(%r{^int = 42$})
}
end

Expand Down
15 changes: 9 additions & 6 deletions spec/defines/virtualhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,35 @@
end

context 'with custom options' do
let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux' } } }
let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux', 'int' => 42 } } }

it {
is_expected.to contain_file(path_avail). \
with_content(%r{^foo = "bar"$}, %r{^baz = "quux"$})
with_content(%r{^foo = "bar"$}, %r{^baz = "quux"$}).\
with_content(%r{^int = 42:$})
}
end

context 'with deeply nested custom options' do
let(:params) { { custom_options: { 'foo' => { 'fnord' => '23', 'xyzzy' => '42' }, 'bar' => %w[cool elements], 'baz' => 'quux' } } }
let(:params) { { custom_options: { 'foo' => { 'fnord' => '23', 'xyzzy' => '42' }, 'bar' => %w[cool elements], 'baz' => 'quux', 'int' => 42 } } }

it {
is_expected.to contain_file(path_avail). \
with_content(%r{^foo = {\n fnord = "23";\n xyzzy = "42";\n}$}, %r{^baz = "quux"$}, %r{^bar = [ "cool"; "elements" ]$})
with_content(%r{^foo = {\n fnord = "23";\n xyzzy = "42";\n}$}, %r{^baz = "quux"$}, %r{^bar = [ "cool"; "elements" ]$}).\
with_content(%r{^int = 42:$})
}
end

context 'with deeply nested component options' do
let(:params) { { components: { 'comp1' => { 'type' => 'muc', 'options' => { 'bo' => true, 'arr' => %w[one two], 'str' => 'string' } } } } }
let(:params) { { components: { 'comp1' => { 'type' => 'muc', 'options' => { 'bo' => true, 'arr' => %w[one two], 'str' => 'string', 'int' => 42 } } } } }

it {
is_expected.to contain_file(path_avail). \
with_content(%r{^Component "comp1" "muc"$}). \
with_content(%r{^ bo = true;$}). \
with_content(%r{^ arr = { "one"; "two" };$}).\
with_content(%r{^ str = "string";$})
with_content(%r{^ str = "string";$}).\
with_content(%r{^ int = 42;$}).\
}
end

Expand Down
2 changes: 1 addition & 1 deletion templates/prosody.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def print_recursive(object, indentation = 0)
'{ "' + object.join('"; "') + '" }'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
when TrueClass, FalseClass, Integer
object.to_s
else
'"' + object.to_s + '"'
Expand Down
2 changes: 1 addition & 1 deletion templates/virtualhost.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def print_recursive(object, indentation = 0)
'{ "' + object.join('"; "') + '" }'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
when TrueClass, FalseClass, Integer
object.to_s
else
'"' + object.to_s + '"'
Expand Down