Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,66 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: password
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
fail-fast: false
matrix:
ruby:
- 2.6.6
- 2.7.2
- 2.6
- 2.7
- '3.0'
- 3.1
- 3.2
rails:
- 6.1.1
- 6.0.3.4
- 5.2.4.4
- 7.0.4
- 6.1.7
- 6.0.6
- 5.2.8.1
- 5.1.7
- 5.0.7.2
- 4.2.11
database_url:
- postgresql://postgres:password@localhost:5432/test
- sqlite3:test_db
exclude:
- ruby: 2.7.2
rails: 5.0.7.2
- ruby: 2.7.2
rails: 4.2.11
- ruby: 2.6.6
rails: 4.2.11
- ruby: 3.2
rails: 6.0.6
- ruby: 3.2
rails: 5.2.8.1
- ruby: 3.2
rails: 5.1.7
- ruby: 3.1
rails: 6.0.6
- ruby: 3.1
rails: 5.2.8.1
- ruby: 3.1
rails: 5.1.7
- ruby: '3.0'
rails: 6.0.6
- ruby: '3.0'
rails: 5.2.8.1
- ruby: '3.0'
rails: 5.1.7
- ruby: 2.6
rails: 7.0.4
- database_url: postgresql://postgres:password@localhost:5432/test
rails: 5.1.7
env:
RAILS_VERSION: ${{ matrix.rails }}
name: Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
name: Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }} DB ${{ matrix.database_url }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi/cached_resource_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def to_cache_value
end

def to_real_resource
rs = Resource.resource_for(self.type).find_by_keys([self.id], {context: self.context})
rs = Resource.resource_for(self.type).find_by_keys([self.id], context: self.context)
return rs.try(:first)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/jsonapi/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module JSONAPI
class Error
attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status, :meta

def initialize(options = {})
def initialize(**options)
@title = options[:title]
@detail = options[:detail]
@id = options[:id]
Expand All @@ -28,7 +28,7 @@ def to_hash

class Warning
attr_accessor :title, :detail, :code
def initialize(options = {})
def initialize(**options)
@title = options[:title]
@detail = options[:detail]
@code = if JSONAPI.configuration.use_text_errors
Expand Down
90 changes: 45 additions & 45 deletions lib/jsonapi/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Exceptions
class Error < RuntimeError
attr :error_object_overrides

def initialize(error_object_overrides = {})
def initialize(**error_object_overrides)
@error_object_overrides = error_object_overrides
end

def create_error_object(error_defaults)
JSONAPI::Error.new(error_defaults.merge(error_object_overrides))
def create_error_object(**error_defaults)
JSONAPI::Error.new(**error_defaults.merge(error_object_overrides))
end

def errors
Expand All @@ -21,9 +21,9 @@ def errors
class InternalServerError < Error
attr_accessor :exception

def initialize(exception, error_object_overrides = {})
def initialize(exception, **error_object_overrides)
@exception = exception
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -46,9 +46,9 @@ def errors
class InvalidResource < Error
attr_accessor :resource

def initialize(resource, error_object_overrides = {})
def initialize(resource, **error_object_overrides)
@resource = resource
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -64,9 +64,9 @@ def errors
class RecordNotFound < Error
attr_accessor :id

def initialize(id, error_object_overrides = {})
def initialize(id, **error_object_overrides)
@id = id
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -82,9 +82,9 @@ def errors
class UnsupportedMediaTypeError < Error
attr_accessor :media_type

def initialize(media_type, error_object_overrides = {})
def initialize(media_type, **error_object_overrides)
@media_type = media_type
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -102,9 +102,9 @@ def errors
class NotAcceptableError < Error
attr_accessor :media_type

def initialize(media_type, error_object_overrides = {})
def initialize(media_type, **error_object_overrides)
@media_type = media_type
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -123,9 +123,9 @@ def errors
class HasManyRelationExists < Error
attr_accessor :id

def initialize(id, error_object_overrides = {})
def initialize(id, **error_object_overrides)
@id = id
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand Down Expand Up @@ -179,9 +179,9 @@ def errors
class InvalidFiltersSyntax < Error
attr_accessor :filters

def initialize(filters, error_object_overrides = {})
def initialize(filters, **error_object_overrides)
@filters = filters
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -198,9 +198,9 @@ def errors
class FilterNotAllowed < Error
attr_accessor :filter

def initialize(filter, error_object_overrides = {})
def initialize(filter, **error_object_overrides)
@filter = filter
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -216,10 +216,10 @@ def errors
class InvalidFilterValue < Error
attr_accessor :filter, :value

def initialize(filter, value, error_object_overrides = {})
def initialize(filter, value, **error_object_overrides)
@filter = filter
@value = value
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -236,10 +236,10 @@ def errors
class InvalidFieldValue < Error
attr_accessor :field, :value

def initialize(field, value, error_object_overrides = {})
def initialize(field, value, **error_object_overrides)
@field = field
@value = value
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand Down Expand Up @@ -289,9 +289,9 @@ def errors
class TypeMismatch < Error
attr_accessor :type

def initialize(type, error_object_overrides = {})
def initialize(type, **error_object_overrides)
@type = type
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -307,10 +307,10 @@ def errors
class InvalidField < Error
attr_accessor :field, :type

def initialize(type, field, error_object_overrides = {})
def initialize(type, field, **error_object_overrides)
@field = field
@type = type
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -327,10 +327,10 @@ def errors
class InvalidInclude < Error
attr_accessor :relationship, :resource

def initialize(resource, relationship, error_object_overrides = {})
def initialize(resource, relationship, **error_object_overrides)
@resource = resource
@relationship = relationship
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -347,10 +347,10 @@ def errors
class InvalidSortCriteria < Error
attr_accessor :sort_criteria, :resource

def initialize(resource, sort_criteria, error_object_overrides = {})
def initialize(resource, sort_criteria, **error_object_overrides)
@resource = resource
@sort_criteria = sort_criteria
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -367,9 +367,9 @@ def errors
class ParameterNotAllowed < Error
attr_accessor :param

def initialize(param, error_object_overrides = {})
def initialize(param, **error_object_overrides)
@param = param
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -385,9 +385,9 @@ def errors
class ParameterMissing < Error
attr_accessor :param

def initialize(param, error_object_overrides = {})
def initialize(param, **error_object_overrides)
@param = param
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -403,9 +403,9 @@ def errors
class KeyNotIncludedInURL < Error
attr_accessor :key

def initialize(key, error_object_overrides = {})
def initialize(key, **error_object_overrides)
@key = key
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand Down Expand Up @@ -433,9 +433,9 @@ def errors
class RecordLocked < Error
attr_accessor :message

def initialize(message, error_object_overrides = {})
def initialize(message, **error_object_overrides)
@message = message
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -450,13 +450,13 @@ def errors
class ValidationErrors < Error
attr_reader :error_messages, :error_metadata, :resource_relationships, :resource_class

def initialize(resource, error_object_overrides = {})
def initialize(resource, **error_object_overrides)
@error_messages = resource.model_error_messages
@error_metadata = resource.validation_error_metadata
@resource_class = resource.class
@resource_relationships = resource.class._relationships.keys
@key_formatter = JSONAPI.configuration.key_formatter
super(error_object_overrides)
super(**error_object_overrides)
end

def format_key(key)
Expand Down Expand Up @@ -529,9 +529,9 @@ def errors
class PageParametersNotAllowed < Error
attr_accessor :params

def initialize(params, error_object_overrides = {})
def initialize(params, **error_object_overrides)
@params = params
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand All @@ -550,10 +550,10 @@ def errors
class InvalidPageValue < Error
attr_accessor :page, :value

def initialize(page, value, error_object_overrides = {})
def initialize(page, value, **error_object_overrides)
@page = page
@value = value
super(error_object_overrides)
super(**error_object_overrides)
end

def errors
Expand Down
Loading