diff --git a/app/models/organization.rb b/app/models/organization.rb index ed12b51..d5f4002 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -32,4 +32,12 @@ class Organization < Profile CreateEnterprise.pending_for(self, :code => code).first end + def processed_validations + CreateEnterprise.processed_for(self) + end + + def find_processed_validation(code) + CreateEnterprise.processed_for(self, :code => code).first + end + end diff --git a/app/models/task.rb b/app/models/task.rb index 0c8f60f..7c59fe6 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -138,6 +138,10 @@ class Task < ActiveRecord::Base def pending_for(target, conditions= nil) self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }.merge(conditions || {})) end + + def processed_for(target, conditions = nil) + self.find(:all, :conditions => { :target_id => target.id, :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }.merge(conditions || {})) + end # generates a random code string consisting of 36 characters in the ranges # a-z and 0-9 diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index fdf9e55..3a1c056 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -80,4 +80,18 @@ class OrganizationTest < Test::Unit::TestCase assert_nil org.find_pending_validation('lele') end + should 'be able to find already processed validations by target' do + org = Organization.new + empty = mock + CreateEnterprise.expects(:processed_for).with(org).returns(empty) + assert_same empty, org.processed_validations + end + + should 'be able to find an already processed validation by its code' do + org = Organization.new + empty = mock + CreateEnterprise.expects(:processed_for).with(org, {:code => 'lalalala'}).returns([empty]) + assert_same empty, org.find_processed_validation('lalalala') + end + end diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 776e9b9..3be869f 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -171,6 +171,31 @@ class TaskTest < Test::Unit::TestCase assert_equal [], Task.pending_for(target, :id => -1) 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 + + assert_equal [], Task.processed_for(target, :id => -1) + end + protected def sample_user -- libgit2 0.21.2