2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Projects::RefsController do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2015-04-26 12:48:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #logs_tree' do
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:path) { 'foo/bar/baz.html' }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def default_get(format = :html)
|
2015-09-11 14:41:01 +05:30
|
|
|
get :logs_tree,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: 'master',
|
2020-05-24 23:13:21 +05:30
|
|
|
path: path
|
2019-02-15 15:39:39 +05:30
|
|
|
},
|
2015-09-11 14:41:01 +05:30
|
|
|
format: format
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def xhr_get(format = :html, params = {})
|
2019-02-15 15:39:39 +05:30
|
|
|
get :logs_tree, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: 'master',
|
2020-05-24 23:13:21 +05:30
|
|
|
path: path,
|
2019-02-15 15:39:39 +05:30
|
|
|
format: format
|
2020-05-24 23:13:21 +05:30
|
|
|
}.merge(params), xhr: true
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'never throws MissingTemplate' do
|
|
|
|
expect { default_get }.not_to raise_error
|
2018-03-17 18:26:18 +05:30
|
|
|
expect { xhr_get(:json) }.not_to raise_error
|
2015-04-26 12:48:37 +05:30
|
|
|
expect { xhr_get }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'renders 404 for HTML requests' do
|
2015-04-26 12:48:37 +05:30
|
|
|
xhr_get
|
|
|
|
|
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when ref is incorrect' do
|
|
|
|
it 'returns 404 page' do
|
|
|
|
xhr_get(:json, id: '.')
|
|
|
|
|
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when offset has an invalid format' do
|
|
|
|
it 'renders JSON' do
|
|
|
|
xhr_get(:json, offset: { wrong: :format })
|
|
|
|
|
|
|
|
expect(response).to be_successful
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when json is requested' do
|
|
|
|
it 'renders JSON' do
|
|
|
|
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
xhr_get(:json)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(response).to be_successful
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|