Skip to content

Commit

Permalink
Remove unused :include IncludeDirectives key
Browse files Browse the repository at this point in the history
Closes gh-1226
  • Loading branch information
lgebhardt committed Mar 22, 2019
1 parent d87cd2d commit 5d18849
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
14 changes: 6 additions & 8 deletions lib/jsonapi/include_directives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ class IncludeDirectives
# For example ['posts.comments.tags']
# will transform into =>
# {
# posts:{
# include:true,
# include_related:{
# posts: {
# include_related: {
# comments:{
# include:true,
# include_related:{
# tags:{
# include:true
# include_related: {
# tags: {
# include_related: {}
# }
# }
# }
Expand Down Expand Up @@ -44,7 +42,7 @@ def parse_include(include)
path.segments.each do |segment|
relationship_name = segment.relationship.name.to_sym

current[:include_related][relationship_name] ||= { include: true, include_related: {} }
current[:include_related][relationship_name] ||= { include_related: {} }
current = current[:include_related][relationship_name]
end

Expand Down
3 changes: 1 addition & 2 deletions lib/jsonapi/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ def find_resource_id_tree_from_resource_relationship(resource, relationship_name
def load_included(resource_klass, source_resource_id_tree, include_related, options)
source_rids = source_resource_id_tree.fragments.keys

include_related.try(:each_pair) do |key, value|
next unless value[:include]
include_related.try(:each_key) do |key|
relationship = resource_klass._relationship(key)
relationship_name = relationship.name.to_sym

Expand Down
60 changes: 37 additions & 23 deletions test/unit/serializer/include_directives_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def test_one_level_one_include
{
include_related: {
posts: {
include: true,
include_related:{}
include_related: {}
}
}
},
Expand All @@ -25,34 +24,54 @@ def test_one_level_multiple_includes
{
include_related: {
posts: {
include: true,
include_related:{}
include_related: {}
},
comments: {
include: true,
include_related:{}
include_related: {}
},
expense_entries: {
include: true,
include_related:{}
include_related: {}
}
}
},
directives)
end

def test_multiple_level_multiple_includes
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments', 'comments', 'expense_entries']).include_directives

assert_hash_equals(
{
include_related: {
posts: {
include_related: {
comments: {
include_related: {}
}
}
},
comments: {
include_related: {}
},
expense_entries: {
include_related: {}
}
}
},
directives)
end


def test_two_levels_include_full_path
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts.comments']).include_directives

assert_hash_equals(
{
include_related: {
posts: {
include: true,
include_related:{
include_related: {
comments: {
include: true,
include_related:{}
include_related: {}
}
}
}
Expand All @@ -62,17 +81,15 @@ def test_two_levels_include_full_path
end

def test_two_levels_include_full_path_redundant
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts','posts.comments']).include_directives
directives = JSONAPI::IncludeDirectives.new(PersonResource, ['posts', 'posts.comments']).include_directives

assert_hash_equals(
{
include_related: {
posts: {
include: true,
include_related:{
include_related: {
comments: {
include: true,
include_related:{}
include_related: {}
}
}
}
Expand All @@ -88,14 +105,11 @@ def test_three_levels_include_full
{
include_related: {
posts: {
include: true,
include_related:{
include_related: {
comments: {
include: true,
include_related:{
include_related: {
tags: {
include: true,
include_related:{}
include_related: {}
}
}
}
Expand Down

0 comments on commit 5d18849

Please sign in to comment.