2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-15 12:45:31 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe HelpController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-11-10 00:57:46 -05:00
|
|
|
describe 'GET #index' do
|
2016-12-01 06:07:52 -05:00
|
|
|
context 'with absolute url' do
|
|
|
|
it 'keeps the URL absolute' do
|
|
|
|
stub_readme("[API](/api/README.md)")
|
|
|
|
|
2016-11-10 00:57:46 -05:00
|
|
|
get :index
|
2016-12-01 06:07:52 -05:00
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[API](/api/README.md)'
|
2016-11-10 00:57:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-01 06:07:52 -05:00
|
|
|
context 'with relative url' do
|
|
|
|
it 'prefixes it with /help/' do
|
|
|
|
stub_readme("[API](api/README.md)")
|
|
|
|
|
2016-11-10 00:57:46 -05:00
|
|
|
get :index
|
2016-12-01 06:07:52 -05:00
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
|
2016-11-10 00:57:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-18 06:57:25 -05:00
|
|
|
context 'when url is an external link' do
|
2016-12-01 06:07:52 -05:00
|
|
|
it 'does not change it' do
|
2016-11-18 06:57:25 -05:00
|
|
|
stub_readme("[external](https://some.external.link)")
|
2016-12-01 06:07:52 -05:00
|
|
|
|
2016-11-10 00:57:46 -05:00
|
|
|
get :index
|
2016-12-01 06:07:52 -05:00
|
|
|
|
2016-11-18 06:57:25 -05:00
|
|
|
expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
|
2016-11-10 00:57:46 -05:00
|
|
|
end
|
|
|
|
end
|
2019-02-11 16:20:39 -05:00
|
|
|
|
|
|
|
context 'when relative url with external on same line' do
|
|
|
|
it 'prefix it with /help/' do
|
|
|
|
stub_readme("[API](api/README.md) [external](https://some.external.link)")
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[API](/help/api/README.md) [external](https://some.external.link)'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when relative url with http:// in query' do
|
|
|
|
it 'prefix it with /help/' do
|
|
|
|
stub_readme("[API](api/README.md?go=https://example.com/)")
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[API](/help/api/README.md?go=https://example.com/)'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when mailto URL' do
|
|
|
|
it 'do not change it' do
|
|
|
|
stub_readme("[report bug](mailto:bugs@example.com)")
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[report bug](mailto:bugs@example.com)'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when protocol-relative link' do
|
|
|
|
it 'do not change it' do
|
|
|
|
stub_readme("[protocol-relative](//example.com)")
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(assigns[:help_index]).to eq '[protocol-relative](//example.com)'
|
|
|
|
end
|
|
|
|
end
|
2016-11-10 00:57:46 -05:00
|
|
|
end
|
|
|
|
|
2015-04-15 12:45:31 -04:00
|
|
|
describe 'GET #show' do
|
|
|
|
context 'for Markdown formats' do
|
|
|
|
context 'when requested file exists' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { path: 'ssh/README' }, format: :md
|
2015-04-15 12:45:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns to @markdown' do
|
|
|
|
expect(assigns[:markdown]).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders HTML' do
|
|
|
|
expect(response).to render_template('show.html.haml')
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requested file is missing' do
|
|
|
|
it 'renders not found' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { path: 'foo/bar' }, format: :md
|
2015-04-15 12:45:31 -04:00
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for image formats' do
|
|
|
|
context 'when requested file exists' do
|
|
|
|
it 'renders the raw file' do
|
2015-06-23 01:24:39 -04:00
|
|
|
get :show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
path: 'user/project/img/labels_default'
|
|
|
|
},
|
2015-06-23 01:24:39 -04:00
|
|
|
format: :png
|
2015-04-15 12:45:31 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
expect(response.content_type).to eq 'image/png'
|
|
|
|
expect(response.headers['Content-Disposition']).to match(/^inline;/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requested file is missing' do
|
|
|
|
it 'renders not found' do
|
2015-06-23 01:24:39 -04:00
|
|
|
get :show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
path: 'foo/bar'
|
|
|
|
},
|
2015-06-23 01:24:39 -04:00
|
|
|
format: :png
|
2015-04-15 12:45:31 -04:00
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for other formats' do
|
|
|
|
it 'always renders not found' do
|
2015-06-23 01:24:39 -04:00
|
|
|
get :show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
path: 'ssh/README'
|
|
|
|
},
|
2015-06-23 01:24:39 -04:00
|
|
|
format: :foo
|
2015-04-15 12:45:31 -04:00
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-19 13:17:14 -04:00
|
|
|
|
|
|
|
describe 'GET #ui' do
|
|
|
|
context 'for UI Development Kit' do
|
|
|
|
it 'renders found' do
|
|
|
|
get :ui
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-07-19 13:17:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-10 00:57:46 -05:00
|
|
|
|
|
|
|
def stub_readme(content)
|
|
|
|
allow(File).to receive(:read).and_return(content)
|
|
|
|
end
|
2015-04-15 12:45:31 -04:00
|
|
|
end
|