summaryrefslogtreecommitdiff
path: root/spec/models/experiment_subject_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/experiment_subject_spec.rb')
-rw-r--r--spec/models/experiment_subject_spec.rb30
1 files changed, 24 insertions, 6 deletions
diff --git a/spec/models/experiment_subject_spec.rb b/spec/models/experiment_subject_spec.rb
index 4850814c5f5..d86dc3cbf65 100644
--- a/spec/models/experiment_subject_spec.rb
+++ b/spec/models/experiment_subject_spec.rb
@@ -6,7 +6,7 @@ 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(:namespace) }
it { is_expected.to belong_to(:project) }
end
@@ -14,8 +14,8 @@ RSpec.describe ExperimentSubject, type: :model 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.' }
+ let(:experiment_subject) { build(:experiment_subject, user: nil, namespace: nil, project: nil) }
+ let(:error_message) { 'Must have exactly one of User, Namespace, or Project.' }
it 'fails when no subject is present' do
expect(experiment_subject).not_to be_valid
@@ -27,8 +27,8 @@ RSpec.describe ExperimentSubject, type: :model do
expect(experiment_subject).to be_valid
end
- it 'passes when group subject is present' do
- experiment_subject.group = build(:group)
+ it 'passes when namespace subject is present' do
+ experiment_subject.namespace = build(:group)
expect(experiment_subject).to be_valid
end
@@ -40,7 +40,7 @@ RSpec.describe ExperimentSubject, type: :model do
it 'fails when more than one subject is present', :aggregate_failures do
# two subjects
experiment_subject.user = build(:user)
- experiment_subject.group = build(:group)
+ experiment_subject.namespace = build(:group)
expect(experiment_subject).not_to be_valid
expect(experiment_subject.errors[:base]).to include(error_message)
@@ -51,4 +51,22 @@ RSpec.describe ExperimentSubject, type: :model do
end
end
end
+
+ describe '.valid_subject?' do
+ subject(:valid_subject?) { described_class.valid_subject?(subject_class.new) }
+
+ context 'when passing a Group, Namespace, User or Project' do
+ [Group, Namespace, User, Project].each do |subject_class|
+ let(:subject_class) { subject_class }
+
+ it { is_expected.to be(true) }
+ end
+ end
+
+ context 'when passing another object' do
+ let(:subject_class) { Issue }
+
+ it { is_expected.to be(false) }
+ end
+ end
end