Commit ae133d6f1714103881fee45272c141d699d3f1c7

Authored by Leandro Santos
1 parent b087600f

access comments through profile author

Showing 2 changed files with 13 additions and 0 deletions   Show diff stats
app/models/person.rb
... ... @@ -81,6 +81,8 @@ roles] }
81 81 memberships.where('role_assignments.role_id = ?', role.id)
82 82 end
83 83  
  84 + has_many :comments, :foreign_key => :author_id
  85 +
84 86 has_many :friendships, :dependent => :destroy
85 87 has_many :friends, :class_name => 'Person', :through => :friendships
86 88  
... ...
test/unit/person_test.rb
... ... @@ -1827,4 +1827,15 @@ class PersonTest < ActiveSupport::TestCase
1827 1827 assert person.voted_against?(article)
1828 1828 end
1829 1829  
  1830 + should 'access comments through profile' do
  1831 + p1 = fast_create(Person)
  1832 + p2 = fast_create(Person)
  1833 + article = fast_create(Article)
  1834 + c1 = fast_create(Comment, :source_id => article.id, :author_id => p1.id)
  1835 + c2 = fast_create(Comment, :source_id => article.id, :author_id => p2.id)
  1836 + c3 = fast_create(Comment, :source_id => article.id, :author_id => p1.id)
  1837 +
  1838 + assert_equivalent [c1,c3], p1.comments
  1839 + end
  1840 +
1830 1841 end
... ...