Commit 07f1d9e1506db0d31dffbc9df9b6a12254d905cc
1 parent
a689bd92
Exists in
master
and in
29 other branches
api: tests for visible_for_person scope
Showing
6 changed files
with
45 additions
and
4 deletions
Show diff stats
Rakefile
app/models/article.rb
app/models/comment.rb
app/models/organization.rb
| ... | ... | @@ -11,7 +11,7 @@ class Organization < Profile |
| 11 | 11 | scope :visible_for_person, lambda { |person| |
| 12 | 12 | joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'') |
| 13 | 13 | .where( |
| 14 | - ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | |
| 14 | + ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | |
| 15 | 15 | (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true] |
| 16 | 16 | ).uniq |
| 17 | 17 | } | ... | ... |
test/unit/organization_test.rb
| ... | ... | @@ -477,4 +477,25 @@ class OrganizationTest < ActiveSupport::TestCase |
| 477 | 477 | assert !c.is_admin?(moderator) |
| 478 | 478 | end |
| 479 | 479 | |
| 480 | + should 'fetch organizations there are visible for a user' do | |
| 481 | + person = create_user('some-person').person | |
| 482 | + o1 = fast_create(Organization, :public_profile => true , :visible => true ) | |
| 483 | + o1.add_member(person) | |
| 484 | + o2 = fast_create(Organization, :public_profile => true , :visible => true ) | |
| 485 | + o3 = fast_create(Organization, :public_profile => false, :visible => true ) | |
| 486 | + o4 = fast_create(Organization, :public_profile => false, :visible => true) | |
| 487 | + o4.add_member(person) | |
| 488 | + o5 = fast_create(Organization, :public_profile => true , :visible => false) | |
| 489 | + o6 = fast_create(Organization, :public_profile => false, :visible => false) | |
| 490 | + | |
| 491 | + organizations = Organization.visible_for_person(person) | |
| 492 | + | |
| 493 | + assert_includes organizations, o1 | |
| 494 | + assert_includes organizations, o2 | |
| 495 | + assert_not_includes organizations, o3 | |
| 496 | + assert_includes organizations, o4 | |
| 497 | + assert_not_includes organizations, o5 | |
| 498 | + assert_not_includes organizations, o6 | |
| 499 | + end | |
| 500 | + | |
| 480 | 501 | end | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -1661,4 +1661,26 @@ class PersonTest < ActiveSupport::TestCase |
| 1661 | 1661 | assert person.can_post_content?(profile, parent) |
| 1662 | 1662 | end |
| 1663 | 1663 | |
| 1664 | + should 'fetch people there are visible for a user' do | |
| 1665 | + person = create_user('some-person').person | |
| 1666 | + p1 = fast_create(Person, :public_profile => true , :visible => true ) | |
| 1667 | + p1.add_friend(person) | |
| 1668 | + p2 = fast_create(Person, :public_profile => true , :visible => true ) | |
| 1669 | + p3 = fast_create(Person, :public_profile => false, :visible => true ) | |
| 1670 | + p4 = fast_create(Person, :public_profile => false, :visible => true) | |
| 1671 | + p4.add_friend(person) | |
| 1672 | + person.add_friend(p4) | |
| 1673 | + p5 = fast_create(Person, :public_profile => true , :visible => false) | |
| 1674 | + p6 = fast_create(Person, :public_profile => false, :visible => false) | |
| 1675 | + | |
| 1676 | + people = Person.visible_for_person(person) | |
| 1677 | + | |
| 1678 | + assert_includes people, p1 | |
| 1679 | + assert_includes people, p2 | |
| 1680 | + assert_not_includes people, p3 | |
| 1681 | + assert_includes people, p4 | |
| 1682 | + assert_not_includes people, p5 | |
| 1683 | + assert_not_includes people, p6 | |
| 1684 | + end | |
| 1685 | + | |
| 1664 | 1686 | end | ... | ... |