-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathpayload.rb.erb
More file actions
39 lines (39 loc) · 1.16 KB
/
payload.rb.erb
File metadata and controls
39 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%- unless omit_comments? -%>
# Register a payload to validate against.
# Add expected attributes within this block, e.g.:
#
# key(:name)
#
# Optionally validate the type as well:
#
# key(:name, String)
#
# This will:
#
# * Compare record.name == json['name']
# * Ensure no extra keys are in the json payload
# * Ensure no values are nil (unless allow_nil: true is passed)
# * Ensures json['name'] is a string
#
# If you have custom serialization logic and want to compare against
# something other than "record.name", pass a block:
#
# key(:name) { |record| record.name.upcase }
#
# Or, if this is a one-off for a particular spec, do that customization at
# runtime:
#
# assert_payload(:person, person_record, json_item) do
# key(:name) { 'Homer Simpson' }
# end
#
# For more information, see https://jsonapi-suite.github.io/jsonapi_spec_helpers/
<%- end -%>
JsonapiSpecHelpers::Payload.register(:<%= singular_table_name %>) do
<%- attributes.each do |a| -%>
<%- type = a.type == :boolean ? [TrueClass, FalseClass] : a.type.to_s.classify -%>
<%- type = String if a.type == :text -%>
<%- type = Float if a.type == :decimal -%>
key(:<%= a.name %>, <%= type %>)
<%- end -%>
end