Skip to content
Snippets Groups Projects
Commit b7e98620 authored by Felipe Artur's avatar Felipe Artur
Browse files

Fix API responses when dealing with txt files

parent fe09c25d
No related branches found
No related tags found
No related merge requests found
---
title: Fix API responses when dealing with txt files
merge_request:
author:
module API
class Files < Grape::API
# Prevents returning plain/text responses for files with .txt extension
after_validation { content_type "application/json" }
helpers do
def commit_params(attrs)
{
Loading
Loading
Loading
Loading
@@ -33,6 +33,15 @@ describe API::Files do
expect(Base64.decode64(json_response['content']).lines.first).to eq("require 'fileutils'\n")
end
 
it 'returns json when file has txt extension' do
file_path = "bar%2Fbranch-test.txt"
get api(route(file_path), current_user), params
expect(response).to have_http_status(200)
expect(response.content_type).to eq('application/json')
end
it 'returns file by commit sha' do
# This file is deleted on HEAD
file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
Loading
Loading
@@ -220,6 +229,7 @@ describe API::Files do
post api(route("new_file_with_author%2Etxt"), user), valid_params
 
expect(response).to have_http_status(201)
expect(response.content_type).to eq('application/json')
last_commit = project.repository.commit.raw
expect(last_commit.author_email).to eq(author_email)
expect(last_commit.author_name).to eq(author_name)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment