groups_controller_spec.rb 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
require 'spec_helper'

describe GroupsController do
  include ExternalAuthorizationServiceHelpers

  let(:user) { create(:user) }
  let(:group) { create(:group) }

  before do
    group.add_owner(user)
    sign_in(user)
  end

  context 'with external authorization service enabled' do
    before do
      enable_external_authorization_service
    end

    describe 'GET #show' do
      it 'is successful' do
        get :show, id: group.to_param

        expect(response).to have_gitlab_http_status(200)
      end

      it 'does not allow other formats' do
        get :show, id: group.to_param, format: :atom

        expect(response).to have_gitlab_http_status(404)
      end
    end

    describe 'GET #edit' do
      it 'is successful' do
        get :edit, id: group.to_param

        expect(response).to have_gitlab_http_status(200)
      end
    end

    describe 'GET #new' do
      it 'is successful' do
        get :new

        expect(response).to have_gitlab_http_status(200)
      end
    end

    describe 'GET #index' do
      it 'is successful' do
        get :index

        # Redirects to the dashboard
        expect(response).to have_gitlab_http_status(302)
      end
    end

    describe 'POST #create' do
      it 'creates a group' do
        expect do
          post :create, group: { name: 'a name', path: 'a-name' }
        end.to change { Group.count }.by(1)
      end
    end

    describe 'PUT #update' do
      it 'updates a group' do
        expect do
          put :update, id: group.to_param, group: { name: 'world' }
        end.to change { group.reload.name }
      end
    end

    describe 'DELETE #destroy' do
      it 'deletes the group' do
        delete :destroy, id: group.to_param

        expect(response).to have_gitlab_http_status(302)
      end
    end
  end

  describe 'GET #activity' do
    subject { get :activity, id: group.to_param }

    it_behaves_like 'disabled when using an external authorization service'
  end

  describe 'GET #issues' do
    subject { get :issues, id: group.to_param }

    it_behaves_like 'disabled when using an external authorization service'
  end

  describe 'GET #merge_requests' do
    subject { get :merge_requests, id: group.to_param }

    it_behaves_like 'disabled when using an external authorization service'
  end
end