jsonapi_rspec 0.1.0 → 0.2.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/Gemfile.lock +1 -1
- data/README.md +13 -12
- data/lib/jsonapi_rspec/be_json_api_response_for.rb +6 -4
- data/lib/jsonapi_rspec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b4c3c8b180371728a5009b411cda7f77e2abe6
|
4
|
+
data.tar.gz: 258bf4d2d722df6b7c821d4d9aafd0d60f7261f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad0236147e56ee872977834fc829c04bbe5e20442d06c1da8abb2164e1a2a0a9467f4d425bd7cfd3827949156d247cdd334eafef56389c7bede2543a88c9cc2
|
7
|
+
data.tar.gz: 0db6c4e02dc98702339c10cf7a28f6b247057c63332922d15b553770f98034527903cf08434ae3650c2d660646073dedba3894d21cd5a394af12588ca2742805
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# JsonapiRspec
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/jsonapi_rspec)
|
3
4
|
[](https://travis-ci.org/midwire/jsonapi_rspec)
|
4
5
|
|
5
6
|
Match json:api formatted Rack::Response (or Rails controller response) to an instantiated object or ActiveRecord/ActiveModel object.
|
6
7
|
|
7
|
-
This project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to
|
8
|
+
This project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to put it all in a gem.
|
8
9
|
|
9
|
-
As such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate.
|
10
|
+
As such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate, and [pull requests](https://github.com/midwire/jsonapi_rspec/pulls) are always welcome.
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
@@ -33,7 +34,7 @@ expect(response).to be_jsonapi_response_for(my_model)
|
|
33
34
|
```
|
34
35
|
|
35
36
|
It currently tests for required json:api sections and matching attributes for the passed model instance.
|
36
|
-
```
|
37
|
+
```
|
37
38
|
{
|
38
39
|
"jsonapi": "version 1.1", // does not check
|
39
40
|
"data":{ // checks if exists and is a hash
|
@@ -75,19 +76,19 @@ It currently tests for required json:api sections and matching attributes for th
|
|
75
76
|
|
76
77
|
### Possible Failure Messages
|
77
78
|
|
78
|
-
* '
|
79
|
-
* "
|
80
|
-
* 'Expected response to match an object instance but it is an empty string'
|
81
|
-
* "The 'data' section is missing or invalid"
|
79
|
+
* "Attribute: :#{attr_name} with a value of '#{json_val}'(#{json_val.class.name}) does not match object: '#{obj_val}'(#{obj_val.class.name})
|
80
|
+
* "Expected '#{value}' to match object id: '#{object_id}'"
|
82
81
|
* "Expected data:type '#{data_type}' to match: '#{object_type}'"
|
82
|
+
* "Fix 'match_attribute?' method to handle: '#{obj_val_class_name}'" - [please file an issue](https://github.com/midwire/jsonapi_rspec/issues/new) if you get this one.
|
83
|
+
* "The 'data' section is missing or invalid"
|
83
84
|
* "The 'meta' section is missing or invalid"
|
84
|
-
* "The 'meta:version' is missing"
|
85
85
|
* "The 'meta:copyright' is missing or invalid - regex: '/^Copyright.+\\d{4}/'"
|
86
|
-
* "
|
87
|
-
* "
|
88
|
-
*
|
86
|
+
* "The 'meta:version' is missing"
|
87
|
+
* "Unexpected key in response: '#{key}'"
|
88
|
+
* 'Expected response to match an object instance but it is an empty string'
|
89
|
+
* 'Response is an error'
|
89
90
|
|
90
|
-
See the specs for details.
|
91
|
+
[See the specs](https://github.com/midwire/jsonapi_rspec/blob/develop/spec/lib/jsonapi_rspec/be_json_api_response_for_spec.rb) for more details.
|
91
92
|
|
92
93
|
### Configuration
|
93
94
|
|
@@ -14,8 +14,9 @@ require 'active_support/all'
|
|
14
14
|
# @author Chris Blackburn <87a1779b@opayq.com>
|
15
15
|
#
|
16
16
|
class BeJsonApiResponseFor
|
17
|
-
def initialize(object_instance)
|
17
|
+
def initialize(object_instance, plural_form = nil)
|
18
18
|
@object_instance = object_instance
|
19
|
+
@plural_form = plural_form
|
19
20
|
end
|
20
21
|
|
21
22
|
def matches?(response)
|
@@ -91,7 +92,8 @@ class BeJsonApiResponseFor
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def valid_type?(data_type)
|
94
|
-
object_type = @
|
95
|
+
object_type = @plural_form ||
|
96
|
+
@object_instance.class.name.pluralize.underscore.dasherize
|
95
97
|
unless data_type == object_type
|
96
98
|
return set_failure_message("Expected data:type '#{data_type}' to match: '#{object_type}'")
|
97
99
|
end
|
@@ -173,9 +175,9 @@ end
|
|
173
175
|
# Usage:
|
174
176
|
# expect(response).to be_jsonapi_response_for(object_instance)
|
175
177
|
#
|
176
|
-
RSpec::Matchers.define :be_jsonapi_response_for do |object|
|
178
|
+
RSpec::Matchers.define :be_jsonapi_response_for do |object, plural_form|
|
177
179
|
match do |actual_response|
|
178
|
-
@instance = BeJsonApiResponseFor.new(object)
|
180
|
+
@instance = BeJsonApiResponseFor.new(object, plural_form)
|
179
181
|
|
180
182
|
def failure_message
|
181
183
|
@instance.failure_message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|