Commit e8d6d9a63a424db9b8712a726810035642d8b5a6

Authored by AntonioTerceiro
1 parent db1140ee

ActionItem16: finding processed tasks (and consequently, enterprise validations)



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@866 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/organization.rb
... ... @@ -32,4 +32,12 @@ class Organization < Profile
32 32 CreateEnterprise.pending_for(self, :code => code).first
33 33 end
34 34  
  35 + def processed_validations
  36 + CreateEnterprise.processed_for(self)
  37 + end
  38 +
  39 + def find_processed_validation(code)
  40 + CreateEnterprise.processed_for(self, :code => code).first
  41 + end
  42 +
35 43 end
... ...
app/models/task.rb
... ... @@ -138,6 +138,10 @@ class Task < ActiveRecord::Base
138 138 def pending_for(target, conditions= nil)
139 139 self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }.merge(conditions || {}))
140 140 end
  141 +
  142 + def processed_for(target, conditions = nil)
  143 + self.find(:all, :conditions => { :target_id => target.id, :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }.merge(conditions || {}))
  144 + end
141 145  
142 146 # generates a random code string consisting of 36 characters in the ranges
143 147 # a-z and 0-9
... ...
test/unit/organization_test.rb
... ... @@ -80,4 +80,18 @@ class OrganizationTest < Test::Unit::TestCase
80 80 assert_nil org.find_pending_validation('lele')
81 81 end
82 82  
  83 + should 'be able to find already processed validations by target' do
  84 + org = Organization.new
  85 + empty = mock
  86 + CreateEnterprise.expects(:processed_for).with(org).returns(empty)
  87 + assert_same empty, org.processed_validations
  88 + end
  89 +
  90 + should 'be able to find an already processed validation by its code' do
  91 + org = Organization.new
  92 + empty = mock
  93 + CreateEnterprise.expects(:processed_for).with(org, {:code => 'lalalala'}).returns([empty])
  94 + assert_same empty, org.find_processed_validation('lalalala')
  95 + end
  96 +
83 97 end
... ...
test/unit/task_test.rb
... ... @@ -171,6 +171,31 @@ class TaskTest < Test::Unit::TestCase
171 171 assert_equal [], Task.pending_for(target, :id => -1)
172 172 end
173 173  
  174 + should 'be able to list processed tasks' do
  175 + target = sample_user
  176 +
  177 + task = Task.new
  178 + task.target = target
  179 + task.finish
  180 +
  181 + # this one shouldn't be listed as processed, since it was not
  182 + task2 = Task.new
  183 + task2.target = target
  184 + target.save!
  185 +
  186 + assert_equal [task], Task.processed_for(target)
  187 + end
  188 +
  189 + should 'be able to pass optional parameters for getting processed tasks' do
  190 + target = sample_user
  191 +
  192 + task = Task.new
  193 + task.target = target
  194 + task.finish
  195 +
  196 + assert_equal [], Task.processed_for(target, :id => -1)
  197 + end
  198 +
174 199 protected
175 200  
176 201 def sample_user
... ...