test/controllers/controller_test.rb in jsonapi-resources-0.7.0 vs test/controllers/controller_test.rb in jsonapi-resources-0.7.1.beta1
- old
+ new
@@ -483,11 +483,11 @@
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body']
assert_equal 1, json_response['meta']["warnings"].count
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
assert_equal "asdfg is not allowed.", json_response['meta']["warnings"][0]["detail"]
- assert_equal 105, json_response['meta']["warnings"][0]["code"]
+ assert_equal '105', json_response['meta']["warnings"][0]["code"]
ensure
JSONAPI.configuration.raise_if_parameters_not_allowed = true
end
def test_create_with_invalid_data
@@ -693,11 +693,11 @@
assert_equal 1, json_response['meta']["warnings"].count
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
assert_equal "subject is not allowed.", json_response['meta']["warnings"][0]["detail"]
- assert_equal 105, json_response['meta']["warnings"][0]["code"]
+ assert_equal '105', json_response['meta']["warnings"][0]["code"]
ensure
JSONAPI.configuration.raise_if_parameters_not_allowed = true
end
def test_create_with_links_to_many_type_ids
@@ -864,11 +864,11 @@
assert_equal 1, json_response['meta']["warnings"].count
assert_equal "Param not allowed", json_response['meta']["warnings"][0]["title"]
assert_equal "subject is not allowed.", json_response['meta']["warnings"][0]["detail"]
- assert_equal 105, json_response['meta']["warnings"][0]["code"]
+ assert_equal '105', json_response['meta']["warnings"][0]["code"]
ensure
JSONAPI.configuration.raise_if_parameters_not_allowed = true
end
def test_update_remove_links
@@ -1651,10 +1651,18 @@
}
assert_response :bad_request
end
+ def test_delete_with_validation_error
+ post = Post.create!(title: "can't destroy me", author: Person.first)
+ delete :destroy, { id: post.id }
+
+ assert_equal "can't destroy me", json_response['errors'][0]['title']
+ assert_response :unprocessable_entity
+ end
+
def test_delete_single
initial_count = Post.count
delete :destroy, {id: '4'}
assert_response :no_content
assert_equal initial_count - 1, Post.count
@@ -3271,12 +3279,34 @@
assert_equal 'customers', json_response['data'][0]['type']
end
end
class Api::V7::CategoriesControllerTest < ActionController::TestCase
- def test_uncaught_error_in_controller
+ def test_uncaught_error_in_controller_translated_to_internal_server_error
get :show, {id: '1'}
assert_response 500
assert_match /Internal Server Error/, json_response['errors'][0]['detail']
end
-end
\ No newline at end of file
+
+ def test_not_whitelisted_error_in_controller
+ original_config = JSONAPI.configuration.dup
+ JSONAPI.configuration.operations_processor = :error_raising
+ JSONAPI.configuration.exception_class_whitelist = []
+ get :show, {id: '1'}
+ assert_response 500
+ assert_match /Internal Server Error/, json_response['errors'][0]['detail']
+ ensure
+ JSONAPI.configuration = original_config
+ end
+
+ def test_whitelisted_error_in_controller
+ original_config = JSONAPI.configuration.dup
+ JSONAPI.configuration.operations_processor = :error_raising
+ JSONAPI.configuration.exception_class_whitelist = [PostsController::SubSpecialError]
+ assert_raises PostsController::SubSpecialError do
+ get :show, {id: '1'}
+ end
+ ensure
+ JSONAPI.configuration = original_config
+ end
+end