mbklein/confstruct — Issue #6: Unexpected behaviour when using #presence
Author: phorsuedzie
Created: 2012-02-08 16:56:07+00:00
State: open

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