2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-06 23:02:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::RefsController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-04-06 23:02:06 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2015-04-06 23:02:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #logs_tree' do
|
2020-04-23 14:09:46 -04:00
|
|
|
let(:path) { 'foo/bar/baz.html' }
|
|
|
|
|
2015-04-06 23:02:06 -04:00
|
|
|
def default_get(format = :html)
|
2015-06-23 01:24:39 -04:00
|
|
|
get :logs_tree,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: 'master',
|
2020-04-23 14:09:46 -04:00
|
|
|
path: path
|
2018-12-17 17:52:17 -05:00
|
|
|
},
|
2015-06-23 01:24:39 -04:00
|
|
|
format: format
|
2015-04-06 23:02:06 -04:00
|
|
|
end
|
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
def xhr_get(format = :html, params = {})
|
2018-12-19 16:57:41 -05:00
|
|
|
get :logs_tree, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: 'master',
|
2020-04-23 14:09:46 -04:00
|
|
|
path: path,
|
2018-12-19 16:57:41 -05:00
|
|
|
format: format
|
2020-04-23 14:09:46 -04:00
|
|
|
}.merge(params), xhr: true
|
2015-04-06 23:02:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'never throws MissingTemplate' do
|
|
|
|
expect { default_get }.not_to raise_error
|
2017-11-01 12:48:47 -04:00
|
|
|
expect { xhr_get(:json) }.not_to raise_error
|
2015-04-06 23:02:06 -04:00
|
|
|
expect { xhr_get }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
2020-06-29 17:09:07 -04:00
|
|
|
it 'renders 404 for HTML requests' do
|
2015-04-06 23:02:06 -04:00
|
|
|
xhr_get
|
|
|
|
|
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
context 'when json is requested' do
|
|
|
|
it 'renders JSON' do
|
|
|
|
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
|
2019-04-06 08:04:27 -04:00
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
xhr_get(:json)
|
2017-11-01 12:48:47 -04:00
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
expect(response).to be_successful
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
end
|
2017-11-01 12:48:47 -04:00
|
|
|
end
|
2015-04-06 23:02:06 -04:00
|
|
|
end
|
|
|
|
end
|