BigW Consortium Gitlab

help_controller_spec.rb 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'spec_helper'

describe HelpController do
  let(:user) { create(:user) }

  before do
    sign_in(user)
  end

  describe 'GET #show' do
    context 'for Markdown formats' do
      context 'when requested file exists' do
        before do
Connor Shea committed
14
          get :show, path: 'ssh/README', format: :md
15 16 17 18 19 20 21 22 23 24 25 26 27 28
        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
Connor Shea committed
29
          get :show, path: 'foo/bar', format: :md
30 31 32 33 34 35 36 37
          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
38
          get :show,
39
              path: 'user/project/img/labels_filter',
40
              format: :png
41 42 43 44 45 46 47 48
          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
49
          get :show,
Connor Shea committed
50
              path: 'foo/bar',
51
              format: :png
52 53 54 55 56 57 58
          expect(response).to be_not_found
        end
      end
    end

    context 'for other formats' do
      it 'always renders not found' do
59
        get :show,
Connor Shea committed
60
            path: 'ssh/README',
61
            format: :foo
62 63 64 65
        expect(response).to be_not_found
      end
    end
  end
66 67 68 69 70 71 72 73 74

  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
75
end