Commit 36c2effa1b1cb70267ab53906f97e5cbcc102383
1 parent
8afe63e2
Exists in
master
and in
29 other branches
ActionItem732: destroy tasks when requestor or target is destroyed
Showing
5 changed files
with
29 additions
and
1 deletions
Show diff stats
app/models/person.rb
... | ... | @@ -6,6 +6,8 @@ class Person < Profile |
6 | 6 | has_many :friendships |
7 | 7 | has_many :friends, :class_name => 'Person', :through => :friendships |
8 | 8 | |
9 | + has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy | |
10 | + | |
9 | 11 | def suggested_friend_groups |
10 | 12 | (friend_groups + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq |
11 | 13 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -98,7 +98,7 @@ class Profile < ActiveRecord::Base |
98 | 98 | has_many :consumptions |
99 | 99 | has_many :consumed_product_categories, :through => :consumptions, :source => :product_category |
100 | 100 | |
101 | - has_many :tasks, :foreign_key => :target_id | |
101 | + has_many :tasks, :foreign_key => :target_id, :dependent => :destroy | |
102 | 102 | |
103 | 103 | has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] |
104 | 104 | has_many :categories, :through => :profile_categorizations | ... | ... |
test/unit/person_test.rb
... | ... | @@ -306,4 +306,13 @@ class PersonTest < Test::Unit::TestCase |
306 | 306 | assert_kind_of Person, p.template |
307 | 307 | end |
308 | 308 | |
309 | + should 'destroy all task that it requested when destroyed' do | |
310 | + p = create_user('test_profile').person | |
311 | + | |
312 | + assert_no_difference Task, :count do | |
313 | + Task.create(:requestor => p) | |
314 | + p.destroy | |
315 | + end | |
316 | + end | |
317 | + | |
309 | 318 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -929,6 +929,15 @@ class ProfileTest < Test::Unit::TestCase |
929 | 929 | assert_equal 6, p.boxes_limit |
930 | 930 | end |
931 | 931 | |
932 | + should 'destroy tasks requested to it when destroyed' do | |
933 | + p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') | |
934 | + | |
935 | + assert_no_difference Task, :count do | |
936 | + Task.create(:target => p) | |
937 | + p.destroy | |
938 | + end | |
939 | + end | |
940 | + | |
932 | 941 | private |
933 | 942 | |
934 | 943 | def assert_invalid_identifier(id) | ... | ... |
test/unit/task_test.rb
... | ... | @@ -182,6 +182,14 @@ class TaskTest < Test::Unit::TestCase |
182 | 182 | t = Task.new |
183 | 183 | assert_equal :perform_task, t.permission |
184 | 184 | end |
185 | + | |
186 | + should 'be destroyed when requestor destroyed' do | |
187 | + user = create_user('test_user').person | |
188 | + assert_no_difference Task, :count do | |
189 | + Task.create(:requestor => user) | |
190 | + user.destroy | |
191 | + end | |
192 | + end | |
185 | 193 | |
186 | 194 | protected |
187 | 195 | ... | ... |