Skip to content

Commit 5d18849

Browse files
committed
Remove unused :include IncludeDirectives key
Closes gh-1226
1 parent d87cd2d commit 5d18849

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

lib/jsonapi/include_directives.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ class IncludeDirectives
44
# For example ['posts.comments.tags']
55
# will transform into =>
66
# {
7-
# posts:{
8-
# include:true,
9-
# include_related:{
7+
# posts: {
8+
# include_related: {
109
# comments:{
11-
# include:true,
12-
# include_related:{
13-
# tags:{
14-
# include:true
10+
# include_related: {
11+
# tags: {
12+
# include_related: {}
1513
# }
1614
# }
1715
# }
@@ -44,7 +42,7 @@ def parse_include(include)
4442
path.segments.each do |segment|
4543
relationship_name = segment.relationship.name.to_sym
4644

47-
current[:include_related][relationship_name] ||= { include: true, include_related: {} }
45+
current[:include_related][relationship_name] ||= { include_related: {} }
4846
current = current[:include_related][relationship_name]
4947
end
5048

lib/jsonapi/processor.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def find_resource_id_tree_from_resource_relationship(resource, relationship_name
429429
def load_included(resource_klass, source_resource_id_tree, include_related, options)
430430
source_rids = source_resource_id_tree.fragments.keys
431431

432-
include_related.try(:each_pair) do |key, value|
433-
next unless value[:include]
432+
include_related.try(:each_key) do |key|
434433
relationship = resource_klass._relationship(key)
435434
relationship_name = relationship.name.to_sym
436435

test/unit/serializer/include_directives_test.rb

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ def test_one_level_one_include
1010
{
1111
include_related: {
1212
posts: {
13-
include: true,
14-
include_related:{}
13+
include_related: {}
1514
}
1615
}
1716
},
@@ -25,34 +24,54 @@ def test_one_level_multiple_includes
2524
{
2625
include_related: {
2726
posts: {
28-
include: true,
29-
include_related:{}
27+
include_related: {}
3028
},
3129
comments: {
32-
include: true,
33-
include_related:{}
30+
include_related: {}
3431
},
3532
expense_entries: {
36-
include: true,
37-
include_related:{}
33+
include_related: {}
3834
}
3935
}
4036
},
4137
directives)
4238
end
4339

40+
def test_multiple_level_multiple_includes
41+
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments', 'comments', 'expense_entries']).include_directives
42+
43+
assert_hash_equals(
44+
{
45+
include_related: {
46+
posts: {
47+
include_related: {
48+
comments: {
49+
include_related: {}
50+
}
51+
}
52+
},
53+
comments: {
54+
include_related: {}
55+
},
56+
expense_entries: {
57+
include_related: {}
58+
}
59+
}
60+
},
61+
directives)
62+
end
63+
64+
4465
def test_two_levels_include_full_path
4566
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts.comments']).include_directives
4667

4768
assert_hash_equals(
4869
{
4970
include_related: {
5071
posts: {
51-
include: true,
52-
include_related:{
72+
include_related: {
5373
comments: {
54-
include: true,
55-
include_related:{}
74+
include_related: {}
5675
}
5776
}
5877
}
@@ -62,17 +81,15 @@ def test_two_levels_include_full_path
6281
end
6382

6483
def test_two_levels_include_full_path_redundant
65-
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts','posts.comments']).include_directives
84+
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments']).include_directives
6685

6786
assert_hash_equals(
6887
{
6988
include_related: {
7089
posts: {
71-
include: true,
72-
include_related:{
90+
include_related: {
7391
comments: {
74-
include: true,
75-
include_related:{}
92+
include_related: {}
7693
}
7794
}
7895
}
@@ -88,14 +105,11 @@ def test_three_levels_include_full
88105
{
89106
include_related: {
90107
posts: {
91-
include: true,
92-
include_related:{
108+
include_related: {
93109
comments: {
94-
include: true,
95-
include_related:{
110+
include_related: {
96111
tags: {
97-
include: true,
98-
include_related:{}
112+
include_related: {}
99113
}
100114
}
101115
}

0 commit comments

Comments
 (0)