Skip to content

Commit e2ff04f

Browse files
committed
We should honor auto-vivification on read in method_missing lookups
1 parent 8c0dd99 commit e2ff04f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎chef/lib/chef/node/attribute.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def method_missing(symbol, *args)
369369
if args.length != 0
370370
by = symbol
371371
else
372-
raise ArgumentError, "Attribute #{symbol.to_s} is not defined!"
372+
raise ArgumentError, "Attribute #{symbol.to_s} is not defined!" unless auto_vivifiy_on_read
373373
end
374374
end
375375

‎chef/spec/unit/node/attribute_spec.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@
462462
@attributes.reset
463463
@attributes.music.mastodon.should == [ "dream", "still", "shining" ]
464464
end
465+
466+
it "should honor auto-vivifiy on read" do
467+
@attributes.auto_vivifiy_on_read = true
468+
@attributes.rock.and.roll = "boom boom yeah"
469+
@attributes.reset
470+
@attributes.rock.and.roll.should == "boom boom yeah"
471+
end
465472
end
466473

467474
describe "keys" do

0 commit comments

Comments
 (0)