test/controllers/controller_test.rb in jsonapi-resources-0.5.4 vs test/controllers/controller_test.rb in jsonapi-resources-0.5.5

- old
+ new

@@ -67,10 +67,18 @@ assert_response :success assert_equal 2, json_response['data'].size assert_equal 1, json_response['included'].size end + def test_index_filter_not_allowed + JSONAPI.configuration.allow_filter = false + get :index, {filter: {id: '1'}} + assert_response :bad_request + ensure + JSONAPI.configuration.allow_filter = true + end + def test_index_include_one_level_query_count count_queries do get :index, {include: 'author'} end assert_response :success @@ -237,10 +245,18 @@ assert_response :bad_request assert_match /asdfg is not a valid sort criteria for post/, response.body end + def test_show_single_with_sort_disallowed + JSONAPI.configuration.allow_sort = false + get :index, {sort: 'title,body'} + assert_response :bad_request + ensure + JSONAPI.configuration.allow_sort = true + end + def test_excluded_sort_param get :index, {sort: 'id'} assert_response :bad_request assert_match /id is not a valid sort criteria for post/, response.body @@ -274,10 +290,18 @@ assert matches_array?([{'type' => 'comments', 'id' => '1'}, {'type' => 'comments', 'id' => '2'}], json_response['data']['relationships']['comments']['data']) assert_equal 2, json_response['included'].size end + def test_show_single_with_include_disallowed + JSONAPI.configuration.allow_include = false + get :show, {id: '1', include: 'comments'} + assert_response :bad_request + ensure + JSONAPI.configuration.allow_include = true + end + def test_show_single_with_fields get :show, {id: '1', fields: {posts: 'author'}} assert_response :success assert json_response['data'].is_a?(Hash) assert_nil json_response['data']['attributes'] @@ -394,16 +418,16 @@ } assert_response :unprocessable_entity assert_equal "/data/relationships/author", json_response['errors'][0]['source']['pointer'] - 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 "can't be blank", json_response['errors'][0]['title'] + assert_equal "author - can't be blank", json_response['errors'][0]['detail'] assert_equal "/data/attributes/title", json_response['errors'][1]['source']['pointer'] - 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'] + assert_equal "is too long (maximum is 35 characters)", json_response['errors'][1]['title'] + assert_equal "title - is too long (maximum is 35 characters)", json_response['errors'][1]['detail'] end def test_create_multiple set_content_type_header! post :create, @@ -2210,15 +2234,15 @@ } assert_response :unprocessable_entity assert_equal "/data/attributes/spouse-name", json_response['errors'][0]['source']['pointer'] - assert_equal "can't be blank", json_response['errors'][0]['detail'] - assert_equal "spouse-name - can't be blank", json_response['errors'][0]['title'] + assert_equal "can't be blank", json_response['errors'][0]['title'] + assert_equal "spouse-name - can't be blank", json_response['errors'][0]['detail'] assert_equal "/data/attributes/bio", json_response['errors'][1]['source']['pointer'] - assert_equal "can't be blank", json_response['errors'][1]['detail'] - assert_equal "bio - can't be blank", json_response['errors'][1]['title'] + assert_equal "can't be blank", json_response['errors'][1]['title'] + assert_equal "bio - can't be blank", json_response['errors'][1]['detail'] end end class Api::V2::BooksControllerTest < ActionController::TestCase def setup