Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6a695084
Commit
6a695084
authored
May 31, 2021
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement reviewer feedback
parent
66f28b08
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
5 deletions
+27
-5
app/experiments/application_experiment.rb
app/experiments/application_experiment.rb
+1
-1
app/models/experiment.rb
app/models/experiment.rb
+2
-2
app/models/experiment_subject.rb
app/models/experiment_subject.rb
+4
-0
spec/models/experiment_spec.rb
spec/models/experiment_spec.rb
+2
-2
spec/models/experiment_subject_spec.rb
spec/models/experiment_subject_spec.rb
+18
-0
No files found.
app/experiments/application_experiment.rb
View file @
6a695084
...
...
@@ -58,7 +58,7 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
def
record_experiment
subject
=
context
.
value
[
:namespace
]
||
context
.
value
[
:group
]
||
context
.
value
[
:project
]
||
context
.
value
[
:user
]
||
context
.
value
[
:actor
]
return
unless
subject
.
is_a?
(
Namespace
)
||
subject
.
is_a?
(
User
)
||
subject
.
is_a?
(
Pro
ject
)
return
unless
ExperimentSubject
.
valid_subject?
(
sub
ject
)
variant
=
:experimental
if
@variant_name
!=
:control
...
...
app/models/experiment.rb
View file @
6a695084
...
...
@@ -42,9 +42,9 @@ class Experiment < ApplicationRecord
end
def
record_subject_and_variant!
(
subject
,
variant
)
raise
'Incompatible subject provided!'
unless
subject
.
is_a?
(
Namespace
)
||
subject
.
is_a?
(
User
)
||
subject
.
is_a?
(
Pro
ject
)
raise
'Incompatible subject provided!'
unless
ExperimentSubject
.
valid_subject?
(
sub
ject
)
attr_name
=
subject
.
is_a?
(
Namespace
)
?
:namespace
:
subject
.
class
.
name
.
downcas
e
.
to_sym
attr_name
=
subject
.
class
.
table_name
.
singulariz
e
.
to_sym
experiment_subject
=
experiment_subjects
.
find_or_initialize_by
(
attr_name
=>
subject
)
experiment_subject
.
assign_attributes
(
variant:
variant
)
# We only call save when necessary because this causes the request to stick to the primary DB
...
...
app/models/experiment_subject.rb
View file @
6a695084
...
...
@@ -14,6 +14,10 @@ class ExperimentSubject < ApplicationRecord
enum
variant:
{
GROUP_CONTROL
=>
0
,
GROUP_EXPERIMENTAL
=>
1
}
def
self
.
valid_subject?
(
subject
)
subject
.
is_a?
(
Namespace
)
||
subject
.
is_a?
(
User
)
||
subject
.
is_a?
(
Project
)
end
private
def
must_have_one_subject_present
...
...
spec/models/experiment_spec.rb
View file @
6a695084
...
...
@@ -273,7 +273,7 @@ RSpec.describe Experiment do
describe
'providing a subject to record'
do
context
'when given a group as subject'
do
it
'saves the namespace
owner as experiment_subject user
'
do
it
'saves the namespace
as the experiment subject
'
do
expect
(
record_subject_and_variant!
.
namespace
).
to
eq
(
subject_to_record
)
end
end
...
...
@@ -281,7 +281,7 @@ RSpec.describe Experiment do
context
'when given a users namespace as subject'
do
let_it_be
(
:subject_to_record
)
{
build
(
:namespace
)
}
it
'saves the namespace
owner as experiment_subject user
'
do
it
'saves the namespace
as the experiment_subject
'
do
expect
(
record_subject_and_variant!
.
namespace
).
to
eq
(
subject_to_record
)
end
end
...
...
spec/models/experiment_subject_spec.rb
View file @
6a695084
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment