diff options
author | Felipe Artur <felipefac@gmail.com> | 2018-02-19 22:06:16 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-03-03 18:56:17 +0300 |
commit | dd071c4b6e9754a0abeec45ab2040d9e2d5a62b8 (patch) | |
tree | 9dda99bb987378cb6cbc95d236757d11f21176a6 /spec/controllers | |
parent | 98fecb5f8e64c4c64c96d065bc342d986140367e (diff) |
Bring one group board to CE
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/groups/boards_controller_spec.rb | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb new file mode 100644 index 00000000000..0f5bde62006 --- /dev/null +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -0,0 +1,136 @@ +require 'spec_helper' + +describe Groups::BoardsController do + let(:group) { create(:group) } + let(:user) { create(:user) } + + before do + group.add_master(user) + sign_in(user) + end + + describe 'GET index' do + it 'creates a new board when group does not have one' do + expect { list_boards }.to change(group.boards, :count).by(1) + end + + context 'when format is HTML' do + it 'renders template' do + list_boards + + expect(response).to render_template :index + expect(response.content_type).to eq 'text/html' + end + + context 'with unauthorized user' do + before do + allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) + allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false) + end + + it 'returns a not found 404 response' do + list_boards + + expect(response).to have_gitlab_http_status(404) + expect(response.content_type).to eq 'text/html' + end + end + end + + context 'when format is JSON' do + it 'return an array with one group board' do + create(:board, group: group) + + list_boards format: :json + + parsed_response = JSON.parse(response.body) + + expect(response).to match_response_schema('boards') + expect(parsed_response.length).to eq 1 + end + + context 'with unauthorized user' do + before do + allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) + allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false) + end + + it 'returns a not found 404 response' do + list_boards format: :json + + expect(response).to have_gitlab_http_status(404) + expect(response.content_type).to eq 'application/json' + end + end + end + + def list_boards(format: :html) + get :index, group_id: group, format: format + end + end + + describe 'GET show' do + let!(:board) { create(:board, group: group) } + + context 'when format is HTML' do + it 'renders template' do + read_board board: board + + expect(response).to render_template :show + expect(response.content_type).to eq 'text/html' + end + + context 'with unauthorized user' do + before do + allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) + allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false) + end + + it 'returns a not found 404 response' do + read_board board: board + + expect(response).to have_gitlab_http_status(404) + expect(response.content_type).to eq 'text/html' + end + end + end + + context 'when format is JSON' do + it 'returns project board' do + read_board board: board, format: :json + + expect(response).to match_response_schema('board') + end + + context 'with unauthorized user' do + before do + allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) + allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false) + end + + it 'returns a not found 404 response' do + read_board board: board, format: :json + + expect(response).to have_gitlab_http_status(404) + expect(response.content_type).to eq 'application/json' + end + end + end + + context 'when board does not belong to group' do + it 'returns a not found 404 response' do + another_board = create(:board) + + read_board board: another_board + + expect(response).to have_gitlab_http_status(404) + end + end + + def read_board(board:, format: :html) + get :show, group_id: group, + id: board.to_param, + format: format + end + end +end |