summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-11-15 13:42:37 -0800
committerGitHub <noreply@github.com>2016-11-15 13:42:37 -0800
commitb4c077bec9220a13489b2f125d59e0326232b93b (patch)
treeeadfe66599a9fc078aec0bec6fa08521185bec15
parentaa13c0639259219213cc938f27ec0365ddfe183f (diff)
parentc3f75bc59dfbae82ccb249659da898ce49179371 (diff)
downloadchef-b4c077bec9220a13489b2f125d59e0326232b93b.tar.gz
Merge pull request #5541 from chef/lcg/node-immutable-array-slice
fix ImmutableArray slices
-rw-r--r--lib/chef/node/mixin/state_tracking.rb7
-rw-r--r--spec/unit/node/immutable_collections_spec.rb5
-rw-r--r--spec/unit/node/vivid_mash_spec.rb11
3 files changed, 21 insertions, 2 deletions
diff --git a/lib/chef/node/mixin/state_tracking.rb b/lib/chef/node/mixin/state_tracking.rb
index 469d4d300f..5958973024 100644
--- a/lib/chef/node/mixin/state_tracking.rb
+++ b/lib/chef/node/mixin/state_tracking.rb
@@ -34,14 +34,17 @@ class Chef
@__precedence__ = precedence
end
- def [](key)
+ def [](*args)
ret = super
+ key = args.first
next_path = [ __path__, convert_key(key) ].flatten.compact
copy_state_to(ret, next_path)
end
- def []=(key, value)
+ def []=(*args)
ret = super
+ key = args.first
+ value = args.last
next_path = [ __path__, convert_key(key) ].flatten.compact
send_attribute_changed_event(next_path, value)
copy_state_to(ret, next_path)
diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb
index fe4e50d1bd..81dd771df3 100644
--- a/spec/unit/node/immutable_collections_spec.rb
+++ b/spec/unit/node/immutable_collections_spec.rb
@@ -198,4 +198,9 @@ describe Chef::Node::ImmutableArray do
end
end
+ describe "#[]" do
+ it "works with array slices" do
+ expect(@immutable_array[1, 2]).to eql(%w{bar baz})
+ end
+ end
end
diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb
index 017e6206fc..4898c22380 100644
--- a/spec/unit/node/vivid_mash_spec.rb
+++ b/spec/unit/node/vivid_mash_spec.rb
@@ -47,7 +47,18 @@ describe Chef::Node::VividMash do
end
end
+ context "#[]" do
+ it "works with array slices" do
+ expect(vivid["array"][1, 2]).to eql([1, 2])
+ end
+ end
+
context "#[]=" do
+ it "works with array slices" do
+ vivid["array"][3, 2] = [ 3, 4 ]
+ expect(vivid["array"]).to eql([0, 1, 2, 3, 4])
+ end
+
it "deep converts values through arrays" do
expect(root).to receive(:reset_cache).with("foo")
vivid["foo"] = [ { :bar => true } ]