rspec_jsonapi_serializer 1.1.0 → 1.3.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/association_matcher.rb +14 -0
- data/lib/rspec_jsonapi_serializer/matchers/association_matchers/id_method_name_matcher.rb +47 -0
- data/lib/rspec_jsonapi_serializer/matchers/association_matchers/object_method_name_matcher.rb +47 -0
- data/lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb +8 -0
- data/lib/rspec_jsonapi_serializer/matchers/have_many_matcher.rb +8 -0
- data/lib/rspec_jsonapi_serializer/matchers/have_one_matcher.rb +8 -0
- data/lib/rspec_jsonapi_serializer/matchers.rb +6 -0
- data/lib/rspec_jsonapi_serializer/version.rb +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01005a800b62bc1790bef3c0b41d7f39528016cbc3f44255100d60c06f6e3f7
|
4
|
+
data.tar.gz: 6870f0d87b139a4e50bedabc2af25faae9a9aa10918ee20cf7a31947b57ecb3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3de4e1e8b9253c30fd625113d0633e70a175546c071c413164af646fceb3785bcd1bb0c310e47f0b91162f48d0a7c989807cc32e13754b4376d89ecdebb195d
|
7
|
+
data.tar.gz: b65538587e22e77df17ef8acaca5694ca9212b7827e9e8ec35dcf4583b860f6ca287396b92bdb01a88aa623f7fabe520c76ff95036c8efb22351f8453e74c771
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "rspec_jsonapi_serializer/matchers/base"
|
4
4
|
require "rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher"
|
5
|
+
require "rspec_jsonapi_serializer/matchers/association_matchers/id_method_name_matcher"
|
6
|
+
require "rspec_jsonapi_serializer/matchers/association_matchers/object_method_name_matcher"
|
5
7
|
require "rspec_jsonapi_serializer/metadata/relationships"
|
6
8
|
|
7
9
|
module RSpecJSONAPISerializer
|
@@ -26,6 +28,18 @@ module RSpecJSONAPISerializer
|
|
26
28
|
self
|
27
29
|
end
|
28
30
|
|
31
|
+
def id_method_name(value)
|
32
|
+
add_submatcher AssociationMatchers::IdMethodNameMatcher.new(value, expected)
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def object_method_name(value)
|
38
|
+
add_submatcher AssociationMatchers::ObjectMethodNameMatcher.new(value, expected)
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
29
43
|
def main_failure_message
|
30
44
|
[expected_message, actual_message].compact.join(", ")
|
31
45
|
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 IdMethodNameMatcher < 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 id_method_name 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).id_method_name
|
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,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 ObjectMethodNameMatcher < 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 object_method_name 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).object_method_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def metadata
|
42
|
+
Metadata::Relationships.new(serializer_instance)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -13,6 +13,14 @@ module RSpecJSONAPISerializer
|
|
13
13
|
association_matcher.matches?(serializer_instance)
|
14
14
|
end
|
15
15
|
|
16
|
+
def id_method_name(value)
|
17
|
+
association_matcher.id_method_name(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def object_method_name(value)
|
21
|
+
association_matcher.object_method_name(value)
|
22
|
+
end
|
23
|
+
|
16
24
|
def serializer(value)
|
17
25
|
association_matcher.serializer(value)
|
18
26
|
end
|
@@ -13,6 +13,14 @@ module RSpecJSONAPISerializer
|
|
13
13
|
association_matcher.matches?(serializer_instance)
|
14
14
|
end
|
15
15
|
|
16
|
+
def id_method_name(value)
|
17
|
+
association_matcher.id_method_name(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def object_method_name(value)
|
21
|
+
association_matcher.object_method_name(value)
|
22
|
+
end
|
23
|
+
|
16
24
|
def serializer(value)
|
17
25
|
association_matcher.serializer(value)
|
18
26
|
end
|
@@ -13,6 +13,14 @@ module RSpecJSONAPISerializer
|
|
13
13
|
association_matcher.matches?(serializer_instance)
|
14
14
|
end
|
15
15
|
|
16
|
+
def id_method_name(value)
|
17
|
+
association_matcher.id_method_name(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def object_method_name(value)
|
21
|
+
association_matcher.object_method_name(value)
|
22
|
+
end
|
23
|
+
|
16
24
|
def serializer(value)
|
17
25
|
association_matcher.serializer(value)
|
18
26
|
end
|
@@ -15,6 +15,8 @@ module RSpecJSONAPISerializer
|
|
15
15
|
# expect(serializer).to belong_to(:team)
|
16
16
|
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
17
17
|
# expect(serializer).to belong_to(:team).serializer(TeamSerializer)
|
18
|
+
# If you have a custom id, you can assert its value with the `id_method_name` submatcher
|
19
|
+
# expect(serializer).to belong_to(:team).id_method_name(:team_slug)
|
18
20
|
def belong_to(expected)
|
19
21
|
BelongToMatcher.new(expected)
|
20
22
|
end
|
@@ -49,6 +51,8 @@ module RSpecJSONAPISerializer
|
|
49
51
|
# expect(serializer).to have_many(:teams)
|
50
52
|
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
51
53
|
# expect(serializer).to have_many(:teams).serializer(TeamSerializer)
|
54
|
+
# If you have a custom id, you can assert its value with the `id_method_name` submatcher
|
55
|
+
# expect(serializer).to have_many(:teams).id_method_name(:team_slugs)
|
52
56
|
def have_many(expected)
|
53
57
|
HaveManyMatcher.new(expected)
|
54
58
|
end
|
@@ -67,6 +71,8 @@ module RSpecJSONAPISerializer
|
|
67
71
|
# expect(serializer).to have_one(:team)
|
68
72
|
# If you have a custom serializer, you can assert its value with the `serializer` submatcher
|
69
73
|
# expect(serializer).to have_one(:team).serializer(TeamSerializer)
|
74
|
+
# If you have a custom id, you can assert its value with the `id_method_name` submatcher
|
75
|
+
# expect(serializer).to have_one(:team).id_method_name(:team_slug)
|
70
76
|
def have_one(expected)
|
71
77
|
HaveOneMatcher.new(expected)
|
72
78
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateus Cruz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializer
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- mateus@intricately.com
|
30
30
|
executables: []
|
@@ -34,6 +34,8 @@ 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/id_method_name_matcher.rb
|
38
|
+
- lib/rspec_jsonapi_serializer/matchers/association_matchers/object_method_name_matcher.rb
|
37
39
|
- lib/rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher.rb
|
38
40
|
- lib/rspec_jsonapi_serializer/matchers/base.rb
|
39
41
|
- lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb
|
@@ -49,14 +51,14 @@ files:
|
|
49
51
|
- lib/rspec_jsonapi_serializer/matchers/have_type_matcher.rb
|
50
52
|
- lib/rspec_jsonapi_serializer/metadata/relationships.rb
|
51
53
|
- lib/rspec_jsonapi_serializer/version.rb
|
52
|
-
homepage: https://github.com/
|
54
|
+
homepage: https://github.com/mateuscruz/rspec_jsonapi_serializer
|
53
55
|
licenses:
|
54
56
|
- MIT
|
55
57
|
metadata:
|
56
|
-
homepage_uri: https://github.com/
|
57
|
-
source_code_uri: https://github.com/
|
58
|
-
changelog_uri: https://github.com/
|
59
|
-
post_install_message:
|
58
|
+
homepage_uri: https://github.com/mateuscruz/rspec_jsonapi_serializer
|
59
|
+
source_code_uri: https://github.com/mateuscruz/rspec_jsonapi_serializer
|
60
|
+
changelog_uri: https://github.com/mateuscruz/rspec_jsonapi_serializer/blob/main/CHANGELOG.md
|
61
|
+
post_install_message:
|
60
62
|
rdoc_options: []
|
61
63
|
require_paths:
|
62
64
|
- lib
|
@@ -71,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
73
|
- !ruby/object:Gem::Version
|
72
74
|
version: '0'
|
73
75
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
75
|
-
signing_key:
|
76
|
+
rubygems_version: 3.3.7
|
77
|
+
signing_key:
|
76
78
|
specification_version: 4
|
77
79
|
summary: RSpec matchers for jsonapi-serializer.
|
78
80
|
test_files: []
|