rspec_jsonapi_serializer 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rspec_jsonapi_serializer/matchers.rb +6 -0
- data/lib/rspec_jsonapi_serializer/matchers/association_matcher.rb +20 -5
- data/lib/rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher.rb +47 -0
- data/lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb +4 -0
- data/lib/rspec_jsonapi_serializer/matchers/have_many_matcher.rb +4 -0
- data/lib/rspec_jsonapi_serializer/matchers/have_one_matcher.rb +4 -0
- data/lib/rspec_jsonapi_serializer/metadata/relationships.rb +26 -0
- data/lib/rspec_jsonapi_serializer/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e24d0b3794bdc77750c98e578543eb472a655f79ea61190682623b2ce7f8e89f
|
4
|
+
data.tar.gz: 89cfb3714d48e15345fbad93540bdf58b02153f4001e88defc66fbc63758d672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2693f3a69e99f02b54d6a283b377bc41f02ef74f82455d78d7c4b98965645f972939e2df2aeaea107f2546f9e0a69f2cc51e803cdaf3e6090f8b09491929ce09
|
7
|
+
data.tar.gz: 2f5f2c1c81eb3a56e974d807c6136f2908540bb4afc07e25a179c03af36e5b0b9f0e583b8a707804b7e1d1cf032b84161ff8ea6221c21bf989e1c088c8675797
|
@@ -13,6 +13,8 @@ module RSpecJSONAPISerializer
|
|
13
13
|
module Matchers
|
14
14
|
# This allows us to assert attributes on a serializer, e.g.:
|
15
15
|
# expect(serializer).to belong_to(:team)
|
16
|
+
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
17
|
+
# expect(serializer).to belong_to(:team).serializer(TeamSerializer)
|
16
18
|
def belong_to(expected)
|
17
19
|
BelongToMatcher.new(expected)
|
18
20
|
end
|
@@ -45,6 +47,8 @@ module RSpecJSONAPISerializer
|
|
45
47
|
|
46
48
|
# This allows us to assert attributes on a serializer, e.g.:
|
47
49
|
# expect(serializer).to have_many(:teams)
|
50
|
+
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
51
|
+
# expect(serializer).to have_many(:teams).serializer(TeamSerializer)
|
48
52
|
def have_many(expected)
|
49
53
|
HaveManyMatcher.new(expected)
|
50
54
|
end
|
@@ -61,6 +65,8 @@ module RSpecJSONAPISerializer
|
|
61
65
|
|
62
66
|
# This allows us to assert attributes on a serializer, e.g.:
|
63
67
|
# expect(serializer).to have_one(:team)
|
68
|
+
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
69
|
+
# expect(serializer).to have_one(:team).serializer(TeamSerializer)
|
64
70
|
def have_one(expected)
|
65
71
|
HaveOneMatcher.new(expected)
|
66
72
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rspec_jsonapi_serializer/matchers/base"
|
4
|
+
require "rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher"
|
5
|
+
require "rspec_jsonapi_serializer/metadata/relationships"
|
4
6
|
|
5
7
|
module RSpecJSONAPISerializer
|
6
8
|
module Matchers
|
@@ -15,8 +17,13 @@ module RSpecJSONAPISerializer
|
|
15
17
|
def matches?(serializer_instance)
|
16
18
|
@serializer_instance = serializer_instance
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
relationship_matches? && submatchers_match?
|
21
|
+
end
|
22
|
+
|
23
|
+
def serializer(value)
|
24
|
+
add_submatcher AssociationMatchers::SerializerMatcher.new(value, expected)
|
25
|
+
|
26
|
+
self
|
20
27
|
end
|
21
28
|
|
22
29
|
def main_failure_message
|
@@ -31,8 +38,12 @@ module RSpecJSONAPISerializer
|
|
31
38
|
"expected #{serializer_name} to #{association_message} #{expected}"
|
32
39
|
end
|
33
40
|
|
41
|
+
def relationship_matches?
|
42
|
+
actual.present? && actual.relationship_type == relationship_type
|
43
|
+
end
|
44
|
+
|
34
45
|
def actual_message
|
35
|
-
actual ? "got :#{actual} instead" : nil
|
46
|
+
actual ? "got :#{actual.relationship_type} instead" : nil
|
36
47
|
end
|
37
48
|
|
38
49
|
def association_message
|
@@ -40,11 +51,15 @@ module RSpecJSONAPISerializer
|
|
40
51
|
end
|
41
52
|
|
42
53
|
def actual
|
43
|
-
|
54
|
+
metadata.relationship(expected)
|
44
55
|
end
|
45
56
|
|
46
57
|
def relationships
|
47
|
-
|
58
|
+
metadata.relationships
|
59
|
+
end
|
60
|
+
|
61
|
+
def metadata
|
62
|
+
Metadata::Relationships.new(serializer_instance)
|
48
63
|
end
|
49
64
|
end
|
50
65
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rspec_jsonapi_serializer/metadata/relationships"
|
4
|
+
|
5
|
+
module RSpecJSONAPISerializer
|
6
|
+
module Matchers
|
7
|
+
module AssociationMatchers
|
8
|
+
class SerializerMatcher < Base
|
9
|
+
def initialize(value, relationship_target)
|
10
|
+
super(value)
|
11
|
+
|
12
|
+
@relationship_target = relationship_target
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(serializer_instance)
|
16
|
+
@serializer_instance = serializer_instance
|
17
|
+
|
18
|
+
actual == expected
|
19
|
+
end
|
20
|
+
|
21
|
+
def main_failure_message
|
22
|
+
[expected_message, actual_message].compact.join(", ")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :relationship_target
|
28
|
+
|
29
|
+
def expected_message
|
30
|
+
"expected #{serializer_name} to use #{expected} as serializer for #{relationship_target}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def actual_message
|
34
|
+
actual ? "got #{actual} instead" : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def actual
|
38
|
+
metadata.relationship(relationship_target).serializer
|
39
|
+
end
|
40
|
+
|
41
|
+
def metadata
|
42
|
+
Metadata::Relationships.new(serializer_instance)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
require "rspec_jsonapi_serializer/metadata/relationships"
|
5
|
+
|
6
|
+
module RSpecJSONAPISerializer
|
7
|
+
module Metadata
|
8
|
+
class Relationships
|
9
|
+
def initialize(serializer)
|
10
|
+
@serializer = serializer
|
11
|
+
end
|
12
|
+
|
13
|
+
def relationship(key)
|
14
|
+
relationships.values.find { |relationship| relationship.key.to_s == key.to_s }
|
15
|
+
end
|
16
|
+
|
17
|
+
def relationships
|
18
|
+
serializer.class&.relationships_to_serialize || {}
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :serializer
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_jsonapi_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateus Cruz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializer
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/rspec_jsonapi_serializer.rb
|
35
35
|
- lib/rspec_jsonapi_serializer/matchers.rb
|
36
36
|
- lib/rspec_jsonapi_serializer/matchers/association_matcher.rb
|
37
|
+
- lib/rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher.rb
|
37
38
|
- lib/rspec_jsonapi_serializer/matchers/base.rb
|
38
39
|
- lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb
|
39
40
|
- lib/rspec_jsonapi_serializer/matchers/have_attribute_matcher.rb
|
@@ -46,6 +47,7 @@ files:
|
|
46
47
|
- lib/rspec_jsonapi_serializer/matchers/have_meta_matchers/as_matcher.rb
|
47
48
|
- lib/rspec_jsonapi_serializer/matchers/have_one_matcher.rb
|
48
49
|
- lib/rspec_jsonapi_serializer/matchers/have_type_matcher.rb
|
50
|
+
- lib/rspec_jsonapi_serializer/metadata/relationships.rb
|
49
51
|
- lib/rspec_jsonapi_serializer/version.rb
|
50
52
|
homepage: https://github.com/teamintricately/rspec_jsonapi_serializer
|
51
53
|
licenses:
|