Skip to content

Commit d82073c

Browse files
committed
Simplify and test relationship_segments
1 parent 9918556 commit d82073c

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/jsonapi/path.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ def initialize(resource_klass:,
2525
end
2626

2727
def relationship_segments
28-
relationships = []
29-
@segments.each do |segment|
30-
relationships << segment if segment.is_a?(PathSegment::Relationship)
31-
end
32-
relationships
28+
@segments.select {|p| p.is_a?(PathSegment::Relationship)}
3329
end
3430

3531
def relationship_path_string

test/unit/paths/path_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def test_two_relationships_and_field
4040
assert_equal Api::V1::PostResource._relationship(:comments), path.segments[0].relationship
4141
assert_equal Api::V1::CommentResource._relationship(:author), path.segments[1].relationship
4242
assert_equal 'name', path.segments[2].field_name
43+
44+
assert_equal 2, path.relationship_segments.length
4345
end
4446

4547
def test_two_relationships_and_parse_fields_false_raises_with_field

0 commit comments

Comments
 (0)