jsonapi_expectations 0.0.3 → 0.0.5
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/lib/jsonapi_expectations.rb +75 -29
- 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: 21c2096f2fc743d92f1a54390a688d52086e9788
|
4
|
+
data.tar.gz: 95cf32b87db3ef08d7321d7f6efad2c023ea633e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80cf32bab52f34beb07fe627ffd0abcce9f76830814076756e0b31afb0ccd3ab3c7e50c99185971843fb991e89979f6b47880d0d04090fbc686d7966cbea9a3f
|
7
|
+
data.tar.gz: 9ab15ccbe87fd48208c946984f606e2d8cb03b7a4f52c3fbdcd53abbf80f858069cd9a9c71323a6099e4d37524dbcb685f724553d5c9b44247be88e51056ff1d
|
data/lib/jsonapi_expectations.rb
CHANGED
@@ -3,18 +3,35 @@ require 'active_support/inflector'
|
|
3
3
|
|
4
4
|
module JsonapiExpectations
|
5
5
|
def expect_attributes attrs
|
6
|
-
|
7
|
-
|
6
|
+
expect_valid_data
|
7
|
+
if is_array_response?
|
8
|
+
location = 'data.?.attributes'
|
9
|
+
else
|
10
|
+
location = 'data.attributes'
|
11
|
+
end
|
12
|
+
expect_json location, dasherize_keys(attrs)
|
8
13
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
alias_method :expect_attributes_in_list, :expect_attributes
|
15
|
+
|
16
|
+
def expect_attributes_absent *keys
|
17
|
+
expect_valid_data
|
18
|
+
if is_array_response?
|
19
|
+
json_body[:data].each do |data|
|
20
|
+
dasherize_array(keys).each do |key|
|
21
|
+
expect(data[key].present?).to be_falsey
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
dasherize_array(keys).each do |key|
|
26
|
+
expect(json_body[:data][:attributes][key].present?).to be_falsey
|
27
|
+
end
|
28
|
+
end
|
13
29
|
end
|
30
|
+
alias_method :expect_attributes_absent_in_list, :expect_attributes_absent
|
14
31
|
|
15
32
|
def expect_relationship opts
|
16
|
-
|
17
|
-
location = if
|
33
|
+
expect_valid_data
|
34
|
+
location = if is_array_response?
|
18
35
|
"data.?.relationships.#{opts[:key]}"
|
19
36
|
else
|
20
37
|
"data.relationships.#{opts[:key]}"
|
@@ -41,48 +58,69 @@ module JsonapiExpectations
|
|
41
58
|
end
|
42
59
|
end
|
43
60
|
end
|
44
|
-
|
45
|
-
def expect_relationship_in_list opts
|
46
|
-
opts[:in_list] = true
|
47
|
-
expect_relationship opts
|
48
|
-
end
|
61
|
+
alias_method :expect_relationship_in_list, :expect_relationship
|
49
62
|
|
50
63
|
def expect_item_count number
|
64
|
+
expect_valid_data
|
51
65
|
expect_json_sizes data: number
|
52
66
|
end
|
53
67
|
|
54
|
-
def
|
68
|
+
def expect_record find_me, opts = {}
|
55
69
|
opts[:type] ||= jsonapi_type find_me
|
56
|
-
|
57
|
-
|
70
|
+
if opts[:included]
|
71
|
+
location = json_body[:included]
|
72
|
+
else
|
73
|
+
location = json_body[:data]
|
74
|
+
end
|
75
|
+
expect_valid_data location
|
76
|
+
found = location.detect do |item|
|
58
77
|
jsonapi_match? find_me, item, opts[:type]
|
59
78
|
end
|
60
79
|
expect(found).to be_truthy
|
61
80
|
end
|
81
|
+
alias_method :expect_item_in_list, :expect_record
|
62
82
|
|
63
|
-
def
|
83
|
+
def expect_record_absent dont_find_me, opts = {}
|
64
84
|
opts[:type] ||= jsonapi_type dont_find_me
|
65
|
-
|
66
|
-
|
85
|
+
if opts[:included]
|
86
|
+
location = json_body[:included]
|
87
|
+
else
|
88
|
+
location = json_body[:data]
|
89
|
+
end
|
90
|
+
expect_valid_data location
|
91
|
+
location.each do |item|
|
67
92
|
expect(jsonapi_match?(dont_find_me, item, opts[:type])).to be_falsey
|
68
93
|
end
|
69
94
|
end
|
70
|
-
alias_method :
|
71
|
-
|
72
|
-
alias_method :expect_item_to_not_be_in_list,
|
73
|
-
:expect_item_not_in_list
|
95
|
+
alias_method :expect_item_not_in_list, :expect_record_absent
|
96
|
+
alias_method :expect_item_not_to_be_in_list, :expect_record_absent
|
97
|
+
alias_method :expect_item_to_not_be_in_list, :expect_record_absent
|
74
98
|
|
75
|
-
|
76
|
-
|
77
|
-
def find_record_in_response record, opts = {}
|
99
|
+
def find_record record, opts = {}
|
78
100
|
opts[:type] ||= jsonapi_type(record)
|
79
|
-
|
80
|
-
|
101
|
+
if opts[:included]
|
102
|
+
location = json_body[:included]
|
103
|
+
else
|
104
|
+
location = json_body[:data]
|
105
|
+
end
|
106
|
+
expect_valid_data location
|
107
|
+
location.select do |item|
|
108
|
+
jsonapi_match? record, item, opts[:type]
|
81
109
|
end.first
|
82
110
|
end
|
83
111
|
|
112
|
+
def expect_valid_data location = nil
|
113
|
+
location ||= json_body[:data]
|
114
|
+
expect(location).to_not be_nil
|
115
|
+
expect(location).to_not be_empty
|
116
|
+
end
|
117
|
+
|
84
118
|
private
|
85
119
|
|
120
|
+
def is_array_response?
|
121
|
+
json_body[:data].is_a? Array
|
122
|
+
end
|
123
|
+
|
86
124
|
def expect_linkage_data location, relationship_data, included
|
87
125
|
begin
|
88
126
|
expect_json location, relationship_data
|
@@ -93,8 +131,16 @@ module JsonapiExpectations
|
|
93
131
|
expect_json "included.?", relationship_data if included
|
94
132
|
end
|
95
133
|
|
134
|
+
def dasherize_array array
|
135
|
+
array.map { |item| dasherize item }
|
136
|
+
end
|
137
|
+
|
96
138
|
def dasherize_keys hash
|
97
|
-
hash.deep_transform_keys { |key| key
|
139
|
+
hash.deep_transform_keys { |key| dasherize key }
|
140
|
+
end
|
141
|
+
|
142
|
+
def dasherize thing
|
143
|
+
thing.to_s.tr('_', '-').to_sym
|
98
144
|
end
|
99
145
|
|
100
146
|
def jsonapi_match? model, data, type
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross-Hunter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: airborne
|