Skip to content
Merged
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: 4 additions & 1 deletion lib/hocon/impl/simple_config_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'hocon/impl'
require 'hocon/parser/config_document'
require 'hocon/impl/config_document_parser'
require 'hocon/config_render_options'

class Hocon::Impl::SimpleConfigDocument
include Hocon::Parser::ConfigDocument
Expand All @@ -23,7 +24,9 @@ def set_value(path, new_value)
end

def set_config_value(path, new_value)
set_value(path, new_value.render.strip)
options = Hocon::ConfigRenderOptions.defaults
options.origin_comments = false
set_value(path, new_value.render(options).strip)
end

def remove_value(path)
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/typesafe/config/config_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,15 @@
config_document = ConfigDocumentFactory.parse_string(orig_text)
map_val = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})

expect(config_document.set_config_value("a", map_val).render).to eq("a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n}")
expect(config_document.set_config_value("a", map_val).render).to eq("a : {\n \"a\" : 1,\n \"b\" : 2\n}")
end

it "should successfully insert an array into an empty document" do
orig_text = ""
config_document = ConfigDocumentFactory.parse_string(orig_text)
array_val = ConfigValueFactory.from_any_ref([1,2])

expect(config_document.set_config_value("a", array_val).render).to eq("a : [\n # hardcoded value\n 1,\n # hardcoded value\n 2\n]")
expect(config_document.set_config_value("a", array_val).render).to eq("a : [\n 1,\n 2\n]")
end
end

Expand All @@ -570,7 +570,7 @@
config_document = ConfigDocumentFactory.parse_string(orig_text)

map = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})
expect(config_document.set_config_value("a", map).render).to eq("{ a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n } }")
expect(config_document.set_config_value("a", map).render).to eq("{ a : {\n \"a\" : 1,\n \"b\" : 2\n } }")
end
end
end