jsonapi-resources-matchers 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/jsonapi-resources-matchers.gemspec +1 -1
- data/lib/jsonapi/resources/matchers.rb +1 -0
- data/lib/jsonapi/resources/matchers/have_attribute.rb +2 -0
- data/lib/jsonapi/resources/matchers/relationship.rb +5 -0
- data/lib/jsonapi/resources/matchers/services/check_serialization.rb +20 -0
- data/lib/jsonapi/resources/matchers/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5eb7553b4ddb23d720be211d89683f3c4c88bc
|
4
|
+
data.tar.gz: d6a11affc10bff3b80af212f6ca782ea87aff4bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46810d777d7bb4c400f86d5991111f0c42c890cb80e3948550838314022f645a1cd0402d41ff3dda885df3eb3dd8b14d9c578d01ddb6084890441255bd5af71c
|
7
|
+
data.tar.gz: 3fa6ff1723de7a92681b15559bcd0620a687c05c33b668a74d774e64201dbf5a561f91244cb7a8e398facbf7dfddb3e756ade38e7c403b72271ae909ec23f57e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [1.0.0] - 2016-02-28
|
6
|
+
### Changed
|
7
|
+
- Require jsonapi-resources 0.9.0 and above
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
- `have_attribute` and `have_one`, `have_many` matchers: give instructions to the developer when the primary key is not set
|
11
|
+
|
5
12
|
## [0.6.0] - 2016-12-22
|
6
13
|
### Added
|
7
14
|
- support for `have_sortable_field`
|
data/Gemfile
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency "jsonapi-resources", ">= 0.
|
30
|
+
spec.add_dependency "jsonapi-resources", ">= 0.9.0"
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.10"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "jsonapi/resources/matchers/version"
|
2
|
+
require "jsonapi/resources/matchers/services/check_serialization"
|
2
3
|
require "jsonapi/resources/matchers/have_attribute"
|
3
4
|
require "jsonapi/resources/matchers/have_creatable_field"
|
4
5
|
require "jsonapi/resources/matchers/have_updatable_field"
|
@@ -25,11 +25,16 @@ module JSONAPI
|
|
25
25
|
def matches?(resource)
|
26
26
|
self.resource = resource
|
27
27
|
|
28
|
+
is_serializable? &&
|
28
29
|
has_key_in_relationships? &&
|
29
30
|
matches_class_name? &&
|
30
31
|
matches_relation_name?
|
31
32
|
end
|
32
33
|
|
34
|
+
def is_serializable?
|
35
|
+
CheckSerialization.(self.resource)
|
36
|
+
end
|
37
|
+
|
33
38
|
def has_key_in_relationships?
|
34
39
|
serialized_hash = JSONAPI::ResourceSerializer.new(resource.class).
|
35
40
|
serialize_to_hash(resource).with_indifferent_access
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JSONAPI::Resources::Matchers
|
2
|
+
class CheckSerialization
|
3
|
+
|
4
|
+
MESSAGE = [
|
5
|
+
"`:primary_key` is nil.",
|
6
|
+
"In this scenario, jsonapi-resources does not",
|
7
|
+
"include the attributes in order for this matcher to work.",
|
8
|
+
"To get this working, initialize the model with a primary key set.",
|
9
|
+
].join(" ")
|
10
|
+
|
11
|
+
def self.call(resource)
|
12
|
+
return true if resource.try(:id).present?
|
13
|
+
fail(
|
14
|
+
ArgumentError,
|
15
|
+
MESSAGE.gsub(":primary_key", resource.class._primary_key.to_s)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- G5
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-resources
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.9.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.9.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/jsonapi/resources/matchers/have_updatable_field.rb
|
113
113
|
- lib/jsonapi/resources/matchers/integrations/rspec.rb
|
114
114
|
- lib/jsonapi/resources/matchers/relationship.rb
|
115
|
+
- lib/jsonapi/resources/matchers/services/check_serialization.rb
|
115
116
|
- lib/jsonapi/resources/matchers/version.rb
|
116
117
|
homepage: https://github.com/G5/jsonapi-resources-matchers
|
117
118
|
licenses:
|