2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-07-27 15:32:32 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Board do
|
2020-01-17 10:08:37 -05:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:other_project) { create(:project) }
|
|
|
|
|
2016-07-27 15:32:32 -04:00
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2016-07-31 19:48:00 -04:00
|
|
|
it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
2021-03-12 07:09:33 -05:00
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
2016-07-27 15:32:32 -04:00
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
end
|
2020-01-17 10:08:37 -05:00
|
|
|
|
|
|
|
describe '#order_by_name_asc' do
|
2020-02-07 10:09:52 -05:00
|
|
|
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') }
|
2020-01-17 10:08:37 -05:00
|
|
|
|
2020-02-07 10:09:52 -05:00
|
|
|
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]
|
2020-01-17 10:08:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#first_board' do
|
2020-02-07 10:09:52 -05:00
|
|
|
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') }
|
2020-01-17 10:08:37 -05:00
|
|
|
|
2020-02-07 10:09:52 -05:00
|
|
|
it 'return the first case-insensitive alphabetical board as a relation' do
|
|
|
|
expect(project.boards.first_board).to eq [board_a]
|
2020-01-17 10:08:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# BoardsActions#board expects this behavior
|
|
|
|
it 'raises an error when find is done on a non-existent record' do
|
2020-02-07 10:09:52 -05:00
|
|
|
expect { project.boards.first_board.find(board_A.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
2020-01-17 10:08:37 -05:00
|
|
|
end
|
|
|
|
end
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|