Unexpected behaviour when using #presence
phorsuedzie opened this issue · comments
Given I create a Confstruct::Configuration from a Hash
When I call #presence on a deep value
Then I should get the value # or at least something behaving equally
This fails - because #presence (called for an HashWithStructAccess with ActiveSupport) will return the value converted to an OrderedHash:
$#> irb -f
# set up env
require 'rubygems'
# => true
require 'active_support/core_ext/object/blank'
# => true
require 'confstruct' # 0.2.1
# => true
# set up data
c = Confstruct::Configuration.new("a" => {"b" => {"c" => "d"}})
# => {:a=>{:b=>{:c=>"d"}}}
# access data
c["a"]["b"].class
# => Confstruct::HashWithStructAccess
# ooops!
c["a"]["b"].presence.class
# => ActiveSupport::OrderedHash
Unfortunately, the OrderedHash is not .with_indifferent_access:
# surprise! :-(
c["a"]["b"]["c"]
# => "d"
c["a"]["b"].presence["c"]
# => nil
This seems to be an artifact of the Delegator implementation I'm using. I've started investigating workarounds, but no luck so far. I'll have to think about the best way to ensure that the right typecasting happens all the way down. Thanks for bringing it to my attention.