jsonapi_spec_helpers 0.4.2 → 0.4.3
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_spec_helpers/payload.rb +21 -3
- data/lib/jsonapi_spec_helpers/version.rb +1 -1
- data/lib/jsonapi_spec_helpers.rb +7 -2
- 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: 4c295655bfaecaa565099cd1cf389e2905062477
|
4
|
+
data.tar.gz: 9bbe76f2dd612f58d8c2c1c0e59bb0291eee8cd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f938afb72bd5f90673ff88753304d3686c224d560daf5301c62f3fd6ddec12f083a5fab7d6f9b6d15fc64d50fa67d8b8c71b5937d82dcd450b5fc45d292515f7
|
7
|
+
data.tar.gz: 83d36ed2cf2e6e2398ff40d17d625413305b8b5c0bc9cc637d690747b3a34f58318393da18422739dbaaefc6db7364b40725c280e5ff557f97032f1ef6fdb36f
|
@@ -5,14 +5,24 @@ module JsonapiSpecHelpers
|
|
5
5
|
end
|
6
6
|
self.registry = {}
|
7
7
|
|
8
|
-
attr_accessor :keys, :no_keys
|
8
|
+
attr_accessor :name, :type, :keys, :no_keys
|
9
9
|
|
10
10
|
def self.register(name, &blk)
|
11
11
|
instance = new
|
12
12
|
instance.instance_eval(&blk)
|
13
|
+
instance.name = name
|
13
14
|
registry[name] = instance
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.by_type(type)
|
18
|
+
found = nil
|
19
|
+
registry.each_pair do |name, payload|
|
20
|
+
found = payload if payload.type == type
|
21
|
+
end
|
22
|
+
raise "Could not find payload for type #{type}" unless found
|
23
|
+
found
|
24
|
+
end
|
25
|
+
|
16
26
|
def fork
|
17
27
|
instance = self.class.new
|
18
28
|
instance.keys = keys.dup
|
@@ -30,6 +40,14 @@ module JsonapiSpecHelpers
|
|
30
40
|
@no_keys << name
|
31
41
|
end
|
32
42
|
|
43
|
+
def type(val = nil)
|
44
|
+
if val
|
45
|
+
@type = val
|
46
|
+
else
|
47
|
+
@type || name.to_s.pluralize.to_sym
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
33
51
|
def key(name, *args, &blk)
|
34
52
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
35
53
|
options[:type] = args.first
|
@@ -41,8 +59,8 @@ module JsonapiSpecHelpers
|
|
41
59
|
end
|
42
60
|
|
43
61
|
def timestamps!
|
44
|
-
@keys[:created_at] = key(:created_at)
|
45
|
-
@keys[:updated_at] = key(:updated_at)
|
62
|
+
@keys[:created_at] = key(:created_at, String)
|
63
|
+
@keys[:updated_at] = key(:updated_at, String)
|
46
64
|
end
|
47
65
|
end
|
48
66
|
end
|
data/lib/jsonapi_spec_helpers.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'jsonapi_spec_helpers/version'
|
3
|
-
require 'jsonapi_spec_helpers/matchers'
|
4
3
|
require 'jsonapi_spec_helpers/helpers'
|
5
4
|
require 'jsonapi_spec_helpers/payload'
|
6
5
|
require 'jsonapi_spec_helpers/payload_sanitizer'
|
7
6
|
|
8
7
|
module JsonapiSpecHelpers
|
9
8
|
def self.included(klass)
|
9
|
+
# don't load RSpec until included
|
10
|
+
require 'jsonapi_spec_helpers/matchers'
|
10
11
|
klass.send(:include, Helpers)
|
11
12
|
if defined?(Rails)
|
12
|
-
|
13
|
+
load_payloads!
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.load_payloads!
|
18
|
+
Dir[Rails.root.join('spec/payloads/**/*.rb')].each { |f| require f }
|
19
|
+
end
|
20
|
+
|
16
21
|
def assert_payload(name, record, json, &blk)
|
17
22
|
unless payload = JsonapiSpecHelpers::Payload.registry[name]
|
18
23
|
raise "No payloads registered for '#{name}'"
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|