jsonapi_spec_helpers 0.4.7 → 0.4.8

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
  SHA1:
3
- metadata.gz: 450f850031706134902174b64cd695becc932b61
4
- data.tar.gz: 82ad19e3168d9e3f3cf79f8784e9ef39d3725a41
3
+ metadata.gz: 149949daac0fbc6ab318cb6239580cf2fa46768f
4
+ data.tar.gz: 900d14a392bddbfae556c975fa5fe10c83412d79
5
5
  SHA512:
6
- metadata.gz: 754a76c50defb5b40dfabf0febb43235726bd1988159c1cbeeb5fcbb63f09a855a9846c9039442593432ee1d2f86fd274f3800e9c631c86c39e3652e8265e69b
7
- data.tar.gz: a2d0b4f1f9519fe7bef4996ae5bade8d5c4b5d97021f57ab13c0581c94610d79dd432fcebadd5d7dbea7c0d40371f991bc9e6774e0dfeea5c2b17c02193753e3
6
+ metadata.gz: cdc23866fbcdc9d257c03b38b3eb4a4ec69e4abb6082ee300869426648c03aa8f212b5fdd7fcd010cc5ea1a0a909c1822066d0216deb45a0bb1ee93f124cc4fe
7
+ data.tar.gz: b751dec6c0f13493b6a9926ef3f5053ccb65ca821d5ae713b8610c432b8c6cc30732179596873b163749682f721b979521f038d85e2ef5df29b89e13cb86c5f7
@@ -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
- expect(json[attribute.to_s]).to match_payload(attribute, prc.call(record))
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
- includes << json_item(from: included.at(index))
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
@@ -1,3 +1,3 @@
1
1
  module JsonapiSpecHelpers
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.8"
3
3
  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.7
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-01-29 00:00:00.000000000 Z
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