diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/models/experiment_subject_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/models/experiment_subject_spec.rb')
-rw-r--r-- | spec/models/experiment_subject_spec.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/models/experiment_subject_spec.rb b/spec/models/experiment_subject_spec.rb new file mode 100644 index 00000000000..4850814c5f5 --- /dev/null +++ b/spec/models/experiment_subject_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ExperimentSubject, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:experiment) } + it { is_expected.to belong_to(:user) } + it { is_expected.to belong_to(:group) } + it { is_expected.to belong_to(:project) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:experiment) } + + describe 'must_have_one_subject_present' do + let(:experiment_subject) { build(:experiment_subject, user: nil, group: nil, project: nil) } + let(:error_message) { 'Must have exactly one of User, Group, or Project.' } + + it 'fails when no subject is present' do + expect(experiment_subject).not_to be_valid + expect(experiment_subject.errors[:base]).to include(error_message) + end + + it 'passes when user subject is present' do + experiment_subject.user = build(:user) + expect(experiment_subject).to be_valid + end + + it 'passes when group subject is present' do + experiment_subject.group = build(:group) + expect(experiment_subject).to be_valid + end + + it 'passes when project subject is present' do + experiment_subject.project = build(:project) + expect(experiment_subject).to be_valid + end + + it 'fails when more than one subject is present', :aggregate_failures do + # two subjects + experiment_subject.user = build(:user) + experiment_subject.group = build(:group) + expect(experiment_subject).not_to be_valid + expect(experiment_subject.errors[:base]).to include(error_message) + + # three subjects + experiment_subject.project = build(:project) + expect(experiment_subject).not_to be_valid + expect(experiment_subject.errors[:base]).to include(error_message) + end + end + end +end |