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
1 change: 0 additions & 1 deletion lib/jsonapi/acts_as_resource_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'csv'
require_relative 'compatibility_helper'
module JSONAPI
module ActsAsResourceController
Expand Down
4 changes: 2 additions & 2 deletions lib/jsonapi/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def errors

def json_api_error(attr_key, message)
create_error_object(code: JSONAPI::VALIDATION_ERROR,
status: :unprocessable_entity,
status: :unprocessable_content,
title: message,
detail: detail(attr_key, message),
source: { pointer: pointer(attr_key) },
Expand Down Expand Up @@ -532,7 +532,7 @@ def general_error?(attr_key)
class SaveFailed < Error
def errors
[create_error_object(code: JSONAPI::SAVE_FAILED,
status: :unprocessable_entity,
status: :unprocessable_content,
title: I18n.translate('jsonapi-resources.exceptions.save_failed.title',
default: 'Save failed or was cancelled'),
detail: I18n.translate('jsonapi-resources.exceptions.save_failed.detail',
Expand Down
18 changes: 9 additions & 9 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def test_create_link_to_missing_object
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content
# TODO: check if this validation is working
assert_match /author - can't be blank/, response.body
assert_nil response.location
Expand Down Expand Up @@ -864,7 +864,7 @@ def test_create_with_invalid_data
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content

assert_equal "/data/relationships/author", json_response['errors'][0]['source']['pointer']
assert_equal "can't be blank", json_response['errors'][0]['title']
Expand Down Expand Up @@ -2019,7 +2019,7 @@ def test_delete_with_validation_error_base

assert_equal "can't destroy me", json_response['errors'][0]['title']
assert_equal "/data", json_response['errors'][0]['source']['pointer']
assert_response :unprocessable_entity
assert_response :unprocessable_content
end

def test_delete_with_validation_error_attr
Expand All @@ -2028,7 +2028,7 @@ def test_delete_with_validation_error_attr

assert_equal "is locked", json_response['errors'][0]['title']
assert_equal "/data/attributes/title", json_response['errors'][0]['source']['pointer']
assert_response :unprocessable_entity
assert_response :unprocessable_content
end

def test_delete_single
Expand Down Expand Up @@ -2631,7 +2631,7 @@ def test_create_validations_missing_attribute
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content
assert_equal 2, json_response['errors'].size
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][0]['code']
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][1]['code']
Expand All @@ -2653,7 +2653,7 @@ def test_update_validations_missing_attribute
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content
assert_equal 1, json_response['errors'].size
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][0]['code']
assert_match /name - can't be blank/, response.body
Expand Down Expand Up @@ -3183,7 +3183,7 @@ def test_create_with_invalid_data
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content

assert_equal "/data/attributes/spouse-name", json_response['errors'][0]['source']['pointer']
assert_equal "can't be blank", json_response['errors'][0]['title']
Expand Down Expand Up @@ -3779,7 +3779,7 @@ def test_save_model_callbacks_fail
}
}

assert_response :unprocessable_entity
assert_response :unprocessable_content
assert_match /Save failed or was cancelled/, json_response['errors'][0]['detail']
end
end
Expand Down Expand Up @@ -4077,7 +4077,7 @@ def test_delete_with_validation_error_base_on_resource

assert_equal "can't destroy me", json_response['errors'][0]['title']
assert_equal "/data/attributes/base", json_response['errors'][0]['source']['pointer']
assert_response :unprocessable_entity
assert_response :unprocessable_content
end
end

Expand Down