Commit 07f1d9e1506db0d31dffbc9df9b6a12254d905cc

Authored by Rodrigo Souto
1 parent a689bd92

api: tests for visible_for_person scope

@@ -15,7 +15,7 @@ Noosfero::Application.load_tasks @@ -15,7 +15,7 @@ Noosfero::Application.load_tasks
15 Dir.glob(pattern).sort 15 Dir.glob(pattern).sort
16 end.flatten.each do |taskfile| 16 end.flatten.each do |taskfile|
17 load taskfile 17 load taskfile
18 -end 18 +end
19 19
20 # plugins' tasks 20 # plugins' tasks
21 plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + 21 plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort +
app/models/article.rb
@@ -708,7 +708,6 @@ class Article < ActiveRecord::Base @@ -708,7 +708,6 @@ class Article < ActiveRecord::Base
708 person ? person.id : nil 708 person ? person.id : nil
709 end 709 end
710 710
711 - #FIXME make this test  
712 def author_custom_image(size = :icon) 711 def author_custom_image(size = :icon)
713 author ? author.profile_custom_image(size) : nil 712 author ? author.profile_custom_image(size) : nil
714 end 713 end
app/models/comment.rb
@@ -67,7 +67,6 @@ class Comment < ActiveRecord::Base @@ -67,7 +67,6 @@ class Comment < ActiveRecord::Base
67 author ? author.url : nil 67 author ? author.url : nil
68 end 68 end
69 69
70 - #FIXME make this test  
71 def author_custom_image(size = :icon) 70 def author_custom_image(size = :icon)
72 author ? author.profile_custom_image(size) : nil 71 author ? author.profile_custom_image(size) : nil
73 end 72 end
app/models/organization.rb
@@ -11,7 +11,7 @@ class Organization < Profile @@ -11,7 +11,7 @@ class Organization < Profile
11 scope :visible_for_person, lambda { |person| 11 scope :visible_for_person, lambda { |person|
12 joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'') 12 joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'')
13 .where( 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 (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true] 15 (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true]
16 ).uniq 16 ).uniq
17 } 17 }
test/unit/organization_test.rb
@@ -477,4 +477,25 @@ class OrganizationTest < ActiveSupport::TestCase @@ -477,4 +477,25 @@ class OrganizationTest < ActiveSupport::TestCase
477 assert !c.is_admin?(moderator) 477 assert !c.is_admin?(moderator)
478 end 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 end 501 end
test/unit/person_test.rb
@@ -1661,4 +1661,26 @@ class PersonTest < ActiveSupport::TestCase @@ -1661,4 +1661,26 @@ class PersonTest < ActiveSupport::TestCase
1661 assert person.can_post_content?(profile, parent) 1661 assert person.can_post_content?(profile, parent)
1662 end 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 end 1686 end