Commit 48ed402738a2224e019595989e4ac02562ea158a
1 parent
6aacd907
Exists in
master
and in
28 other branches
destroy AbuseComplaint when reported is destroyed
ActionItem2451 Including: migration and test.
Showing
3 changed files
with
26 additions
and
1 deletions
Show diff stats
app/models/profile.rb
@@ -211,7 +211,7 @@ class Profile < ActiveRecord::Base | @@ -211,7 +211,7 @@ class Profile < ActiveRecord::Base | ||
211 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' | 211 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' |
212 | has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category | 212 | has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category |
213 | 213 | ||
214 | - has_many :abuse_complaints, :foreign_key => 'requestor_id' | 214 | + has_many :abuse_complaints, :foreign_key => 'requestor_id', :dependent => :destroy |
215 | 215 | ||
216 | def top_level_categorization | 216 | def top_level_categorization |
217 | ret = {} | 217 | ret = {} |
db/migrate/20130429214630_destroy_inconsistent_abuse_complaints.rb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class DestroyInconsistentAbuseComplaints < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + AbuseComplaint.all.each do |ac| | ||
4 | + if ac.reported.nil? | ||
5 | + ac.destroy | ||
6 | + end | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + raise ActiveRecord::IrreversibleMigration | ||
12 | + end | ||
13 | +end |
test/unit/abuse_complaint_test.rb
@@ -35,4 +35,16 @@ class AbuseComplaintTest < ActiveSupport::TestCase | @@ -35,4 +35,16 @@ class AbuseComplaintTest < ActiveSupport::TestCase | ||
35 | t = AbuseComplaint.create | 35 | t = AbuseComplaint.create |
36 | assert_equal Task::Status::HIDDEN, t.status | 36 | assert_equal Task::Status::HIDDEN, t.status |
37 | end | 37 | end |
38 | + | ||
39 | + should 'be destroyed with reported' do | ||
40 | + reported = fast_create(Profile) | ||
41 | + reported_id = reported.id | ||
42 | + abuse_complaint = AbuseComplaint.create!(:reported => reported) | ||
43 | + | ||
44 | + assert AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint was not created!" | ||
45 | + | ||
46 | + reported.destroy | ||
47 | + | ||
48 | + assert !AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint still exist!" | ||
49 | + end | ||
38 | end | 50 | end |