json_api_test_helpers 1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/json_api_test_helpers/response.rb +3 -3
- 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: 7049d95423c1b890bc7682de2f30aa6db778526efc22e4598f5d99bbca22c528
|
4
|
+
data.tar.gz: fed032e89f35c31a30e52f9c1940e1924225e230e6032db949577d94e47d8bc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40db80329ad03c43ef159dcecfeb8909760a72e53794dab345c1259b2b566f073f7ae718900a602ea488e600b47277cc96c1d7dbb1d57fb6e17897fcedb537f2
|
7
|
+
data.tar.gz: a32d7c16a93ff291a2f9472823248bb1b7f69d55a45aad745dd255beafa78e981acc96194696002d9a2a4f2c0525322222588e772d5d293b933d133ce09e42f1
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ Methods:
|
|
27
27
|
| json_response | | Returns parsed `response.body` as Hash with indifferent access or Array |
|
28
28
|
| json_api_record | `record`, `attributes`, `relationships: nil`, `additional: nil`| Returns Hash in JSON API format with serialized object |
|
29
29
|
| json_api_collection | `collection`, `attributes = nil`, `relationships: nil` | Returns Hash in JSON API format with serialized array |
|
30
|
+
| json_api_relationships | `record`, `relationships` | Returns Hash of the record's relationships. When `relationships` argument is Array, all releations have name same as model class names. When it's Hash { relationship_name => class_name } |
|
30
31
|
| 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
32
|
| 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
33
|
| attributes_for_nested | `attributes`, `**associations` | Merge `attributes` with associations with JSON API format |
|
@@ -39,6 +40,8 @@ expect(json_response).to include_json(json_api_record(User.first, [ :email, :ano
|
|
39
40
|
|
40
41
|
expect(json_response).to include_json(json_api_collection(User.all))
|
41
42
|
|
43
|
+
expect(json_response).to include_json(json_api_relationships(user, posts: :user_posts))
|
44
|
+
|
42
45
|
post 'some_post', params: json_api_params({ attribute1: :value1, attribute2: :value2 })
|
43
46
|
```
|
44
47
|
|
@@ -12,7 +12,7 @@ module JsonApiTestHelpers
|
|
12
12
|
def json_api_record(record, attributes, relationships: nil, additional: nil)
|
13
13
|
json = {
|
14
14
|
'data' => {
|
15
|
-
'id' => record.
|
15
|
+
'id' => record.uuid,
|
16
16
|
'attributes' => json_api_record_attributes(record, attributes)
|
17
17
|
}
|
18
18
|
}
|
@@ -24,7 +24,7 @@ module JsonApiTestHelpers
|
|
24
24
|
{
|
25
25
|
'data' => collection.map do |record|
|
26
26
|
hash = {
|
27
|
-
'id' => record.
|
27
|
+
'id' => record.uuid
|
28
28
|
}
|
29
29
|
hash['attributes'] = json_api_record_attributes(record, attributes) if attributes
|
30
30
|
hash['relationships'] = json_api_relationships(record, relationships) if relationships
|
@@ -92,7 +92,7 @@ module JsonApiTestHelpers
|
|
92
92
|
|
93
93
|
def data_relationship_object(object, relationship)
|
94
94
|
{
|
95
|
-
'id' => object.
|
95
|
+
'id' => object.uuid,
|
96
96
|
'type' => json_api_model_name(relationship).pluralize
|
97
97
|
}
|
98
98
|
end
|
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.2.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:
|
11
|
+
date: 2020-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|