Commit ae133d6f1714103881fee45272c141d699d3f1c7
1 parent
b087600f
Exists in
master
and in
20 other branches
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,6 +81,8 @@ roles] } | ||
81 | memberships.where('role_assignments.role_id = ?', role.id) | 81 | memberships.where('role_assignments.role_id = ?', role.id) |
82 | end | 82 | end |
83 | 83 | ||
84 | + has_many :comments, :foreign_key => :author_id | ||
85 | + | ||
84 | has_many :friendships, :dependent => :destroy | 86 | has_many :friendships, :dependent => :destroy |
85 | has_many :friends, :class_name => 'Person', :through => :friendships | 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,4 +1827,15 @@ class PersonTest < ActiveSupport::TestCase | ||
1827 | assert person.voted_against?(article) | 1827 | assert person.voted_against?(article) |
1828 | end | 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 | end | 1841 | end |