Commit 69b22fc818d74dc8270a35e13fd0d02b09e1aaef

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 4d520921

Defining abuser

Showing 2 changed files with 39 additions and 0 deletions   Show diff stats
app/models/person.rb
... ... @@ -67,6 +67,9 @@ class Person < Profile
67 67 :order => 'total DESC',
68 68 :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago]
69 69  
  70 + named_scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*'
  71 + named_scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*"
  72 +
70 73 after_destroy do |person|
71 74 Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy }
72 75 end
... ... @@ -440,6 +443,10 @@ class Person < Profile
440 443 abuse_report.save!
441 444 end
442 445  
  446 + def abuser?
  447 + AbuseComplaint.finished.where(:requestor_id => self).count > 0
  448 + end
  449 +
443 450 def control_panel_settings_button
444 451 {:title => _('Edit Profile'), :icon => 'edit-profile'}
445 452 end
... ...
test/unit/person_test.rb
... ... @@ -1284,4 +1284,36 @@ class PersonTest < ActiveSupport::TestCase
1284 1284 p.stubs(:fields_privacy).returns({ 'sex' => 'public', 'birth_date' => 'private' })
1285 1285 assert_equal ['sex'], p.public_fields
1286 1286 end
  1287 +
  1288 + should 'define abuser?' do
  1289 + abuser = create_user('abuser').person
  1290 + AbuseComplaint.create!(:reported => abuser).finish
  1291 + person = create_user('person').person
  1292 +
  1293 + assert abuser.abuser?
  1294 + assert !person.abuser?
  1295 + end
  1296 +
  1297 + should 'be able to retrieve abusers and non abusers' do
  1298 + abuser1 = create_user('abuser1').person
  1299 + AbuseComplaint.create!(:reported => abuser1).finish
  1300 + abuser2 = create_user('abuser2').person
  1301 + AbuseComplaint.create!(:reported => abuser2).finish
  1302 + person = create_user('person').person
  1303 +
  1304 + abusers = Person.abusers
  1305 +
  1306 + assert_equal ActiveRecord::NamedScope::Scope, abusers.class
  1307 + assert_includes abusers, abuser1
  1308 + assert_includes abusers, abuser2
  1309 + assert_not_includes abusers, person
  1310 +
  1311 + non_abusers = Person.non_abusers
  1312 +
  1313 + assert_equal ActiveRecord::NamedScope::Scope, non_abusers.class
  1314 + assert_not_includes non_abusers, abuser1
  1315 + assert_not_includes non_abusers, abuser2
  1316 + assert_includes non_abusers, person
  1317 + end
  1318 +
1287 1319 end
... ...