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!"