Skip to content

Commit

Permalink
Simplify and test relationship_segments
Browse files Browse the repository at this point in the history
  • Loading branch information
lgebhardt committed Feb 8, 2019
1 parent 9918556 commit d82073c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/jsonapi/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def initialize(resource_klass:,
end

def relationship_segments
relationships = []
@segments.each do |segment|
relationships << segment if segment.is_a?(PathSegment::Relationship)
end
relationships
@segments.select {|p| p.is_a?(PathSegment::Relationship)}
end

def relationship_path_string
Expand Down
2 changes: 2 additions & 0 deletions test/unit/paths/path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_two_relationships_and_field
assert_equal Api::V1::PostResource._relationship(:comments), path.segments[0].relationship
assert_equal Api::V1::CommentResource._relationship(:author), path.segments[1].relationship
assert_equal 'name', path.segments[2].field_name

assert_equal 2, path.relationship_segments.length
end

def test_two_relationships_and_parse_fields_false_raises_with_field
Expand Down

0 comments on commit d82073c

Please sign in to comment.