test/controllers/controller_test.rb in jsonapi-resources-0.0.11 vs test/controllers/controller_test.rb in jsonapi-resources-0.0.12

- old
+ new

@@ -283,11 +283,11 @@ author: 304567 } } } - assert_response :bad_request + assert_response :unprocessable_entity # Todo: check if this validation is working assert_match /author - can't be blank/, response.body end def test_create_extra_param @@ -305,10 +305,33 @@ assert_response :bad_request assert_match /asdfg is not allowed/, response.body end + def test_create_with_invalid_data + post :create, + { + posts: { + title: 'JSONAPIResources is the greatest thing...', + body: 'JSONAPIResources is the greatest thing since unsliced bread.', + links: { + author: nil + } + } + } + + assert_response :unprocessable_entity + + assert_equal "/author", json_response['errors'][0]['path'] + assert_equal "can't be blank", json_response['errors'][0]['detail'] + assert_equal "author - can't be blank", json_response['errors'][0]['title'] + + assert_equal "/title", json_response['errors'][1]['path'] + assert_equal "is too long (maximum is 35 characters)", json_response['errors'][1]['detail'] + assert_equal "title - is too long (maximum is 35 characters)", json_response['errors'][1]['title'] + end + def test_create_multiple post :create, { posts: [ { @@ -1196,11 +1219,11 @@ people: { email: 'sj@email.zzz' } } - assert_response :bad_request + assert_response :unprocessable_entity 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'] assert_match /date_joined - can't be blank/, response.body assert_match /name - can't be blank/, response.body @@ -1213,11 +1236,11 @@ people: { name: '' } } - assert_response :bad_request + assert_response :unprocessable_entity 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 end @@ -1347,6 +1370,13 @@ delete :destroy, {id: '3'} assert_response :no_content assert_equal initial_count - 1, $breed_data.breeds.keys.count end +end + +class Api::V2::PreferencesControllerTest < ActionController::TestCase + def test_show_singleton_resource_without_id + get :show + assert_response :success + end end