jsonapi_spec_helpers 0.4.7 → 0.4.8
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149949daac0fbc6ab318cb6239580cf2fa46768f
|
4
|
+
data.tar.gz: 900d14a392bddbfae556c975fa5fe10c83412d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc23866fbcdc9d257c03b38b3eb4a4ec69e4abb6082ee300869426648c03aa8f212b5fdd7fcd010cc5ea1a0a909c1822066d0216deb45a0bb1ee93f124cc4fe
|
7
|
+
data.tar.gz: b751dec6c0f13493b6a9926ef3f5053ccb65ca821d5ae713b8610c432b8c6cc30732179596873b163749682f721b979521f038d85e2ef5df29b89e13cb86c5f7
|
data/lib/jsonapi_spec_helpers.rb
CHANGED
@@ -3,6 +3,7 @@ require 'jsonapi_spec_helpers/version'
|
|
3
3
|
require 'jsonapi_spec_helpers/helpers'
|
4
4
|
require 'jsonapi_spec_helpers/payload'
|
5
5
|
require 'jsonapi_spec_helpers/payload_sanitizer'
|
6
|
+
require 'jsonapi_spec_helpers/errors'
|
6
7
|
|
7
8
|
module JsonapiSpecHelpers
|
8
9
|
def self.included(klass)
|
@@ -33,7 +34,8 @@ module JsonapiSpecHelpers
|
|
33
34
|
prc = options[:proc]
|
34
35
|
if (expect(json).to have_payload_key(attribute, options[:allow_nil])) == true
|
35
36
|
unless options[:allow_nil]
|
36
|
-
|
37
|
+
output = instance_exec(record, &prc)
|
38
|
+
expect(json[attribute.to_s]).to match_payload(attribute, output)
|
37
39
|
|
38
40
|
if options[:type]
|
39
41
|
expect(json[attribute.to_s]).to match_type(attribute, options[:type])
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module JsonapiSpecHelpers
|
2
|
+
module Errors
|
3
|
+
class Base < StandardError; end
|
4
|
+
class IncludedOutOfBounds < Base
|
5
|
+
def initialize(type, index, array)
|
6
|
+
@type = type; @index = index; @array = array
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
"You attempted to get an item at index #{@index} of the type '#{@type}' " \
|
11
|
+
"from the included property of your JSON payload. But it contained " \
|
12
|
+
"#{@array.length} '#{@type}'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -39,7 +39,11 @@ module JsonapiSpecHelpers
|
|
39
39
|
indices = (0...included.length).to_a if indices.empty?
|
40
40
|
includes = []
|
41
41
|
indices.each do |index|
|
42
|
-
|
42
|
+
single_included = included.at(index)
|
43
|
+
if single_included.nil?
|
44
|
+
raise Errors::IncludedOutOfBounds.new(type, index, included)
|
45
|
+
end
|
46
|
+
includes << json_item(from: single_included)
|
43
47
|
end
|
44
48
|
includes
|
45
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_spec_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/setup
|
114
114
|
- jsonapi_spec_helpers.gemspec
|
115
115
|
- lib/jsonapi_spec_helpers.rb
|
116
|
+
- lib/jsonapi_spec_helpers/errors.rb
|
116
117
|
- lib/jsonapi_spec_helpers/helpers.rb
|
117
118
|
- lib/jsonapi_spec_helpers/matchers.rb
|
118
119
|
- lib/jsonapi_spec_helpers/payload.rb
|