diff options
Diffstat (limited to 'spec/controllers/groups/boards_controller_spec.rb')
-rw-r--r-- | spec/controllers/groups/boards_controller_spec.rb | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb index bf41aa0706f..d1d08391164 100644 --- a/spec/controllers/groups/boards_controller_spec.rb +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Groups::BoardsController do let(:group) { create(:group) } - let(:user) { create(:user) } + let(:user) { create(:user) } before do group.add_maintainer(user) @@ -22,6 +22,27 @@ describe Groups::BoardsController do expect(response.content_type).to eq 'text/html' end + it 'redirects to latest visited board' do + board = create(:board, group: group) + create(:board_group_recent_visit, group: board.group, board: board, user: user) + + list_boards + + expect(response).to redirect_to(group_board_path(id: board.id)) + end + + it 'renders template if visited board is not found' do + visited = double + + allow(visited).to receive(:board_id).and_return(12) + allow_any_instance_of(Boards::Visits::LatestService).to receive(:execute).and_return(visited) + + 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) @@ -35,12 +56,30 @@ describe Groups::BoardsController do expect(response.content_type).to eq 'text/html' end end + + context 'when user is signed out' do + let(:group) { create(:group, :public) } + + it 'renders template' do + sign_out(user) + + board = create(:board, group: group) + create(:board_group_recent_visit, group: board.group, board: board, user: user) + + list_boards + + expect(response).to render_template :index + 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) + expect(Boards::Visits::LatestService).not_to receive(:new) + list_boards format: :json parsed_response = JSON.parse(response.body) @@ -74,7 +113,7 @@ describe Groups::BoardsController do context 'when format is HTML' do it 'renders template' do - read_board board: board + expect { read_board board: board }.to change(BoardGroupRecentVisit, :count).by(1) expect(response).to render_template :show expect(response.content_type).to eq 'text/html' @@ -93,10 +132,25 @@ describe Groups::BoardsController do expect(response.content_type).to eq 'text/html' end end + + context 'when user is signed out' do + let(:group) { create(:group, :public) } + + it 'does not save visit' do + sign_out(user) + + expect { read_board board: board }.to change(BoardGroupRecentVisit, :count).by(0) + + expect(response).to render_template :show + expect(response.content_type).to eq 'text/html' + end + end end context 'when format is JSON' do it 'returns project board' do + expect(Boards::Visits::CreateService).not_to receive(:new) + read_board board: board, format: :json expect(response).to match_response_schema('board') |