From ffc26a001c5ae16a68c1d51bf1097244790040f2 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 22 Feb 2008 23:05:03 +0000 Subject: [PATCH] ActionItem36: changing the interface for requesting pending and finished tasks --- app/models/task.rb | 8 ++++---- test/unit/task_test.rb | 55 ++++++++++++++----------------------------------------- 2 files changed, 18 insertions(+), 45 deletions(-) diff --git a/app/models/task.rb b/app/models/task.rb index 04ec99a..bf781c1 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -149,12 +149,12 @@ class Task < ActiveRecord::Base class << self - def pending_for(target, conditions= nil) - self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }.merge(conditions || {})) + def pending + self.find(:all, :conditions => { :status => Task::Status::ACTIVE }) end - def processed_for(target, conditions = nil) - self.find(:all, :conditions => { :target_id => target.id, :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }.merge(conditions || {})) + def finished + self.find(:all, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED]}) end # generates a random code string consisting of 36 characters in the ranges diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 3be869f..4f605b8 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -149,51 +149,24 @@ class TaskTest < Test::Unit::TestCase task.save! end - should 'be able to list pending tasks for a given target' do - target = sample_user + should 'be able to list pending tasks' do + Task.delete_all + t1 = Task.create! + t2 = Task.create! + t2.finish + t3 = Task.create! - assert_equal [], Task.pending_for(target) - - task = Task.new - task.target = target - task.save! - - assert_equal [task], Task.pending_for(target) - end - - should 'be able to pass extra conditions for getting pending tasks' do - target = sample_user - - task = Task.new - task.target = target - task.save! - - assert_equal [], Task.pending_for(target, :id => -1) + assert_equal [t1,t3], Task.pending end - should 'be able to list processed tasks' do - target = sample_user - - task = Task.new - task.target = target - task.finish - - # this one shouldn't be listed as processed, since it was not - task2 = Task.new - task2.target = target - target.save! - - assert_equal [task], Task.processed_for(target) - end - - should 'be able to pass optional parameters for getting processed tasks' do - target = sample_user - - task = Task.new - task.target = target - task.finish + should 'be able to list finished tasks' do + Task.delete_all + t1 = Task.create! + t2 = Task.create! + t2.finish + t3 = Task.create! - assert_equal [], Task.processed_for(target, :id => -1) + assert_equal [t2], Task.finished end protected -- libgit2 0.21.2