Commit f97ba599e502b908350994be00b5fd672e174bcb
1 parent
ae9a021d
Exists in
master
and in
29 other branches
ActionItem16: adding optional conditions to pending_for
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@858 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
12 additions
and
2 deletions
Show diff stats
app/models/task.rb
@@ -135,8 +135,8 @@ class Task < ActiveRecord::Base | @@ -135,8 +135,8 @@ class Task < ActiveRecord::Base | ||
135 | 135 | ||
136 | class << self | 136 | class << self |
137 | 137 | ||
138 | - def pending_for(target) | ||
139 | - self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }) | 138 | + def pending_for(target, conditions= nil) |
139 | + self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }.merge(conditions || {})) | ||
140 | end | 140 | end |
141 | 141 | ||
142 | # generates a random code string consisting of 36 characters in the ranges | 142 | # generates a random code string consisting of 36 characters in the ranges |
test/unit/task_test.rb
@@ -161,6 +161,16 @@ class TaskTest < Test::Unit::TestCase | @@ -161,6 +161,16 @@ class TaskTest < Test::Unit::TestCase | ||
161 | assert_equal [task], Task.pending_for(target) | 161 | assert_equal [task], Task.pending_for(target) |
162 | end | 162 | end |
163 | 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) | ||
172 | + end | ||
173 | + | ||
164 | protected | 174 | protected |
165 | 175 | ||
166 | def sample_user | 176 | def sample_user |