diff --git a/app/models/person.rb b/app/models/person.rb index e7d7c3e..49f49d8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -81,6 +81,8 @@ roles] } memberships.where('role_assignments.role_id = ?', role.id) end + has_many :comments, :foreign_key => :author_id + has_many :friendships, :dependent => :destroy has_many :friends, :class_name => 'Person', :through => :friendships diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 72f865b..1813f1d 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1827,4 +1827,15 @@ class PersonTest < ActiveSupport::TestCase assert person.voted_against?(article) end + should 'access comments through profile' do + p1 = fast_create(Person) + p2 = fast_create(Person) + article = fast_create(Article) + c1 = fast_create(Comment, :source_id => article.id, :author_id => p1.id) + c2 = fast_create(Comment, :source_id => article.id, :author_id => p2.id) + c3 = fast_create(Comment, :source_id => article.id, :author_id => p1.id) + + assert_equivalent [c1,c3], p1.comments + end + end -- libgit2 0.21.2