Sha256: 30b39b09c4e321b20756164d99266566b3aecebe26bdf4e75b61334b102032d1

Contents?: true

Size: 1.15 KB

Versions: 25

Compression:

Stored size: 1.15 KB

Contents

<%- 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(:<%= file_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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
jsonapi_compliable-0.11.34 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.33 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.32 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.31 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.30 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.29 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.28 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.27 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.26 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.25 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.24 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.23 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.22 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.21 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.20 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.19 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.18 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.17 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.16 lib/generators/jsonapi/templates/payload.rb.erb
jsonapi_compliable-0.11.15 lib/generators/jsonapi/templates/payload.rb.erb