test/controllers/controller_test.rb in jsonapi-resources-0.3.1 vs test/controllers/controller_test.rb in jsonapi-resources-0.3.2

- old
+ new

@@ -2,10 +2,14 @@ def set_content_type_header! @request.headers['Content-Type'] = JSONAPI::MEDIA_TYPE end +class ConfigControllerTest < ActionController::TestCase + +end + class PostsControllerTest < ActionController::TestCase def test_index get :index assert_response :success assert json_response['data'].is_a?(Array) @@ -1386,10 +1390,18 @@ class ExpenseEntriesControllerTest < ActionController::TestCase def setup JSONAPI.configuration.json_key_format = :camelized_key end + def test_text_error + JSONAPI.configuration.use_text_errors = true + get :index, {sort: 'not_in_record'} + assert_response 400 + assert_equal 'INVALID_SORT_FORMAT', json_response['errors'][0]['code'] + JSONAPI.configuration.use_text_errors = false + end + def test_expense_entries_index get :index assert_response :success assert json_response['data'].is_a?(Array) assert_equal 2, json_response['data'].size @@ -1634,10 +1646,32 @@ } assert_response :success end + def test_update_link_with_dasherized_type + JSONAPI.configuration.json_key_format = :dasherized_key + set_content_type_header! + put :update, + { + id: 3, + data: { + id: '3', + type: 'people', + links: { + 'hair-cut' => { + linkage: { + type: 'hair-cuts', + id: '1' + } + } + } + } + } + assert_response :success + end + def test_create_validations_missing_attribute set_content_type_header! post :create, { data: { @@ -1691,40 +1725,49 @@ assert_equal json_response['data'][0]['id'], '1' assert_equal json_response['data'][0]['name'], 'Joe Author' end def test_get_related_resource + JSONAPI.configuration.json_key_format = :dasherized_key + JSONAPI.configuration.route_format = :underscored_key get :get_related_resource, {post_id: '2', association: 'author', :source=>'posts'} assert_response :success - assert_hash_equals json_response, - { - data: { - id: '1', - type: 'people', - name: 'Joe Author', - email: 'joe@xyz.fake', - dateJoined: '2013-08-07 16:25:00 -0400', - links: { - self: 'http://test.host/people/1', - comments: { - self: 'http://test.host/people/1/links/comments', - related: 'http://test.host/people/1/comments' - }, - posts: { - self: 'http://test.host/people/1/links/posts', - related: 'http://test.host/people/1/posts' - }, - preferences: { - self: 'http://test.host/people/1/links/preferences', - related: 'http://test.host/people/1/preferences', - linkage: { - type: 'preferences', - id: '1' - } - } - } - } - } + assert_hash_equals( + { + data: { + id: '1', + type: 'people', + name: 'Joe Author', + email: 'joe@xyz.fake', + "date-joined" => '2013-08-07 16:25:00 -0400', + links: { + self: 'http://test.host/people/1', + comments: { + self: 'http://test.host/people/1/links/comments', + related: 'http://test.host/people/1/comments' + }, + posts: { + self: 'http://test.host/people/1/links/posts', + related: 'http://test.host/people/1/posts' + }, + preferences: { + self: 'http://test.host/people/1/links/preferences', + related: 'http://test.host/people/1/preferences', + linkage: { + type: 'preferences', + id: '1' + } + }, + "hair-cut" => { + "self" => "http://test.host/people/1/links/hair_cut", + "related" => "http://test.host/people/1/hair_cut", + "linkage" => nil + } + } + } + }, + json_response + ) end def test_get_related_resource_nil get :get_related_resource, {post_id: '17', association: 'author', :source=>'posts'} assert_response :success