summaryrefslogtreecommitdiff
path: root/spec/unit/node_spec.rb
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2012-12-11 22:13:13 -0800
committerBryan McLellan <btm@opscode.com>2013-04-01 10:03:19 -0700
commit172d5394daf216fb7c67729029d5856fb6cdb6ce (patch)
treedf471c46809abe192825966b076216c3ad89684c /spec/unit/node_spec.rb
parent4034b525289f0499d4f80810845169f8869e87d3 (diff)
downloadchef-172d5394daf216fb7c67729029d5856fb6cdb6ce.tar.gz
[CHEF-3683] Chef::Node objects should be sortable.
This commit adds a simple <=> method which will allow for Chef::Node objects to be ordered based on their name. The primary use case is sorting arrays of nodes for use in templates.
Diffstat (limited to 'spec/unit/node_spec.rb')
-rw-r--r--spec/unit/node_spec.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 3d32902b94..f466fd1db7 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -35,6 +35,13 @@ describe Chef::Node do
lambda{Chef::Node.build('solo node')}.should raise_error(Chef::Exceptions::ValidationFailed)
end
+ it "should be sortable" do
+ n1 = Chef::Node.build('alpha')
+ n2 = Chef::Node.build('beta')
+ n3 = Chef::Node.build('omega')
+ [n3, n1, n2].sort.first.should == n1
+ end
+
describe "when the node does not exist on the server" do
before do
response = OpenStruct.new(:code => '404')