From: David Lutterkort <[email protected]>
These tests only perform basic collection sanity checks, and are therefore
applicable for most collections
---
tests/cimi/machine_collection_test.rb | 4 +++-
tests/cimi/network_collection_test.rb | 15 +--------------
tests/cimi/test_helper.rb | 21 +++++++++++++++++++++
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/tests/cimi/machine_collection_test.rb
b/tests/cimi/machine_collection_test.rb
index c390b5b..a5ad3f4 100644
--- a/tests/cimi/machine_collection_test.rb
+++ b/tests/cimi/machine_collection_test.rb
@@ -24,9 +24,11 @@ class MachineCollectionBehavior < CIMI::Test::Spec
model :machines, CIMI::Model::MachineCollection do |fmt|
mcoll_uri = cep(:accept => :json).json["machines"]["href"]
- get(mcoll_uri, :accept => :json)
+ get(mcoll_uri, :accept => fmt)
end
+ check_collection :machines, CIMI::Model::Machine
+
it "should have the correct resourceURI", :only => :json do
machines.wont_be_nil # Make sure we talk to the server
last_response.json["resourceURI"].must_equal RESOURCE_URI
diff --git a/tests/cimi/network_collection_test.rb
b/tests/cimi/network_collection_test.rb
index 3e8872b..cd01583 100644
--- a/tests/cimi/network_collection_test.rb
+++ b/tests/cimi/network_collection_test.rb
@@ -27,18 +27,5 @@ class NetworkCollectionBehavior < CIMI::Test::Spec
get(coll_uri, :accept => fmt)
end
- it "must have the \"id\" and \"count\" attributes" do
- networks.count.wont_be_nil
- networks.count.to_i.must_equal networks.entries.size
- networks.id.must_be_uri
- end
-
- it "must have a valid id and name for each member" do
- networks.entries.each do |entry|
- entry.id.must_be_uri
- member = fetch(entry.id, CIMI::Model::Network)
- member.id.must_equal entry.id
- member.name.must_equal entry.name
- end
- end
+ check_collection :networks, CIMI::Model::Network
end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index e264af3..303cce0 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -122,6 +122,27 @@ module CIMI::Test::Methods
end
end
end
+
+ # Perform basic collection checks; +model_name+ is the name of the
+ # method returning the collection model; +member_class+ is the class
+ # for the model of individual entries
+ def check_collection(model_name, member_class)
+ it "must have the \"id\" and \"count\" attributes" do
+ coll = self.send(model_name)
+ coll.count.wont_be_nil
+ coll.count.to_i.must_equal coll.entries.size
+ coll.id.must_be_uri
+ end
+
+ it "must have a valid id and name for each member" do
+ self.send(model_name).entries.each do |entry|
+ entry.id.must_be_uri
+ member = fetch(entry.id, member_class)
+ member.id.must_equal entry.id
+ member.name.must_equal entry.name
+ end
+ end
+ end
end
def self.included(base)
--
1.7.7.6