From f77b5589aad63783af9cf3c3aae3333527f6f35b Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 22 Feb 2008 23:05:47 +0000 Subject: [PATCH] ActionItem36: listing tasks in general, plus pending and finished ones --- app/models/profile.rb | 2 ++ test/unit/profile_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 96656d8..2049e1d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -66,6 +66,8 @@ class Profile < ActiveRecord::Base has_many :consumptions has_many :consumed_product_categories, :through => :consumptions, :source => :product_category + has_many :tasks, :foreign_key => :target_id + def top_level_articles(reload = false) if reload @top_level_articles = nil diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index bf8ea7f..ef5e470 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -337,6 +337,34 @@ class ProfileTest < Test::Unit::TestCase assert c.members.include?(p), "Profile should add the new member" end + should 'have tasks' do + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + t1 = c.tasks.build + t1.save! + + t2 = c.tasks.build + t2.save! + + assert_equal [t1, t2]. c.tasks + end + + should 'have pending tasks' do + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + t1 = c.tasks.build; t1.save! + t2 = c.tasks.build; t2.save!; t2.finish + t3 = c.tasks.build; t3.save! + + assert_equal [t1, t3], c.tasks.pending + end + + should 'have finished tasks' do + c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + t1 = c.tasks.build; t1.save! + t2 = c.tasks.build; t2.save!; t2.finish + t3 = c.tasks.build; t3.save!; t3.finish + + assert_equal [t2, t3], c.tasks.finished + end private -- libgit2 0.21.2