Commit ffc26a001c5ae16a68c1d51bf1097244790040f2
1 parent
61e8866b
Exists in
master
and in
29 other branches
ActionItem36: changing the interface for requesting pending and finished tasks
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1479 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
18 additions
and
45 deletions
Show diff stats
app/models/task.rb
... | ... | @@ -149,12 +149,12 @@ class Task < ActiveRecord::Base |
149 | 149 | |
150 | 150 | class << self |
151 | 151 | |
152 | - def pending_for(target, conditions= nil) | |
153 | - self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }.merge(conditions || {})) | |
152 | + def pending | |
153 | + self.find(:all, :conditions => { :status => Task::Status::ACTIVE }) | |
154 | 154 | end |
155 | 155 | |
156 | - def processed_for(target, conditions = nil) | |
157 | - self.find(:all, :conditions => { :target_id => target.id, :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }.merge(conditions || {})) | |
156 | + def finished | |
157 | + self.find(:all, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED]}) | |
158 | 158 | end |
159 | 159 | |
160 | 160 | # generates a random code string consisting of 36 characters in the ranges | ... | ... |
test/unit/task_test.rb
... | ... | @@ -149,51 +149,24 @@ class TaskTest < Test::Unit::TestCase |
149 | 149 | task.save! |
150 | 150 | end |
151 | 151 | |
152 | - should 'be able to list pending tasks for a given target' do | |
153 | - target = sample_user | |
152 | + should 'be able to list pending tasks' do | |
153 | + Task.delete_all | |
154 | + t1 = Task.create! | |
155 | + t2 = Task.create! | |
156 | + t2.finish | |
157 | + t3 = Task.create! | |
154 | 158 | |
155 | - assert_equal [], Task.pending_for(target) | |
156 | - | |
157 | - task = Task.new | |
158 | - task.target = target | |
159 | - task.save! | |
160 | - | |
161 | - assert_equal [task], Task.pending_for(target) | |
162 | - end | |
163 | - | |
164 | - should 'be able to pass extra conditions for getting pending tasks' do | |
165 | - target = sample_user | |
166 | - | |
167 | - task = Task.new | |
168 | - task.target = target | |
169 | - task.save! | |
170 | - | |
171 | - assert_equal [], Task.pending_for(target, :id => -1) | |
159 | + assert_equal [t1,t3], Task.pending | |
172 | 160 | end |
173 | 161 | |
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 | |
162 | + should 'be able to list finished tasks' do | |
163 | + Task.delete_all | |
164 | + t1 = Task.create! | |
165 | + t2 = Task.create! | |
166 | + t2.finish | |
167 | + t3 = Task.create! | |
195 | 168 | |
196 | - assert_equal [], Task.processed_for(target, :id => -1) | |
169 | + assert_equal [t2], Task.finished | |
197 | 170 | end |
198 | 171 | |
199 | 172 | protected | ... | ... |