From 44dd0a25cd5ac6c7a669683e9cdd25a4d06104f0 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 23 Mar 2015 23:13:16 -0300 Subject: [PATCH] adding functional testes for communities endpoint --- app/models/profile.rb | 2 +- test/unit/api/communities_test.rb | 64 +++++++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 3efc1f7..6d07ae6 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -149,7 +149,7 @@ class Profile < ActiveRecord::Base 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 - (profiles.public_profile = ?) )', Profile.name, person.id, true] + (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true] ).uniq } diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index bdfa5e9..9df220c 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -14,14 +14,6 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end - should 'get community' do - community = fast_create(Community) - - get "/api/v1/communities/#{community.id}?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equal community.id, json['community']['id'] - end - should 'not list invisible communities' do community1 = fast_create(Community) fast_create(Community, :visible => false) @@ -50,6 +42,14 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [c1.id, c2.id], json['communities'].map {|c| c['id']} end + should 'get community' do + community = fast_create(Community) + + get "/api/v1/communities/#{community.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal community.id, json['community']['id'] + end + should 'not get invisible community' do community = fast_create(Community, :visible => false) @@ -58,13 +58,43 @@ class CommunitiesTest < ActiveSupport::TestCase assert json['community'].blank? end -# should 'list user communities' do -# community1 = fast_create(Community) -# fast_create(Community) -# community1.add_member(user.person) -# -# get "/api/v1/communities?#{params.to_query}" -# json = JSON.parse(last_response.body) -# assert_equivalent [community1.id], json['communities'].map {|c| c['id']} -# end + should 'not get private communities without permission' do + community = fast_create(Community) + fast_create(Community, :public_profile => false) + + get "/api/v1/communities/#{community.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal community.id, json['community']['id'] + end + + should 'get private community for members' do + community = fast_create(Community, :public_profile => false) + community.add_member(person) + + get "/api/v1/communities/#{community.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal community.id, json['community']['id'] + end + + should 'list person communities' do + community = fast_create(Community) + fast_create(Community) + community.add_member(person) + + get "/api/v1/people/#{person.id}/communities?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equivalent [community.id], json['communities'].map {|c| c['id']} + end + + should 'not list person communities invisible' do + c1 = fast_create(Community) + c2 = fast_create(Community, :visible => false) + c1.add_member(person) + c2.add_member(person) + + get "/api/v1/people/#{person.id}/communities?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equivalent [c1.id], json['communities'].map {|c| c['id']} + end + end -- libgit2 0.21.2