diff --git a/app/models/profile.rb b/app/models/profile.rb index 48ed800..09bbec1 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -211,7 +211,7 @@ class Profile < ActiveRecord::Base has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category - has_many :abuse_complaints, :foreign_key => 'requestor_id' + has_many :abuse_complaints, :foreign_key => 'requestor_id', :dependent => :destroy def top_level_categorization ret = {} diff --git a/db/migrate/20130429214630_destroy_inconsistent_abuse_complaints.rb b/db/migrate/20130429214630_destroy_inconsistent_abuse_complaints.rb new file mode 100644 index 0000000..04d47e3 --- /dev/null +++ b/db/migrate/20130429214630_destroy_inconsistent_abuse_complaints.rb @@ -0,0 +1,13 @@ +class DestroyInconsistentAbuseComplaints < ActiveRecord::Migration + def self.up + AbuseComplaint.all.each do |ac| + if ac.reported.nil? + ac.destroy + end + end + end + + def self.down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/test/unit/abuse_complaint_test.rb b/test/unit/abuse_complaint_test.rb index ceebed6..dec1353 100644 --- a/test/unit/abuse_complaint_test.rb +++ b/test/unit/abuse_complaint_test.rb @@ -35,4 +35,16 @@ class AbuseComplaintTest < ActiveSupport::TestCase t = AbuseComplaint.create assert_equal Task::Status::HIDDEN, t.status end + + should 'be destroyed with reported' do + reported = fast_create(Profile) + reported_id = reported.id + abuse_complaint = AbuseComplaint.create!(:reported => reported) + + assert AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint was not created!" + + reported.destroy + + assert !AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint still exist!" + end end -- libgit2 0.21.2