communities_test.rb
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/test_helper'
class CommunitiesTest < ActiveSupport::TestCase
def setup
login_api
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 'list all communities' do
community1 = fast_create(Community)
community2 = fast_create(Community)
get "/api/v1/communities/all?#{params.to_query}"
json = JSON.parse(last_response.body)
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)
get "/api/v1/communities/all?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal [community1.id], json['communities'].map {|c| c['id']}
end
should 'not get invisible community' do
community = fast_create(Community, :visible => false)
get "/api/v1/communities/#{community.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert json['community'].blank?
end
end