json_api_test_helpers 1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -11
- data/README.md +21 -4
- data/lib/json_api_test_helpers.rb +6 -2
- data/lib/json_api_test_helpers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c70ab02800ebe7be08cef8201ac03e03bd8422abf8ce965d016afd084621ec5f
|
4
|
+
data.tar.gz: 836fd219786c8b7fe4c5b778c7f582e3e641b61730cb467b23bcd8d516ca3921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c5577d47c9db9e0058ad95a385891f3603253b4331bbf15cdd253d365b5537bf9b66480279255395185d43c7ce13f7534c3fc432f4d7ad8d5cebbca8fa9951
|
7
|
+
data.tar.gz: 9367aa3f8a13efdb25ad91038fc116899a2c6a3c793dc2ec5bcc12d004cb16aa37da4c76af39871ab8db399c60ad0402ce3aca4ee8374252a011a2d118d0f82a
|
data/.gitignore
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/
|
4
|
-
/
|
5
|
-
/
|
6
|
-
/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# rspec failure tracking
|
11
|
-
.rspec_status
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
/**/spec/dummy/log/*.log
|
5
|
+
/**/spec/dummy/tmp/
|
6
|
+
/**/spec/dummy/test/
|
7
|
+
*.gem
|
8
|
+
/**/Gemfile.lock
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# JsonApiTestHelpers
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Collection of helper methods to easy testing of JSON API https://jsonapi.org/ responses
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,26 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Methods:
|
24
|
+
|
25
|
+
| Methods | Params | Description |
|
26
|
+
|---------------|---------|-------------------------------------------------------------------------|
|
27
|
+
| json_response | | Returns parsed `response.body` as Hash with indifferent access or Array |
|
28
|
+
| json_api_record | `record`, `attributes`, `relationships: nil`, `additional: nil`| Returns Hash in JSON API format with serialized object |
|
29
|
+
| json_api_collection | `collection`, `attributes = nil`, `relationships: nil` | Returns Hash in JSON API format with serialized array |
|
30
|
+
| fix_value_for_json | `value` | Fix values which are usually used in Rails apps. `DateTime`, `ActiveSupport::TimeWithZone` to `iso8601`; `CarrierWave::Uploader::Serialization` to `serializable_hash`; everything else to Hash with replaced underscores `_` to minus `-` in attribute names |
|
31
|
+
| fix_comparing_types | `value` | Fix type value to easy compare. `DateTime`, `ActiveSupport::TimeWithZone` to `datetime` with UTC; `ActiveRecord::Point` to string `"#{value.x}, #{value.y}"`. |
|
32
|
+
| attributes_for_nested | `attributes`, `**associations` | Merge `attributes` with associations with JSON API format |
|
33
|
+
|
34
|
+
## Examples
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
expect(json_response).to include_json(json_api_record(User.first))
|
38
|
+
|
39
|
+
expect(json_response).to include_json(json_api_collection(User.all))
|
40
|
+
|
41
|
+
expect(json_response).to include_json(json_api
|
42
|
+
```
|
26
43
|
|
27
44
|
## Development
|
28
45
|
|
@@ -2,8 +2,12 @@ require 'json_api_test_helpers/version'
|
|
2
2
|
|
3
3
|
module JsonApiTestHelpers
|
4
4
|
def json_response
|
5
|
-
|
6
|
-
|
5
|
+
if response.body.present?
|
6
|
+
parsed_json = JSON.parse response.body
|
7
|
+
parsed_json.with_indifferent_access unless parsed_json.is_a? Array
|
8
|
+
else
|
9
|
+
raise 'Response body is empty'
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def json_api_record(record, attributes, relationships: nil, additional: nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_test_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|