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
db796737
Commit
db796737
authored
Jan 28, 2021
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scopes to OnboardingProgress model
parent
5e081c84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
2 deletions
+87
-2
app/models/onboarding_progress.rb
app/models/onboarding_progress.rb
+20
-2
spec/models/onboarding_progress_spec.rb
spec/models/onboarding_progress_spec.rb
+67
-0
No files found.
app/models/onboarding_progress.rb
View file @
db796737
...
...
@@ -22,6 +22,24 @@ class OnboardingProgress < ApplicationRecord
:repository_mirrored
].
freeze
scope
:incomplete_actions
,
->
(
actions
)
do
Array
.
wrap
(
actions
).
inject
(
self
)
{
|
scope
,
action
|
scope
.
where
(
column_name
(
action
)
=>
nil
)
}
end
scope
:completed_actions
,
->
(
actions
)
do
Array
.
wrap
(
actions
).
inject
(
self
)
{
|
scope
,
action
|
scope
.
where
.
not
(
column_name
(
action
)
=>
nil
)
}
end
scope
:completed_actions_with_latest_in_range
,
->
(
actions
,
range
)
do
actions
=
Array
(
actions
)
if
actions
.
size
==
1
where
(
column_name
(
actions
[
0
])
=>
range
)
else
action_columns
=
actions
.
map
{
|
action
|
arel_table
[
column_name
(
action
)]
}
completed_actions
(
actions
).
where
(
Arel
::
Nodes
::
NamedFunction
.
new
(
'GREATEST'
,
action_columns
).
between
(
range
))
end
end
class
<<
self
def
onboard
(
namespace
)
return
unless
root_namespace?
(
namespace
)
...
...
@@ -44,12 +62,12 @@ class OnboardingProgress < ApplicationRecord
where
(
namespace:
namespace
).
where
.
not
(
action_column
=>
nil
).
exists?
end
private
def
column_name
(
action
)
:"
#{
action
}
_at"
end
private
def
root_namespace?
(
namespace
)
namespace
&&
namespace
.
root?
end
...
...
spec/models/onboarding_progress_spec.rb
View file @
db796737
...
...
@@ -29,6 +29,67 @@ RSpec.describe OnboardingProgress do
end
end
describe
'scopes'
do
describe
'.incomplete_actions'
do
subject
{
described_class
.
incomplete_actions
(
actions
)
}
let!
(
:no_actions_completed
)
{
create
(
:onboarding_progress
)
}
let!
(
:one_action_completed_one_action_incompleted
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
Time
.
current
)
}
context
'when given one action'
do
let
(
:actions
)
{
action
}
it
{
is_expected
.
to
eq
[
no_actions_completed
]
}
end
context
'when given an array of actions'
do
let
(
:actions
)
{
[
action
,
:git_write
]
}
it
{
is_expected
.
to
eq
[
no_actions_completed
]
}
end
end
describe
'.completed_actions'
do
subject
{
described_class
.
completed_actions
(
actions
)
}
let!
(
:one_action_completed_one_action_incompleted
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
Time
.
current
)
}
let!
(
:both_actions_completed
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
Time
.
current
,
git_write_at:
Time
.
current
)
}
context
'when given one action'
do
let
(
:actions
)
{
action
}
it
{
is_expected
.
to
eq
[
one_action_completed_one_action_incompleted
,
both_actions_completed
]
}
end
context
'when given an array of actions'
do
let
(
:actions
)
{
[
action
,
:git_write
]
}
it
{
is_expected
.
to
eq
[
both_actions_completed
]
}
end
end
describe
'.completed_actions_with_latest_in_range'
do
subject
{
described_class
.
completed_actions_with_latest_in_range
(
actions
,
1
.
day
.
ago
.
beginning_of_day
..
1
.
day
.
ago
.
end_of_day
)
}
let!
(
:one_action_completed_in_range_one_action_incompleted
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
1
.
day
.
ago
.
middle_of_day
)
}
let!
(
:git_write_action_completed_in_range
)
{
create
(
:onboarding_progress
,
git_write_at:
1
.
day
.
ago
.
middle_of_day
)
}
let!
(
:both_actions_completed_latest_action_out_of_range
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
1
.
day
.
ago
.
middle_of_day
,
git_write_at:
Time
.
current
)
}
let!
(
:both_actions_completed_latest_action_in_range
)
{
create
(
:onboarding_progress
,
"
#{
action
}
_at"
=>
1
.
day
.
ago
.
middle_of_day
,
git_write_at:
2
.
days
.
ago
.
middle_of_day
)
}
context
'when given one action'
do
let
(
:actions
)
{
:git_write
}
it
{
is_expected
.
to
eq
[
git_write_action_completed_in_range
]
}
end
context
'when given an array of actions'
do
let
(
:actions
)
{
[
action
,
:git_write
]
}
it
{
is_expected
.
to
eq
[
both_actions_completed_latest_action_in_range
]
}
end
end
end
describe
'.onboard'
do
subject
(
:onboard
)
{
described_class
.
onboard
(
namespace
)
}
...
...
@@ -104,4 +165,10 @@ RSpec.describe OnboardingProgress do
end
end
end
describe
'.column_name'
do
subject
{
described_class
.
column_name
(
action
)
}
it
{
is_expected
.
to
eq
(
:subscription_created_at
)
}
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