Commit 7c6ff2fc authored by Igor Drozdov's avatar Igor Drozdov

Fix 2.7 warnings for api/files_spec

parent b45adad7
...@@ -73,18 +73,20 @@ RSpec.describe API::Files do ...@@ -73,18 +73,20 @@ RSpec.describe API::Files do
describe "HEAD /projects/:id/repository/files/:file_path" do describe "HEAD /projects/:id/repository/files/:file_path" do
shared_examples_for 'repository files' do shared_examples_for 'repository files' do
let(:options) { {} }
it 'returns 400 when file path is invalid' do it 'returns 400 when file path is invalid' do
head api(route(rouge_file_path), current_user), params: params head api(route(rouge_file_path), current_user, **options), params: params
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
end end
it_behaves_like 'when path is absolute' do it_behaves_like 'when path is absolute' do
subject { head api(route(absolute_path), current_user), params: params } subject { head api(route(absolute_path), current_user, **options), params: params }
end end
it 'returns file attributes in headers' do it 'returns file attributes in headers' do
head api(route(file_path), current_user), params: params head api(route(file_path), current_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Gitlab-File-Path']).to eq(CGI.unescape(file_path)) expect(response.headers['X-Gitlab-File-Path']).to eq(CGI.unescape(file_path))
...@@ -98,7 +100,7 @@ RSpec.describe API::Files do ...@@ -98,7 +100,7 @@ RSpec.describe API::Files do
file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"
head api(route(file_path), current_user), params: params head api(route(file_path), current_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Gitlab-File-Name']).to eq('commit.js.coffee') expect(response.headers['X-Gitlab-File-Name']).to eq('commit.js.coffee')
...@@ -107,7 +109,7 @@ RSpec.describe API::Files do ...@@ -107,7 +109,7 @@ RSpec.describe API::Files do
context 'when mandatory params are not given' do context 'when mandatory params are not given' do
it "responds with a 400 status" do it "responds with a 400 status" do
head api(route("any%2Ffile"), current_user) head api(route("any%2Ffile"), current_user, **options)
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
end end
...@@ -117,7 +119,7 @@ RSpec.describe API::Files do ...@@ -117,7 +119,7 @@ RSpec.describe API::Files do
it "responds with a 404 status" do it "responds with a 404 status" do
params[:ref] = 'master' params[:ref] = 'master'
head api(route('app%2Fmodels%2Fapplication%2Erb'), current_user), params: params head api(route('app%2Fmodels%2Fapplication%2Erb'), current_user, **options), params: params
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
...@@ -127,7 +129,7 @@ RSpec.describe API::Files do ...@@ -127,7 +129,7 @@ RSpec.describe API::Files do
include_context 'disabled repository' include_context 'disabled repository'
it "responds with a 403 status" do it "responds with a 403 status" do
head api(route(file_path), current_user), params: params head api(route(file_path), current_user, **options), params: params
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to have_gitlab_http_status(:forbidden)
end end
...@@ -154,8 +156,8 @@ RSpec.describe API::Files do ...@@ -154,8 +156,8 @@ RSpec.describe API::Files do
context 'when PATs are used' do context 'when PATs are used' do
it_behaves_like 'repository files' do it_behaves_like 'repository files' do
let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) } let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) }
let(:current_user) { user } let(:current_user) { nil }
let(:api_user) { { personal_access_token: token } } let(:options) { { personal_access_token: token } }
end end
end end
...@@ -174,21 +176,21 @@ RSpec.describe API::Files do ...@@ -174,21 +176,21 @@ RSpec.describe API::Files do
describe "GET /projects/:id/repository/files/:file_path" do describe "GET /projects/:id/repository/files/:file_path" do
shared_examples_for 'repository files' do shared_examples_for 'repository files' do
let(:api_user) { current_user } let(:options) { {} }
it 'returns 400 for invalid file path' do it 'returns 400 for invalid file path' do
get api(route(rouge_file_path), api_user), params: params get api(route(rouge_file_path), api_user, **options), params: params
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq(invalid_file_message) expect(json_response['error']).to eq(invalid_file_message)
end end
it_behaves_like 'when path is absolute' do it_behaves_like 'when path is absolute' do
subject { get api(route(absolute_path), api_user), params: params } subject { get api(route(absolute_path), api_user, **options), params: params }
end end
it 'returns file attributes as json' do it 'returns file attributes as json' do
get api(route(file_path), api_user), params: params get api(route(file_path), api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['file_path']).to eq(CGI.unescape(file_path)) expect(json_response['file_path']).to eq(CGI.unescape(file_path))
...@@ -201,10 +203,10 @@ RSpec.describe API::Files do ...@@ -201,10 +203,10 @@ RSpec.describe API::Files do
it 'returns json when file has txt extension' do it 'returns json when file has txt extension' do
file_path = "bar%2Fbranch-test.txt" file_path = "bar%2Fbranch-test.txt"
get api(route(file_path), api_user), params: params get api(route(file_path), api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.content_type).to eq('application/json') expect(response.media_type).to eq('application/json')
end end
context 'with filename with pathspec characters' do context 'with filename with pathspec characters' do
...@@ -218,7 +220,7 @@ RSpec.describe API::Files do ...@@ -218,7 +220,7 @@ RSpec.describe API::Files do
it 'returns JSON wth commit SHA' do it 'returns JSON wth commit SHA' do
params[:ref] = 'master' params[:ref] = 'master'
get api(route(file_path), api_user), params: params get api(route(file_path), api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
...@@ -232,7 +234,7 @@ RSpec.describe API::Files do ...@@ -232,7 +234,7 @@ RSpec.describe API::Files do
file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee" file_path = "files%2Fjs%2Fcommit%2Ejs%2Ecoffee"
params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9" params[:ref] = "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"
get api(route(file_path), api_user), params: params get api(route(file_path), api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['file_name']).to eq('commit.js.coffee') expect(json_response['file_name']).to eq('commit.js.coffee')
...@@ -244,7 +246,7 @@ RSpec.describe API::Files do ...@@ -244,7 +246,7 @@ RSpec.describe API::Files do
url = route(file_path) + "/raw" url = route(file_path) + "/raw"
expect(Gitlab::Workhorse).to receive(:send_git_blob) expect(Gitlab::Workhorse).to receive(:send_git_blob)
get api(url, api_user), params: params get api(url, api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
...@@ -253,7 +255,7 @@ RSpec.describe API::Files do ...@@ -253,7 +255,7 @@ RSpec.describe API::Files do
it 'returns blame file info' do it 'returns blame file info' do
url = route(file_path) + '/blame' url = route(file_path) + '/blame'
get api(url, api_user), params: params get api(url, api_user, **options), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
...@@ -261,14 +263,14 @@ RSpec.describe API::Files do ...@@ -261,14 +263,14 @@ RSpec.describe API::Files do
it 'sets inline content disposition by default' do it 'sets inline content disposition by default' do
url = route(file_path) + "/raw" url = route(file_path) + "/raw"
get api(url, api_user), params: params get api(url, api_user, **options), params: params
expect(headers['Content-Disposition']).to eq(%q(inline; filename="popen.rb"; filename*=UTF-8''popen.rb)) expect(headers['Content-Disposition']).to eq(%q(inline; filename="popen.rb"; filename*=UTF-8''popen.rb))
end end
context 'when mandatory params are not given' do context 'when mandatory params are not given' do
it_behaves_like '400 response' do it_behaves_like '400 response' do
let(:request) { get api(route("any%2Ffile"), current_user) } let(:request) { get api(route("any%2Ffile"), current_user, **options) }
end end
end end
...@@ -276,7 +278,7 @@ RSpec.describe API::Files do ...@@ -276,7 +278,7 @@ RSpec.describe API::Files do
let(:params) { { ref: 'master' } } let(:params) { { ref: 'master' } }
it_behaves_like '404 response' do it_behaves_like '404 response' do
let(:request) { get api(route('app%2Fmodels%2Fapplication%2Erb'), api_user), params: params } let(:request) { get api(route('app%2Fmodels%2Fapplication%2Erb'), api_user, **options), params: params }
let(:message) { '404 File Not Found' } let(:message) { '404 File Not Found' }
end end
end end
...@@ -285,7 +287,7 @@ RSpec.describe API::Files do ...@@ -285,7 +287,7 @@ RSpec.describe API::Files do
include_context 'disabled repository' include_context 'disabled repository'
it_behaves_like '403 response' do it_behaves_like '403 response' do
let(:request) { get api(route(file_path), api_user), params: params } let(:request) { get api(route(file_path), api_user, **options), params: params }
end end
end end
end end
...@@ -294,6 +296,7 @@ RSpec.describe API::Files do ...@@ -294,6 +296,7 @@ RSpec.describe API::Files do
it_behaves_like 'repository files' do it_behaves_like 'repository files' do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:current_user) { nil } let(:current_user) { nil }
let(:api_user) { nil }
end end
end end
...@@ -301,7 +304,8 @@ RSpec.describe API::Files do ...@@ -301,7 +304,8 @@ RSpec.describe API::Files do
it_behaves_like 'repository files' do it_behaves_like 'repository files' do
let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) } let(:token) { create(:personal_access_token, scopes: ['read_repository'], user: user) }
let(:current_user) { user } let(:current_user) { user }
let(:api_user) { { personal_access_token: token } } let(:api_user) { nil }
let(:options) { { personal_access_token: token } }
end end
end end
...@@ -315,6 +319,7 @@ RSpec.describe API::Files do ...@@ -315,6 +319,7 @@ RSpec.describe API::Files do
context 'when authenticated', 'as a developer' do context 'when authenticated', 'as a developer' do
it_behaves_like 'repository files' do it_behaves_like 'repository files' do
let(:current_user) { user } let(:current_user) { user }
let(:api_user) { user }
end end
end end
...@@ -687,7 +692,7 @@ RSpec.describe API::Files do ...@@ -687,7 +692,7 @@ RSpec.describe API::Files do
post api(route("new_file_with_author%2Etxt"), user), params: params post api(route("new_file_with_author%2Etxt"), user), params: params
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(response.content_type).to eq('application/json') expect(response.media_type).to eq('application/json')
last_commit = project.repository.commit.raw last_commit = project.repository.commit.raw
expect(last_commit.author_email).to eq(author_email) expect(last_commit.author_email).to eq(author_email)
expect(last_commit.author_name).to eq(author_name) expect(last_commit.author_name).to eq(author_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment