blocks_test.rb
2.37 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
54
55
56
57
58
59
60
61
62
63
64
65
require_relative 'test_helper'
class BlocksTest < ActiveSupport::TestCase
def setup
create_and_activate_user
login_api
@environment = Environment.default
@profile = fast_create(Profile)
end
attr_accessor :environment, :profile
should 'get an environment block' do
box = fast_create(Box, :owner_id => environment.id, :owner_type => Environment.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal block.id, json["block"]["id"]
end
should 'get a profile block' do
box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal block.id, json["block"]["id"]
end
should 'get a profile block for a not logged in user' do
logout_api
box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal block.id, json["block"]["id"]
end
should 'not get a profile block for a not logged in user' do
logout_api
profile = fast_create(Profile, public_profile: false)
box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
assert_equal 403, last_response.status
end
should 'not get a profile block for an user without permission' do
profile = fast_create(Profile, public_profile: false)
box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
assert_equal 403, last_response.status
end
should 'get a block for an user with permission in a private profile' do
profile = fast_create(Profile, public_profile: false)
profile.add_admin(person)
box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name)
block = fast_create(Block, box_id: box.id)
get "/api/v1/blocks/#{block.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal block.id, json["block"]["id"]
end
end