diff --git a/lib/disposable/twin/property/struct.rb b/lib/disposable/twin/property/struct.rb index 3f829b4..6cd0361 100644 --- a/lib/disposable/twin/property/struct.rb +++ b/lib/disposable/twin/property/struct.rb @@ -6,7 +6,7 @@ module Property module Struct def read_value_for(dfn, options) name = dfn[:name] - @model[name.to_s] || @model[name.to_sym] # TODO: test sym vs. str. + @model.key?(name.to_s) ? @model[name.to_s] : @model[name.to_sym] end def sync_hash_representer # TODO: make this without representable, please. diff --git a/test/twin/struct_test.rb b/test/twin/struct_test.rb index 8ed47f3..2e4a5ed 100644 --- a/test/twin/struct_test.rb +++ b/test/twin/struct_test.rb @@ -329,3 +329,15 @@ class Sheeeeeeet < Disposable::Twin end end + +class IndifferentAttributeAccessTwinStructTest < MiniTest::Spec + class Song < Disposable::Twin + include Property::Struct + property :cool? + end + + it { Song.new(cool?: true).cool?.must_equal true } + it { Song.new(cool?: false).cool?.must_equal false } + it { Song.new('cool?' => true).cool?.must_equal true } + it { Song.new('cool?' => false).cool?.must_equal false } +end \ No newline at end of file