jsonapi_spec_helpers 0.4.2 → 0.4.3

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: 611a13d2e04821ba85f2fdd8a455c2c44b213eed
4
- data.tar.gz: c37b252423955ad9bcc5dee7de06d2cf80c716fb
3
+ metadata.gz: 4c295655bfaecaa565099cd1cf389e2905062477
4
+ data.tar.gz: 9bbe76f2dd612f58d8c2c1c0e59bb0291eee8cd7
5
5
  SHA512:
6
- metadata.gz: 47611f5448c9f8c0567bc23544bd31118e353860e619f1190b576d9098eefbd600216dd5a52c4dbdc303f96ccc461a88834dda91348976a05f9a7433758825d6
7
- data.tar.gz: 611a87c2a43e0251ffc35c1dfc5c6b1f70e1f3a00c6e54cdd519353f4c1e6be45255f482a3d1e7959b4ba5958a2ccf438a8edecc78755f70c3f16c3fa8d4cc9d
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
@@ -1,3 +1,3 @@
1
1
  module JsonapiSpecHelpers
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -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
- Dir[Rails.root.join('spec/payloads/**/*.rb')].each { |f| require f }
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.2
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-18 00:00:00.000000000 Z
11
+ date: 2017-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry