gitlab-org--gitlab-foss/spec/controllers/help_controller_spec.rb

106 lines
2.7 KiB
Ruby
Raw Normal View History

2015-04-15 16:45:31 +00:00
require 'spec_helper'
describe HelpController do
let(:user) { create(:user) }
before do
sign_in(user)
end
2016-11-10 05:57:46 +00:00
describe 'GET #index' do
context 'when url prefixed without /help/' do
it 'has correct url prefix' 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 prefixed with help' do
it 'will be an absolute path' do
stub_readme("[API](helpful_hints/README.md)")
get :index
expect(assigns[:help_index]).to eq '[API](/help/helpful_hints/README.md)'
end
end
context 'when url is an external link' do
2016-11-10 05:57:46 +00:00
it 'will not be changed' do
stub_readme("[external](https://some.external.link)")
2016-11-10 05:57:46 +00:00
get :index
expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
2016-11-10 05:57:46 +00:00
end
end
end
2015-04-15 16:45:31 +00:00
describe 'GET #show' do
context 'for Markdown formats' do
context 'when requested file exists' do
before do
2016-07-11 22:11:33 +00:00
get :show, path: 'ssh/README', format: :md
2015-04-15 16:45:31 +00: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
2016-07-11 22:11:33 +00:00
get :show, path: 'foo/bar', format: :md
2015-04-15 16:45:31 +00: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 05:24:39 +00:00
get :show,
2016-07-22 08:41:17 +00:00
path: 'user/project/img/labels_filter',
2015-06-23 05:24:39 +00:00
format: :png
2015-04-15 16:45:31 +00: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 05:24:39 +00:00
get :show,
2016-07-11 22:11:33 +00:00
path: 'foo/bar',
2015-06-23 05:24:39 +00:00
format: :png
2015-04-15 16:45:31 +00:00
expect(response).to be_not_found
end
end
end
context 'for other formats' do
it 'always renders not found' do
2015-06-23 05:24:39 +00:00
get :show,
2016-07-11 22:11:33 +00:00
path: 'ssh/README',
2015-06-23 05:24:39 +00:00
format: :foo
2015-04-15 16:45:31 +00:00
expect(response).to be_not_found
end
end
end
describe 'GET #ui' do
context 'for UI Development Kit' do
it 'renders found' do
get :ui
expect(response).to have_http_status(200)
end
end
end
2016-11-10 05:57:46 +00:00
def stub_readme(content)
allow(File).to receive(:read).and_return(content)
end
2015-04-15 16:45:31 +00:00
end