Skip to content

Commit 4a1b348

Browse files
author
Nuo Yan
committed
not loading environment object in node's expand! method if the environment is _default
1 parent eed9dde commit 4a1b348

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎chef/lib/chef/node.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def expand!
433433

434434
self[:tags] = Array.new unless attribute?(:tags)
435435
@default_attrs = Chef::Mixin::DeepMerge.merge(default_attrs, expansion.default_attrs)
436-
@override_attrs = Chef::Mixin::DeepMerge.merge(Chef::Mixin::DeepMerge.merge(override_attrs, expansion.override_attrs), Chef::Environment.load(chef_environment).attributes)
436+
@override_attrs = Chef::Mixin::DeepMerge.merge(Chef::Mixin::DeepMerge.merge(override_attrs, expansion.override_attrs), chef_environment == "_default" ? {} : Chef::Environment.load(chef_environment).attributes)
437437
@automatic_attrs[:recipes] = expansion.recipes
438438
@automatic_attrs[:roles] = expansion.roles
439439

‎chef/spec/unit/environment_spec.rb‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@
6868
end
6969
end
7070

71+
describe "attributes" do
72+
it "should let you set the attributes hash explicitly" do
73+
@environment.attributes({ :one => 'two' }).should == { :one => 'two' }
74+
end
75+
76+
it "should let you return the attributes hash" do
77+
@environment.attributes({ :one => 'two' })
78+
@environment.attributes.should == { :one => 'two' }
79+
end
80+
81+
it "should throw an ArgumentError if we aren't a kind of hash" do
82+
lambda { @environment.attributes(Array.new) }.should raise_error(ArgumentError)
83+
end
84+
end
85+
7186
describe "cookbook_versions" do
7287
before(:each) do
7388
@cookbook_versions = {
@@ -315,22 +330,28 @@
315330

316331
describe "self.create_default_environment" do
317332
it "should check if the '_default' environment exists" do
318-
Chef::Environment.should_receive(:cdb_load).with('_default')
333+
@couchdb = Chef::CouchDB.new
334+
Chef::CouchDB.stub!(:new).and_return @couchdb
335+
Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new)
319336
Chef::Environment.create_default_environment
320337
end
321338

322339
it "should not re-create the environment if it exists" do
323-
Chef::Environment.should_receive(:cdb_load).with('_default').and_return true
340+
@couchdb = Chef::CouchDB.new
341+
Chef::CouchDB.stub!(:new).and_return @couchdb
342+
Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new).and_return true
324343
Chef::Environment.should_not_receive(:new)
325344
Chef::Environment.create_default_environment
326345
end
327346

328347
it "should create the environment if it doesn't exist" do
329348
@env = Chef::Environment.new
330349
@env.stub!(:cdb_save).and_return true
350+
@couchdb = Chef::CouchDB.new
331351
Chef::Environment.stub!(:new).and_return @env
352+
Chef::CouchDB.stub!(:new).and_return @couchdb
332353

333-
Chef::Environment.should_receive(:cdb_load).with('_default').and_raise(Chef::Exceptions::CouchDBNotFound)
354+
Chef::Environment.should_receive(:cdb_load).with('_default', Chef::CouchDB.new).and_raise(Chef::Exceptions::CouchDBNotFound)
334355
Chef::Environment.should_receive(:new)
335356
Chef::Environment.create_default_environment
336357
end

0 commit comments

Comments
 (0)