debian-mirror-gitlab/spec/controllers/help_controller_spec.rb

175 lines
4.3 KiB
Ruby
Raw Normal View History

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 HelpController do
2015-04-26 12:48:37 +05:30
let(:user) { create(:user) }
before do
sign_in(user)
end
2017-08-17 22:00:37 +05:30
describe 'GET #index' do
context 'with absolute url' do
it 'keeps the URL absolute' do
stub_readme("[API](/api/README.md)")
get :index
expect(assigns[:help_index]).to eq '[API](/api/README.md)'
end
end
context 'with relative url' do
it 'prefixes it with /help/' do
stub_readme("[API](api/README.md)")
get :index
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
end
end
context 'when url is an external link' do
it 'does not change it' do
stub_readme("[external](https://some.external.link)")
get :index
expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
end
end
2019-07-07 11:18:12 +05:30
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
2020-04-22 19:07:51 +05:30
context 'restricted visibility set to public' do
before do
sign_out(user)
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end
it 'redirects to sign_in path' do
get :index
expect(response).to redirect_to(new_user_session_path)
end
end
2017-08-17 22:00:37 +05:30
end
2015-04-26 12:48:37 +05:30
describe 'GET #show' do
context 'for Markdown formats' do
context 'when requested file exists' do
before do
2020-05-24 23:13:21 +05:30
expect(File).to receive(:read).and_return(fixture_file('blockquote_fence_after.md'))
2019-02-15 15:39:39 +05:30
get :show, params: { path: 'ssh/README' }, format: :md
2015-04-26 12:48:37 +05:30
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')
2020-05-24 23:13:21 +05:30
expect(response.media_type).to eq 'text/html'
2015-04-26 12:48:37 +05:30
end
end
context 'when requested file is missing' do
it 'renders not found' do
2019-02-15 15:39:39 +05:30
get :show, params: { path: 'foo/bar' }, format: :md
2015-04-26 12:48:37 +05:30
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-09-11 14:41:01 +05:30
get :show,
2019-02-15 15:39:39 +05:30
params: {
2020-03-13 15:44:24 +05:30
path: 'user/img/markdown_logo'
2019-02-15 15:39:39 +05:30
},
2015-09-11 14:41:01 +05:30
format: :png
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2020-05-24 23:13:21 +05:30
expect(response.media_type).to eq 'image/png'
2015-04-26 12:48:37 +05:30
expect(response.headers['Content-Disposition']).to match(/^inline;/)
end
end
context 'when requested file is missing' do
it 'renders not found' do
2015-09-11 14:41:01 +05:30
get :show,
2019-02-15 15:39:39 +05:30
params: {
path: 'foo/bar'
},
2015-09-11 14:41:01 +05:30
format: :png
2015-04-26 12:48:37 +05:30
expect(response).to be_not_found
end
end
end
context 'for other formats' do
it 'always renders not found' do
2015-09-11 14:41:01 +05:30
get :show,
2019-02-15 15:39:39 +05:30
params: {
path: 'ssh/README'
},
2015-09-11 14:41:01 +05:30
format: :foo
2015-04-26 12:48:37 +05:30
expect(response).to be_not_found
end
end
end
2016-08-24 12:49:21 +05:30
describe 'GET #ui' do
context 'for UI Development Kit' do
it 'renders found' do
get :ui
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-08-24 12:49:21 +05:30
end
end
end
2017-08-17 22:00:37 +05:30
def stub_readme(content)
2020-05-24 23:13:21 +05:30
expect(File).to receive(:read).and_return(content)
2017-08-17 22:00:37 +05:30
end
2015-04-26 12:48:37 +05:30
end