diff --git a/app/models/person.rb b/app/models/person.rb index 24f9a10..0df0e32 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -67,6 +67,9 @@ class Person < Profile :order => 'total DESC', :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] + named_scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' + 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.*" + after_destroy do |person| Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } end @@ -440,6 +443,10 @@ class Person < Profile abuse_report.save! end + def abuser? + AbuseComplaint.finished.where(:requestor_id => self).count > 0 + end + def control_panel_settings_button {:title => _('Edit Profile'), :icon => 'edit-profile'} end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 04d4ef6..0bb7d4b 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1284,4 +1284,36 @@ class PersonTest < ActiveSupport::TestCase p.stubs(:fields_privacy).returns({ 'sex' => 'public', 'birth_date' => 'private' }) assert_equal ['sex'], p.public_fields end + + should 'define abuser?' do + abuser = create_user('abuser').person + AbuseComplaint.create!(:reported => abuser).finish + person = create_user('person').person + + assert abuser.abuser? + assert !person.abuser? + end + + should 'be able to retrieve abusers and non abusers' do + abuser1 = create_user('abuser1').person + AbuseComplaint.create!(:reported => abuser1).finish + abuser2 = create_user('abuser2').person + AbuseComplaint.create!(:reported => abuser2).finish + person = create_user('person').person + + abusers = Person.abusers + + assert_equal ActiveRecord::NamedScope::Scope, abusers.class + assert_includes abusers, abuser1 + assert_includes abusers, abuser2 + assert_not_includes abusers, person + + non_abusers = Person.non_abusers + + assert_equal ActiveRecord::NamedScope::Scope, non_abusers.class + assert_not_includes non_abusers, abuser1 + assert_not_includes non_abusers, abuser2 + assert_includes non_abusers, person + end + end -- libgit2 0.21.2