Commit f126e4411cf9303d86632bb7e74fac17dd7d21d6
1 parent
2b065b7d
Exists in
master
and in
28 other branches
ActionItem16: adding pending_for to list pending actions for a given profile
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@839 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
app/models/task.rb
@@ -134,6 +134,10 @@ class Task < ActiveRecord::Base | @@ -134,6 +134,10 @@ class Task < ActiveRecord::Base | ||
134 | 134 | ||
135 | class << self | 135 | class << self |
136 | 136 | ||
137 | + def pending_for(target) | ||
138 | + self.find(:all, :conditions => { :target_id => target.id, :status => Task::Status::ACTIVE }) | ||
139 | + end | ||
140 | + | ||
137 | # generates a random code string consisting of 36 characters in the ranges | 141 | # generates a random code string consisting of 36 characters in the ranges |
138 | # a-z and 0-9 | 142 | # a-z and 0-9 |
139 | def generate_code | 143 | def generate_code |
test/unit/task_test.rb
@@ -149,6 +149,18 @@ class TaskTest < Test::Unit::TestCase | @@ -149,6 +149,18 @@ class TaskTest < Test::Unit::TestCase | ||
149 | task.save! | 149 | task.save! |
150 | end | 150 | end |
151 | 151 | ||
152 | + should 'be able to list pending tasks for a given target' do | ||
153 | + target = sample_user | ||
154 | + | ||
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 | + | ||
152 | protected | 164 | protected |
153 | 165 | ||
154 | def sample_user | 166 | def sample_user |