rails-template/rspec/helpers/jsonapi_wrapper_for_factories.rb
2022-12-19 17:27:35 +03:00

25 lines
679 B
Ruby

module Rspec
module Helpers
def jsonapi_wrapper_for_factories_configurations
file 'spec/helpers/swagger_errors.rb', <<~CODE
module Helpers
module JsonapiWrapperForFactories
def wrap_factory_with_jsonapi(factory)
attributes = factory.instance_of?(Hash) ? factory : factory.attributes
{
data: {
id: factory.try(:id) || '',
attributes: attributes.deep_transform_keys { |key| key&.to_s&.camelize :lower }
},
jsonapi: {
version: '1.0'
}
}
end
end
end
CODE
end
end
end