You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by as...@apache.org on 2008/05/14 11:39:29 UTC

svn commit: r656181 - in /ode/sandbox/singleshot: app/models/stakeholder.rb app/models/task.rb spec/models/task_spec.rb

Author: assaf
Date: Wed May 14 02:39:28 2008
New Revision: 656181

URL: http://svn.apache.org/viewvc?rev=656181&view=rev
Log:
Added tests for etag.

Modified:
    ode/sandbox/singleshot/app/models/stakeholder.rb
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/spec/models/task_spec.rb

Modified: ode/sandbox/singleshot/app/models/stakeholder.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/stakeholder.rb?rev=656181&r1=656180&r2=656181&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/stakeholder.rb (original)
+++ ode/sandbox/singleshot/app/models/stakeholder.rb Wed May 14 02:39:28 2008
@@ -69,6 +69,11 @@
       define_method("#{plural}=") { |identities| set_role role, identities }
     end
 
+    # Returns true if person is a stakeholder in this task: any role except excluded owners list.
+    def stakeholder?(person)
+      stakeholders.any? { |sh| sh.person_id == person.id && sh.role != 'excluded' }
+    end
+
   private
 
     # Return all people in this role.

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=656181&r1=656180&r2=656181&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Wed May 14 02:39:28 2008
@@ -36,11 +36,18 @@
     id && id.to_s + ('-' + title).gsub(/[^\w]+/, '-').gsub(/-{2,}/, '-').sub(/-+$/, '')
   end
 
-  # --- Task state ---
-
   # Locking column used for versioning and detecting update conflicts.
   set_locking_column 'version'
 
+  # Returns an ETag that can identify changes to the task state.  No two tasks will have
+  # the same ETag.  Changing the task state will also change its ETag.
+  def etag
+    MD5.hexdigest("#{id}:#{version}")
+  end
+
+
+  # --- Task state ---
+
   # A task can be in one of these states:
   # - ready     -- Ready but not yet available/active, the task will not show on anyone's list.
   # - active    -- Task performed by owner.
@@ -79,34 +86,18 @@
   end
 
 
-  # Status starts as reserved or active, and changes from reserved to active on first update.
-  #validates_inclusion_of :status, :on=>:create, :in=>[:reserved, :active]
-  #before_validation_on_update { |task| task.status = :active if task.reserved? }
-  # Only assigned task can change to completed.
-  #validate { |task| task.errors.add :status, 'Only owner can complete task' if task.completed? && task.owner.nil? }
-
-  # Set task status to suspended and back to active.
-  #def suspended=(suspended)
-  #  self.status = suspended ? :suspended : :active if active? || suspended?
-  #end
-
+  # -- Common task attributes --
+  #
   # Task priority: 1 is the lowest (and default) priority.
   PRIORITIES = 1..3
   before_validation { |task| task.priority ||= PRIORITIES.min }
   validates_inclusion_of :priority, :in=>PRIORITIES
 
-  # Returns an ETag that can identify changes to the task state.  No two tasks will have
-  # the same ETag.  Changing the task state will also change its ETag.
-  def etag
-    MD5.hexdigest("#{id}:#{version}")
-  end
-
+  validates_presence_of :title, :frame_url
+  validates_url :frame_url, :if=>:frame_url
 
   # -- View and perform ---
 
-  #validates_presence_of :title, :frame_url, :unless=>:reserved?
-  #validates_url :frame_url, :if=>:frame_url
-
 
   # --- Completion and cancellation ---
 
@@ -169,8 +160,6 @@
 
   # --- Stakeholders ---
 
-  #include Stakeholder::Roles
-
   # Stakeholders and people (as stakeholders) associated with this task.
   has_many :stakeholders, :include=>:person, :dependent=>:delete_all
   attr_protected :stakeholders
@@ -178,12 +167,6 @@
   include Stakeholder::Accessors
   include Stakeholder::Validation
 
-  # Returns true if person is a stakeholder in this task (equivalent to asking if in any role).
-  # Includes all global administrators but excludes excluded owners.
-  def stakeholder?(person)
-    person == owner || person == creator || person.admin? ||
-      stakeholders.any? { |sh| sh.person_id == person.id && sh.role != :excluded_owner }
-  end
 
   # --- Access control ---
 

Modified: ode/sandbox/singleshot/spec/models/task_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/task_spec.rb?rev=656181&r1=656180&r2=656181&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/task_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/task_spec.rb Wed May 14 02:39:28 2008
@@ -41,6 +41,35 @@
 end
 
 
+describe Task, 'etag' do
+  include Specs::Tasks
+
+  before do
+    @task = Task.create(default_task)
+  end
+
+  it 'should be hex digest' do
+    Task.create default_task
+    Task.first.etag.should =~ /^[0-9a-f]{32}$/
+  end
+
+  it 'should remain the same if task not modified' do
+    Task.create default_task
+    Task.first.etag.should == Task.first.etag
+  end
+
+  it 'should be different for two different tasks' do
+    Task.create(default_task).etag.should_not == Task.create(default_task).etag
+  end
+
+  it 'should change whenever task is saved' do
+    Task.create default_task
+    lambda { Task.first.update_attributes! :priority=>2 }.should change { Task.first.etag }
+  end
+
+end
+
+
 describe Task, 'state' do
   include Specs::Tasks