rspec_jsonapi_serializer 1.1.2 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61f6a27fca68262e1efe72673c7519610c53c72de7f5aeb393c9ad5b32864bfd
4
- data.tar.gz: 7f5745572ef15b1442df7d055802f5ffec3e5aac01c14b92e97e80db827f6387
3
+ metadata.gz: fc87e1c0dd34c16432247cfbb0050bf67e1666b557f49a60b2400cbf84e62d40
4
+ data.tar.gz: 7cb83bb3fb733102671a0fe860dfd12a2e8d2070e0613879cf22502462d40254
5
5
  SHA512:
6
- metadata.gz: 8f35c497af303a5802f192639b5d36997d6ea76626d7229cbc9d1990882f7163bdb5f6ac12e4f93e2990a95d9c21888ffa465e02ac5edc0a414ced5ef0c9dadf
7
- data.tar.gz: 7c0ba61d35ad01c788164f650a60b0d532f856cac08f05f974c33c04309b92d7656c776452d7b83418580c700b6f5accab09b6e8d8a7d40c923f848c73e87b29
6
+ metadata.gz: 9e22aa5740094b7d307b8ea1a738546d1fde3bcbe8f28043e66d6211bf85cb457cc2d36a0d819c1f1f507f6c6980f1a699b5ff55d11d2b88d08c3478c4252b9a
7
+ data.tar.gz: bacc318b8c1d7756c9109113b116a2d710d966efa9578b2dc61e07ab67056d9300d1a0138b69d5e415186c49160813247e2a9a7083385c3af4836011fd6cdaba
@@ -2,6 +2,7 @@
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"
5
6
  require "rspec_jsonapi_serializer/metadata/relationships"
6
7
 
7
8
  module RSpecJSONAPISerializer
@@ -26,6 +27,12 @@ module RSpecJSONAPISerializer
26
27
  self
27
28
  end
28
29
 
30
+ def id_method_name(value)
31
+ add_submatcher AssociationMatchers::IdMethodNameMatcher.new(value, expected)
32
+
33
+ self
34
+ end
35
+
29
36
  def description
30
37
  description = "#{association_message} #{expected}"
31
38
 
@@ -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 description
22
+ "with id method name #{expected}"
23
+ end
24
+
25
+ def expectation
26
+ [ "with id method name #{expected}", actual_message ].compact.join(", ")
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :relationship_target
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
@@ -13,6 +13,10 @@ 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
+
16
20
  def serializer(value)
17
21
  association_matcher.serializer(value)
18
22
  end
@@ -13,6 +13,10 @@ 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
+
16
20
  def serializer(value)
17
21
  association_matcher.serializer(value)
18
22
  end
@@ -13,6 +13,10 @@ 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
+
16
20
  def serializer(value)
17
21
  association_matcher.serializer(value)
18
22
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecJSONAPISerializer
4
- VERSION = "1.1.2"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_jsonapi_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateus Cruz
@@ -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/id_method_name_matcher.rb
37
38
  - lib/rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher.rb
38
39
  - lib/rspec_jsonapi_serializer/matchers/base.rb
39
40
  - lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb