From 9f70262378d2b46d4e3ebc7a45538cc5aa8bc40b Mon Sep 17 00:00:00 2001 From: "Michael T. Johnson" Date: Fri, 19 Mar 2021 13:54:30 -0400 Subject: [PATCH] Configatron::Store#fetch with a falsey default should set that default rather than nil --- lib/configatron/store.rb | 2 +- test/unit/configatron/store.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/configatron/store.rb b/lib/configatron/store.rb index c944635..17d8fda 100644 --- a/lib/configatron/store.rb +++ b/lib/configatron/store.rb @@ -71,7 +71,7 @@ def fetch(key, default_value = nil, &block) else if block val = block.call - elsif default_value + else val = default_value end store(key, val) diff --git a/test/unit/configatron/store.rb b/test/unit/configatron/store.rb index 6625c77..df7a1ff 100644 --- a/test/unit/configatron/store.rb +++ b/test/unit/configatron/store.rb @@ -49,6 +49,11 @@ class Critic::Unit::StoreTest < Critic::Unit::Test assert_equal("bar!!", @store.bar) end + it "sets and returns default_value if default is falsey" do + assert_equal(false, @store.fetch(:bar, false)) + assert_equal(false, @store.bar) + end + it "sets and returns the value of the block if no value is found" do @store.fetch(:bar) do "bar!"