boards_controller_spec.rb 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
require 'spec_helper'

describe Projects::BoardsController do
  let(:project) { create(:empty_project) }
  let(:user)    { create(:user) }

  before do
    project.team << [user, :master]
    sign_in(user)
  end

12
  describe 'GET show' do
13 14
    it 'creates a new board when project does not have one' do
      expect { read_board }.to change(Board, :count).by(1)
15 16
    end

17 18
    it 'renders HTML template' do
      read_board
19

20 21
      expect(response).to render_template :show
      expect(response.content_type).to eq 'text/html'
22 23
    end

24 25
    context 'with unauthorized user' do
      before do
26 27
        allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
        allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
28
      end
29

30 31
      it 'returns a successful 404 response' do
        read_board
32

33 34
        expect(response).to have_http_status(404)
      end
35 36 37 38 39 40
    end

    def read_board(format: :html)
      get :show, namespace_id: project.namespace.to_param,
                 project_id: project.to_param,
                 format: format
41 42 43
    end
  end
end