Commit 44dd0a25cd5ac6c7a669683e9cdd25a4d06104f0

Authored by Leandro Santos
Committed by Rodrigo Souto
1 parent bf821d19

adding functional testes for communities endpoint

app/models/profile.rb
... ... @@ -149,7 +149,7 @@ class Profile < ActiveRecord::Base
149 149 joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'')
150 150 .where(
151 151 ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR
152   - (profiles.public_profile = ?) )', Profile.name, person.id, true]
  152 + (profiles.public_profile = ?)) AND (profiles.visible = ?)', Profile.name, person.id, true, true]
153 153 ).uniq
154 154 }
155 155  
... ...
test/unit/api/communities_test.rb
... ... @@ -14,14 +14,6 @@ class CommunitiesTest < ActiveSupport::TestCase
14 14 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']}
15 15 end
16 16  
17   - should 'get community' do
18   - community = fast_create(Community)
19   -
20   - get "/api/v1/communities/#{community.id}?#{params.to_query}"
21   - json = JSON.parse(last_response.body)
22   - assert_equal community.id, json['community']['id']
23   - end
24   -
25 17 should 'not list invisible communities' do
26 18 community1 = fast_create(Community)
27 19 fast_create(Community, :visible => false)
... ... @@ -50,6 +42,14 @@ class CommunitiesTest < ActiveSupport::TestCase
50 42 assert_equivalent [c1.id, c2.id], json['communities'].map {|c| c['id']}
51 43 end
52 44  
  45 + should 'get community' do
  46 + community = fast_create(Community)
  47 +
  48 + get "/api/v1/communities/#{community.id}?#{params.to_query}"
  49 + json = JSON.parse(last_response.body)
  50 + assert_equal community.id, json['community']['id']
  51 + end
  52 +
53 53 should 'not get invisible community' do
54 54 community = fast_create(Community, :visible => false)
55 55  
... ... @@ -58,13 +58,43 @@ class CommunitiesTest < ActiveSupport::TestCase
58 58 assert json['community'].blank?
59 59 end
60 60  
61   -# should 'list user communities' do
62   -# community1 = fast_create(Community)
63   -# fast_create(Community)
64   -# community1.add_member(user.person)
65   -#
66   -# get "/api/v1/communities?#{params.to_query}"
67   -# json = JSON.parse(last_response.body)
68   -# assert_equivalent [community1.id], json['communities'].map {|c| c['id']}
69   -# end
  61 + should 'not get private communities without permission' do
  62 + community = fast_create(Community)
  63 + fast_create(Community, :public_profile => false)
  64 +
  65 + get "/api/v1/communities/#{community.id}?#{params.to_query}"
  66 + json = JSON.parse(last_response.body)
  67 + assert_equal community.id, json['community']['id']
  68 + end
  69 +
  70 + should 'get private community for members' do
  71 + community = fast_create(Community, :public_profile => false)
  72 + community.add_member(person)
  73 +
  74 + get "/api/v1/communities/#{community.id}?#{params.to_query}"
  75 + json = JSON.parse(last_response.body)
  76 + assert_equal community.id, json['community']['id']
  77 + end
  78 +
  79 + should 'list person communities' do
  80 + community = fast_create(Community)
  81 + fast_create(Community)
  82 + community.add_member(person)
  83 +
  84 + get "/api/v1/people/#{person.id}/communities?#{params.to_query}"
  85 + json = JSON.parse(last_response.body)
  86 + assert_equivalent [community.id], json['communities'].map {|c| c['id']}
  87 + end
  88 +
  89 + should 'not list person communities invisible' do
  90 + c1 = fast_create(Community)
  91 + c2 = fast_create(Community, :visible => false)
  92 + c1.add_member(person)
  93 + c2.add_member(person)
  94 +
  95 + get "/api/v1/people/#{person.id}/communities?#{params.to_query}"
  96 + json = JSON.parse(last_response.body)
  97 + assert_equivalent [c1.id], json['communities'].map {|c| c['id']}
  98 + end
  99 +
70 100 end
... ...