-
Notifications
You must be signed in to change notification settings - Fork 539
Expand file tree
/
Copy pathinclude_directives_test.rb
More file actions
99 lines (82 loc) · 2.6 KB
/
include_directives_test.rb
File metadata and controls
99 lines (82 loc) · 2.6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require File.expand_path('../../../test_helper', __FILE__)
require 'jsonapi-resources'
class IncludeDirectivesTest < ActiveSupport::TestCase
def test_one_level_one_include
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts']).include_directives
assert_hash_equals({ posts: {} }, directives)
end
def test_one_level_multiple_includes
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'comments', 'expense_entries']).include_directives
assert_hash_equals(
{
posts: {},
comments: {},
expense_entries: {}
},
directives)
end
def test_multiple_level_multiple_includes
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments', 'comments', 'expense_entries']).include_directives
assert_hash_equals(
{
posts: {
comments: {}
},
comments: {},
expense_entries: {}
},
directives)
end
def test_two_levels_include_full_path
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts.comments']).include_directives
assert_hash_equals(
{
posts: {
comments: {}
}
},
directives)
end
def test_two_levels_include_full_path_redundant
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments']).include_directives
assert_hash_equals(
{
posts: {
comments: {}
}
},
directives)
end
def test_three_levels_include_full
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts.comments.tags']).include_directives
assert_hash_equals(
{
posts: {
comments: {
tags: {}
}
}
},
directives)
end
# def test_three_levels_include_full_model_includes
# directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts.comments.tags'])
# assert_array_equals([{:posts=>[{:comments=>[:tags]}]}], directives.model_includes)
# end
#
def test_invalid_includes_1
assert_raises JSONAPI::Exceptions::InvalidInclude do
JSONAPI::IncludeDirectives.new(PersonResource, ['../../../../']).include_directives
end
end
def test_invalid_includes_2
assert_raises JSONAPI::Exceptions::InvalidInclude do
JSONAPI::IncludeDirectives.new(PersonResource, ['posts./sdaa./........']).include_directives
end
end
def test_invalid_includes_3
assert_raises JSONAPI::Exceptions::InvalidInclude do
JSONAPI::IncludeDirectives.new(PersonResource, ['invalid../../../../']).include_directives
end
end
end