scinote-web/spec/models/team_repository_spec.rb

37 lines
1 KiB
Ruby
Raw Normal View History

2019-07-11 21:40:20 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe TeamRepository, type: :model do
let(:team_repository) { build :team_repository, :read }
it 'is valid' do
2019-09-16 19:03:41 +08:00
team_repository.team = create :team
2019-07-11 21:40:20 +08:00
expect(team_repository).to be_valid
end
describe 'Validations' do
describe '#permission_level' do
it { is_expected.to validate_presence_of(:permission_level) }
end
describe '#repository' do
it { expect(team_repository).to validate_uniqueness_of(:repository).scoped_to(:team_id) }
end
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
repo = create :repository
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