Commit f77b5589aad63783af9cf3c3aae3333527f6f35b
1 parent
2e816a38
Exists in
master
and in
28 other branches
ActionItem36: listing tasks in general, plus pending and finished ones
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1482 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
30 additions
and
0 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -66,6 +66,8 @@ class Profile < ActiveRecord::Base |
66 | 66 | has_many :consumptions |
67 | 67 | has_many :consumed_product_categories, :through => :consumptions, :source => :product_category |
68 | 68 | |
69 | + has_many :tasks, :foreign_key => :target_id | |
70 | + | |
69 | 71 | def top_level_articles(reload = false) |
70 | 72 | if reload |
71 | 73 | @top_level_articles = nil | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -337,6 +337,34 @@ class ProfileTest < Test::Unit::TestCase |
337 | 337 | assert c.members.include?(p), "Profile should add the new member" |
338 | 338 | end |
339 | 339 | |
340 | + should 'have tasks' do | |
341 | + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
342 | + t1 = c.tasks.build | |
343 | + t1.save! | |
344 | + | |
345 | + t2 = c.tasks.build | |
346 | + t2.save! | |
347 | + | |
348 | + assert_equal [t1, t2]. c.tasks | |
349 | + end | |
350 | + | |
351 | + should 'have pending tasks' do | |
352 | + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
353 | + t1 = c.tasks.build; t1.save! | |
354 | + t2 = c.tasks.build; t2.save!; t2.finish | |
355 | + t3 = c.tasks.build; t3.save! | |
356 | + | |
357 | + assert_equal [t1, t3], c.tasks.pending | |
358 | + end | |
359 | + | |
360 | + should 'have finished tasks' do | |
361 | + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
362 | + t1 = c.tasks.build; t1.save! | |
363 | + t2 = c.tasks.build; t2.save!; t2.finish | |
364 | + t3 = c.tasks.build; t3.save!; t3.finish | |
365 | + | |
366 | + assert_equal [t2, t3], c.tasks.finished | |
367 | + end | |
340 | 368 | |
341 | 369 | private |
342 | 370 | ... | ... |