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
5ba52c44
Commit
5ba52c44
authored
Mar 04, 2021
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move callout dismissal to service
Moves the logic for dismissing a user callout into a service.
parent
333a697b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
8 deletions
+47
-8
app/controllers/user_callouts_controller.rb
app/controllers/user_callouts_controller.rb
+3
-2
app/graphql/mutations/user_callouts/create.rb
app/graphql/mutations/user_callouts/create.rb
+5
-5
app/services/users/dismiss_user_callout_service.rb
app/services/users/dismiss_user_callout_service.rb
+11
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-1
spec/services/users/dismiss_user_callout_service_spec.rb
spec/services/users/dismiss_user_callout_service_spec.rb
+27
-0
No files found.
app/controllers/user_callouts_controller.rb
View file @
5ba52c44
...
...
@@ -4,8 +4,9 @@ class UserCalloutsController < ApplicationController
feature_category
:navigation
def
create
callout
=
current_user
.
find_or_initialize_callout
(
feature_name
)
callout
.
update
(
dismissed_at:
Time
.
current
)
if
callout
.
valid?
callout
=
Users
::
DismissUserCalloutService
.
new
(
container:
nil
,
current_user:
current_user
,
params:
{
feature_name:
feature_name
}
).
execute
if
callout
.
persisted?
respond_to
do
|
format
|
...
...
app/graphql/mutations/user_callouts/create.rb
View file @
5ba52c44
...
...
@@ -15,13 +15,13 @@ module Mutations
description:
'The user callout dismissed.'
def
resolve
(
feature_name
:)
user_callout
=
current_user
.
find_or_initialize_callout
(
feature_name
)
user_callout
.
update
(
dismissed_at:
Time
.
current
)
if
user_callout
.
valid?
errors
=
errors_on_object
(
user_
callout
)
callout
=
Users
::
DismissUserCalloutService
.
new
(
container:
nil
,
current_user:
current_user
,
params:
{
feature_name:
feature_name
}
).
execute
errors
=
errors_on_object
(
callout
)
{
user_callout:
user_
callout
,
user_callout:
callout
,
errors:
errors
}
end
...
...
app/services/users/dismiss_user_callout_service.rb
0 → 100644
View file @
5ba52c44
# frozen_string_literal: true
module
Users
class
DismissUserCalloutService
<
BaseContainerService
def
execute
current_user
.
find_or_initialize_callout
(
params
[
:feature_name
]).
tap
do
|
callout
|
callout
.
update
(
dismissed_at:
Time
.
current
)
if
callout
.
valid?
end
end
end
end
spec/models/user_spec.rb
View file @
5ba52c44
...
...
@@ -5487,7 +5487,7 @@ RSpec.describe User do
subject
(
:find_or_initialize_callout
)
{
user
.
find_or_initialize_callout
(
feature_name
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:feature_name
)
{
UserCallout
.
feature_names
.
keys
.
first
}
let
(
:feature_name
)
{
UserCallout
.
feature_names
.
each_key
.
first
}
context
'when callout exists'
do
let!
(
:callout
)
{
create
(
:user_callout
,
user:
user
,
feature_name:
feature_name
)
}
...
...
spec/services/users/dismiss_user_callout_service_spec.rb
0 → 100644
View file @
5ba52c44
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Users
::
DismissUserCalloutService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
do
described_class
.
new
(
container:
nil
,
current_user:
user
,
params:
{
feature_name:
UserCallout
.
feature_names
.
each_key
.
first
}
)
end
describe
'#execute'
do
subject
(
:execute
)
{
service
.
execute
}
it
'returns a user callout'
do
expect
(
execute
).
to
be_an_instance_of
(
UserCallout
)
end
it
'sets the dismisse_at attribute to current time'
do
freeze_time
do
expect
(
execute
).
to
have_attributes
(
dismissed_at:
Time
.
current
)
end
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