Sha256: 6961744f3a6a2362166d1f4abd37e6fff2e75366091b6da13f8e2c8a4cac9ee9
Contents?: true
Size: 1.81 KB
Versions: 20
Compression:
Stored size: 1.81 KB
Contents
require File.expand_path('../../../test_helper', __FILE__) require 'jsonapi-resources' require 'json' class ResponseDocumentTest < ActionDispatch::IntegrationTest def setup JSONAPI.configuration.json_key_format = :dasherized_key JSONAPI.configuration.route_format = :dasherized_route end def create_response_document(operation_results, resource_klass) JSONAPI::ResponseDocument.new( operation_results, { primary_resource_klass: resource_klass } ) end def test_response_document operations = [ JSONAPI::CreateResourceOperation.new(PlanetResource, data: {attributes: {'name' => 'Earth 2.0'}}), JSONAPI::CreateResourceOperation.new(PlanetResource, data: {attributes: {'name' => 'Vulcan'}}) ] request = JSONAPI::Request.new request.operations = operations op = BasicOperationsProcessor.new() operation_results = op.process(request) response_doc = create_response_document(operation_results, PlanetResource) assert_equal :created, response_doc.status contents = response_doc.contents assert contents.is_a?(Hash) assert contents[:data].is_a?(Array) assert_equal 2, contents[:data].size end def test_response_document_multiple_find operations = [ JSONAPI::FindOperation.new(PostResource, filters: {id: '1'}), JSONAPI::FindOperation.new(PostResource, filters: {id: '2'}) ] request = JSONAPI::Request.new request.operations = operations op = ActiveRecordOperationsProcessor.new() operation_results = op.process(request) response_doc = create_response_document(operation_results, PostResource) assert_equal :ok, response_doc.status contents = response_doc.contents assert contents.is_a?(Hash) assert contents[:data].is_a?(Array) assert_equal 2, contents[:data].size end end
Version data entries
20 entries across 20 versions & 1 rubygems