Skip to content

Commit

Permalink
fix: don't cast the value provided as a default
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Apr 4, 2023
1 parent 3d02451 commit 8a4f160
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ GEM

PLATFORMS
arm64-darwin-21
arm64-darwin-22

DEPENDENCIES
konfig-config!
Expand Down
2 changes: 1 addition & 1 deletion lib/konfig/schema_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_hash(path, source = nil)
@attributes.each_with_object({}) do |(name, attribute), hash|
attribute_path = path + [name]
if source.nil?
hash[name] = attribute.cast(attribute.default)
hash[name] = attribute.default
else
begin
source_value = source.get(attribute_path, attribute: attribute)
Expand Down
7 changes: 6 additions & 1 deletion spec/specs/schema_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ module Konfig
context 'when not given a source' do
it 'returns a hash with the default values only' do
group.add_attribute(:hostname, default: 'localhost')
group.add_attribute(:port, default: 8080)
group.add_attribute(:port, default: '8080')
expect(group.create_hash([])).to eq(hostname: 'localhost', port: '8080')
end

it 'does not cast the values provided as the default' do
group.add_attribute(:hostname, default: 12_345)
expect(group.create_hash([])).to eq(hostname: 12_345)
end

it 'does include attributes that do not have a default value' do
group.add_attribute(:hostname)
group.add_attribute(:port)
Expand Down

0 comments on commit 8a4f160

Please sign in to comment.