json_api_test_helpers 1.1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_api_test_helpers/response.rb +10 -6
- data/lib/json_api_test_helpers/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8426114ccff33ae5db1ecf0cedcac9a3d6eb8c50d7af2d690271a943c60ca6b
|
4
|
+
data.tar.gz: 13afcc8aac13cb0d0450d2814b4b5526158558507dc103b04f13540bde8e38a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 363c1fb6cce348f7456c4caa56c820a280771b335b0f6be3032543ab617b149c05de1312028216e9e3a6bf3265ffb0c1e5937868478b849a532a3dbd120ba339
|
7
|
+
data.tar.gz: 3f736067be421d041e32d465a5c9d48d0b27ffb608c2028119a303eb047ba616bf95aabc19cbcb9709bc8ef456fd3010b18295c5f448b057ffef6d148054edec
|
@@ -66,8 +66,6 @@ module JsonApiTestHelpers
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
private
|
70
|
-
|
71
69
|
def json_api_record_attributes(record, attributes)
|
72
70
|
attributes.reduce({}) do |hash, attr|
|
73
71
|
hash.merge! attr.to_s.tr('_', '-') => fix_value_for_json(record.send(attr))
|
@@ -76,13 +74,15 @@ module JsonApiTestHelpers
|
|
76
74
|
|
77
75
|
def json_api_relationships(record, relationships)
|
78
76
|
relationships.reduce({}) do |hash, relationship|
|
79
|
-
|
77
|
+
name = relation_has_another_class_name?(relationship) ? relationship[0] : relationship
|
78
|
+
class_name = relation_has_another_class_name?(relationship) ? relationship[1] : relationship
|
79
|
+
object = record.send name
|
80
80
|
data = if object.is_a?(ActiveRecord::Associations::CollectionProxy)
|
81
|
-
object.reduce([]) { |result, item| result << data_relationship_object(item,
|
81
|
+
object.reduce([]) { |result, item| result << data_relationship_object(item, class_name) }
|
82
82
|
else
|
83
|
-
object.present? ? data_relationship_object(object,
|
83
|
+
object.present? ? data_relationship_object(object, class_name) : {}
|
84
84
|
end
|
85
|
-
hash.merge! json_api_model_name(
|
85
|
+
hash.merge! json_api_model_name(name) => { 'data' => data }
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -96,5 +96,9 @@ module JsonApiTestHelpers
|
|
96
96
|
'type' => json_api_model_name(relationship).pluralize
|
97
97
|
}
|
98
98
|
end
|
99
|
+
|
100
|
+
def relation_has_another_class_name?(relationship)
|
101
|
+
relationship.is_a? Array
|
102
|
+
end
|
99
103
|
end
|
100
104
|
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: 1.
|
4
|
+
version: '1.2'
|
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-
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.7.6
|
96
|
+
rubygems_version: 3.0.3
|
98
97
|
signing_key:
|
99
98
|
specification_version: 4
|
100
99
|
summary: JSON API helpers for testing
|