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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '085d264d18f15d881bcf15ed6afc54914872902bd5b08737e5db7105d8c4de0b'
4
- data.tar.gz: b4b3ef5093a2ebb42c030ba1776ebdb5babde215c684db5d48ba00e92a7509d1
3
+ metadata.gz: d8426114ccff33ae5db1ecf0cedcac9a3d6eb8c50d7af2d690271a943c60ca6b
4
+ data.tar.gz: 13afcc8aac13cb0d0450d2814b4b5526158558507dc103b04f13540bde8e38a5
5
5
  SHA512:
6
- metadata.gz: 89ffbc28e38bba6dceebc8085c393c93b5f40276568334e4189a8ccb6fb1ff0e38fdd6ba50ca603563a6194da385b50996808ac2dd448bf8df724f2ae90d7934
7
- data.tar.gz: b3b5eb41031be9c7215e2d2a21aec128a9d879a27524f8eb5e56d8382e69e1be34ca184f35d7865dd065c84ba664125b622e3956330f958e9d0b314ba519bfef
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
- object = record.send relationship
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, relationship) }
81
+ object.reduce([]) { |result, item| result << data_relationship_object(item, class_name) }
82
82
  else
83
- object.present? ? data_relationship_object(object, relationship) : {}
83
+ object.present? ? data_relationship_object(object, class_name) : {}
84
84
  end
85
- hash.merge! json_api_model_name(relationship) => { 'data' => data }
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
@@ -1,3 +1,3 @@
1
1
  module JsonApiTestHelpers
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2'
3
3
  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.1.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-07-25 00:00:00.000000000 Z
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
- rubyforge_project:
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