2019-07-11 21:40:20 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe TeamRepository, type: :model do
|
2022-06-07 00:21:57 +08:00
|
|
|
let(:user) { create :user }
|
|
|
|
let(:team) { create :team, created_by: user }
|
|
|
|
let(:another_team) { create :team, created_by: user }
|
|
|
|
let(:repository) { create :repository, team: team, created_by: user }
|
|
|
|
let(:team_repository) { build :team_repository, :read, team: another_team, repository: repository }
|
2019-07-11 21:40:20 +08:00
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(team_repository).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Validations' do
|
|
|
|
describe '#permission_level' do
|
|
|
|
it { is_expected.to validate_presence_of(:permission_level) }
|
|
|
|
end
|
2019-07-15 23:17:26 +08:00
|
|
|
describe '#repository' do
|
|
|
|
it { expect(team_repository).to validate_uniqueness_of(:repository).scoped_to(:team_id) }
|
|
|
|
end
|
2019-08-09 17:36:19 +08:00
|
|
|
describe '#team' do
|
|
|
|
it { expect(team_repository).to validate_uniqueness_of(:repository).scoped_to(:team_id) }
|
|
|
|
|
|
|
|
it 'invalid when repo team is same as sharring team' do
|
2022-06-07 00:21:57 +08:00
|
|
|
repo = create :repository, team: team, created_by: user
|
2019-08-09 17:36:19 +08:00
|
|
|
invalid_team_repository = build :team_repository, :read, repository: repo, team: repo.team
|
|
|
|
|
|
|
|
expect(invalid_team_repository).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
2019-07-11 21:40:20 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Associations' do
|
|
|
|
it { is_expected.to belong_to(:team) }
|
|
|
|
it { is_expected.to belong_to(:repository) }
|
|
|
|
end
|
|
|
|
end
|