From 07f1d9e1506db0d31dffbc9df9b6a12254d905cc Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 29 May 2015 15:20:37 -0300 Subject: [PATCH] api: tests for visible_for_person scope --- Rakefile | 2 +- app/models/article.rb | 1 - app/models/comment.rb | 1 - app/models/organization.rb | 2 +- test/unit/organization_test.rb | 21 +++++++++++++++++++++ test/unit/person_test.rb | 22 ++++++++++++++++++++++ 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 5d8df4a..d6717f0 100644 --- a/Rakefile +++ b/Rakefile @@ -15,7 +15,7 @@ Noosfero::Application.load_tasks Dir.glob(pattern).sort end.flatten.each do |taskfile| load taskfile -end +end # plugins' tasks plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + diff --git a/app/models/article.rb b/app/models/article.rb index 7d7c9ff..591477c 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -708,7 +708,6 @@ class Article < ActiveRecord::Base person ? person.id : nil end - #FIXME make this test def author_custom_image(size = :icon) author ? author.profile_custom_image(size) : nil end diff --git a/app/models/comment.rb b/app/models/comment.rb index 575e96f..a04dac8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -67,7 +67,6 @@ class Comment < ActiveRecord::Base author ? author.url : nil end - #FIXME make this test def author_custom_image(size = :icon) author ? author.profile_custom_image(size) : nil end diff --git a/app/models/organization.rb b/app/models/organization.rb index da67e14..32badcb 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -11,7 +11,7 @@ class Organization < Profile scope :visible_for_person, lambda { |person| joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'') .where( - ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR + ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true] ).uniq } diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index 5aab807..fe1b8ca 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -477,4 +477,25 @@ class OrganizationTest < ActiveSupport::TestCase assert !c.is_admin?(moderator) end + should 'fetch organizations there are visible for a user' do + person = create_user('some-person').person + o1 = fast_create(Organization, :public_profile => true , :visible => true ) + o1.add_member(person) + o2 = fast_create(Organization, :public_profile => true , :visible => true ) + o3 = fast_create(Organization, :public_profile => false, :visible => true ) + o4 = fast_create(Organization, :public_profile => false, :visible => true) + o4.add_member(person) + o5 = fast_create(Organization, :public_profile => true , :visible => false) + o6 = fast_create(Organization, :public_profile => false, :visible => false) + + organizations = Organization.visible_for_person(person) + + assert_includes organizations, o1 + assert_includes organizations, o2 + assert_not_includes organizations, o3 + assert_includes organizations, o4 + assert_not_includes organizations, o5 + assert_not_includes organizations, o6 + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index dcc57d3..e854f03 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1661,4 +1661,26 @@ class PersonTest < ActiveSupport::TestCase assert person.can_post_content?(profile, parent) end + should 'fetch people there are visible for a user' do + person = create_user('some-person').person + p1 = fast_create(Person, :public_profile => true , :visible => true ) + p1.add_friend(person) + p2 = fast_create(Person, :public_profile => true , :visible => true ) + p3 = fast_create(Person, :public_profile => false, :visible => true ) + p4 = fast_create(Person, :public_profile => false, :visible => true) + p4.add_friend(person) + person.add_friend(p4) + p5 = fast_create(Person, :public_profile => true , :visible => false) + p6 = fast_create(Person, :public_profile => false, :visible => false) + + people = Person.visible_for_person(person) + + assert_includes people, p1 + assert_includes people, p2 + assert_not_includes people, p3 + assert_includes people, p4 + assert_not_includes people, p5 + assert_not_includes people, p6 + end + end -- libgit2 0.21.2