-
Notifications
You must be signed in to change notification settings - Fork 539
Expand file tree
/
Copy pathbook_authorization_test.rb
More file actions
38 lines (31 loc) · 1.16 KB
/
book_authorization_test.rb
File metadata and controls
38 lines (31 loc) · 1.16 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
require File.expand_path('../../test_helper', __FILE__)
class BookAuthorizationTest < ActionDispatch::IntegrationTest
def setup
DatabaseCleaner.start
JSONAPI.configuration.json_key_format = :underscored_key
JSONAPI.configuration.route_format = :underscored_route
Api::V2::BookResource.paginator :offset
end
def test_restricted_records_primary
Api::V2::BookResource.paginator :none
# Not a book admin
$test_user = Person.find(1001)
assert_cacheable_jsonapi_get '/api/v2/books?filter[title]=Book%206'
assert_equal 12, json_response['data'].size
# book_admin
$test_user = Person.find(1005)
assert_cacheable_jsonapi_get '/api/v2/books?filter[title]=Book%206'
assert_equal 111, json_response['data'].size
end
def test_restricted_records_related
Api::V2::BookResource.paginator :none
# Not a book admin
$test_user = Person.find(1001)
assert_cacheable_jsonapi_get '/api/v2/authors/1002/books'
assert_equal 1, json_response['data'].size
# book_admin
$test_user = Person.find(1005)
assert_cacheable_jsonapi_get '/api/v2/authors/1002/books'
assert_equal 2, json_response['data'].size
end
end