From: Tomas Sedovic <[email protected]>

These requirements make sure that the records of task creation, start and end
time are consistent.

The tests are failing now.
---
 src/spec/models/task_spec.rb |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/spec/models/task_spec.rb b/src/spec/models/task_spec.rb
index ffdb604..d392cb2 100644
--- a/src/spec/models/task_spec.rb
+++ b/src/spec/models/task_spec.rb
@@ -3,21 +3,28 @@ require 'spec_helper'
 describe Task do
 
   before(:each) do
+    @valid_attributes = { :created_at => Time.now,
+      :time_started => Time.now + 3.minutes,
+      :time_ended => Time.now + 5.minutes,
+      :state => Task::STATE_FINISHED }
     @task = InstanceTask.new( {} )
   end
 
+  it "should be valid with the test data" do
+    @task.attributes = @valid_attributes
+    @task.should be_valid
+  end
+
   it "should begin in a queued state" do
     @task.state.should eql('queued')
   end
 
   it "should be invalid with unknown type" do
-    @task.should be_valid
     @task.type = 'TotallyInvalidTask'
     @task.should_not be_valid
   end
 
   it "should be invalid with unknown state" do
-    @task.should be_valid
     @task.state = 'BetYouDidNotExpectThisState'
     @task.should_not be_valid
   end
@@ -31,4 +38,27 @@ describe Task do
     @task.type_label.should eql('Instance')
   end
 
+  it "should have 'created at' time set if it started" do
+    @task.attributes = @valid_attributes.except :created_at
+    @task.should_not be_valid
+  end
+
+  it "should have 'started' time set if it ended" do
+    @task.attributes = @valid_attributes.except :time_started
+    @task.should_not be_valid
+  end
+
+  it "should not be valid if it started before it was created" do
+    @task.attributes = @valid_attributes
+    @task.time_started = @task.created_at - 1.minute
+    @task.should_not be_valid
+  end
+
+  it "should not be valid if it ended before it was started" do
+    @task.attributes = @valid_attributes
+    @task.time_ended = @task.time_started - 1.minute
+    @task.should_not be_valid
+  end
+
+
 end
-- 
1.6.6.1

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to