2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Board do
|
2022-08-27 11:52:29 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:other_project) { create(:project) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
2021-04-17 20:07:23 +05:30
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
2016-09-13 17:45:13 +05:30
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe 'constants' do
|
|
|
|
it { expect(described_class::RECENT_BOARDS_SIZE).to be_a(Integer) }
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#order_by_name_asc' do
|
2022-06-21 17:19:12 +05:30
|
|
|
# rubocop:disable RSpec/VariableName
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:board_B) { create(:board, project: project, name: 'B') }
|
|
|
|
let!(:board_C) { create(:board, project: project, name: 'C') }
|
|
|
|
let!(:board_a) { create(:board, project: project, name: 'a') }
|
|
|
|
let!(:board_A) { create(:board, project: project, name: 'A') }
|
2022-06-21 17:19:12 +05:30
|
|
|
# rubocop:enable RSpec/VariableName
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'returns in case-insensitive alphabetical order and then by ascending id' do
|
|
|
|
expect(project.boards.order_by_name_asc).to eq [board_a, board_A, board_B, board_C]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#first_board' do
|
2022-06-21 17:19:12 +05:30
|
|
|
# rubocop:disable RSpec/VariableName
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:board_B) { create(:board, project: project, name: 'B') }
|
|
|
|
let!(:board_C) { create(:board, project: project, name: 'C') }
|
|
|
|
let!(:board_a) { create(:board, project: project, name: 'a') }
|
|
|
|
let!(:board_A) { create(:board, project: project, name: 'A') }
|
2022-06-21 17:19:12 +05:30
|
|
|
# rubocop:enable RSpec/VariableName
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'return the first case-insensitive alphabetical board as a relation' do
|
|
|
|
expect(project.boards.first_board).to eq [board_a]
|
|
|
|
end
|
|
|
|
|
|
|
|
# BoardsActions#board expects this behavior
|
|
|
|
it 'raises an error when find is done on a non-existent record' do
|
|
|
|
expect { project.boards.first_board.find(board_A.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe '#disabled_for?' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { board.disabled_for?(user) }
|
|
|
|
|
|
|
|
shared_examples 'board disabled_for?' do
|
|
|
|
context 'when current user cannot create non backlog issues' do
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can create backlog issues' do
|
|
|
|
before do
|
|
|
|
board.resource_parent.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
|
|
|
|
context 'when block_issue_repositioning is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(block_issue_repositioning: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for group board' do
|
|
|
|
let_it_be(:board) { create(:board, group: group) }
|
|
|
|
|
|
|
|
it_behaves_like 'board disabled_for?'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project board' do
|
|
|
|
let_it_be(:board) { create(:board, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'board disabled_for?'
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|