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
15b02da6
Commit
15b02da6
authored
Jul 09, 2019
by
Luke Duncalfe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AwardEmojis services in GraphQL mutations
https://gitlab.com/gitlab-org/gitlab-ce/issues/63372
parent
37b17fa6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
40 deletions
+32
-40
app/graphql/mutations/award_emojis/add.rb
app/graphql/mutations/award_emojis/add.rb
+3
-6
app/graphql/mutations/award_emojis/remove.rb
app/graphql/mutations/award_emojis/remove.rb
+2
-13
app/graphql/mutations/award_emojis/toggle.rb
app/graphql/mutations/award_emojis/toggle.rb
+3
-11
spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
+12
-5
spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb
...equests/api/graphql/mutations/award_emojis/toggle_spec.rb
+12
-5
No files found.
app/graphql/mutations/award_emojis/add.rb
View file @
15b02da6
...
...
@@ -10,14 +10,11 @@ module Mutations
check_object_is_awardable!
(
awardable
)
# TODO this will be handled by AwardEmoji::AddService
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
award
=
awardable
.
create_award_emoji
(
args
[
:name
],
current_user
)
service
=
::
AwardEmojis
::
AddService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
{
award_emoji:
(
award
if
award
.
persisted?
),
errors:
errors_on_object
(
award
)
award_emoji:
(
service
[
:award
]
if
service
[
:status
]
==
:success
),
errors:
service
[
:errors
]
||
[]
}
end
end
...
...
app/graphql/mutations/award_emojis/remove.rb
View file @
15b02da6
...
...
@@ -10,22 +10,11 @@ module Mutations
check_object_is_awardable!
(
awardable
)
# TODO this check can be removed once AwardEmoji services are available.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
unless
awardable
.
awarded_emoji?
(
args
[
:name
],
current_user
)
raise
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
,
'You have not awarded emoji of type name to the awardable'
end
# TODO this will be handled by AwardEmoji::DestroyService
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
awardable
.
remove_award_emoji
(
args
[
:name
],
current_user
)
service
=
::
AwardEmojis
::
DestroyService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
{
# Mutation response is always a `nil` award_emoji
errors:
[]
errors:
service
[
:errors
]
||
[]
}
end
end
...
...
app/graphql/mutations/award_emojis/toggle.rb
View file @
15b02da6
...
...
@@ -15,23 +15,15 @@ module Mutations
check_object_is_awardable!
(
awardable
)
# TODO this will be handled by AwardEmoji::ToggleService
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
award
=
awardable
.
toggle_award_emoji
(
args
[
:name
],
current_user
)
# Destroy returns a collection :(
award
=
award
.
first
if
award
.
is_a?
(
Array
)
errors
=
errors_on_object
(
award
)
service
=
::
AwardEmojis
::
ToggleService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
toggled_on
=
awardable
.
awarded_emoji?
(
args
[
:name
],
current_user
)
{
# For consistency with the AwardEmojis::Remove mutation, only return
# the AwardEmoji if it was created and not destroyed
award_emoji:
(
award
if
toggled_on
),
errors:
errors
,
award_emoji:
(
service
[
:award
]
if
toggled_on
),
errors:
service
[
:errors
]
||
[]
,
toggled_on:
toggled_on
}
end
...
...
spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
View file @
15b02da6
...
...
@@ -5,9 +5,9 @@ require 'spec_helper'
describe
'Adding an AwardEmoji'
do
include
GraphqlHelpers
l
et
(
:current_user
)
{
create
(
:user
)
}
let
(
:awardable
)
{
create
(
:note
)
}
let
(
:project
)
{
awardable
.
project
}
s
et
(
:current_user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
)
}
set
(
:awardable
)
{
create
(
:note
,
project:
project
)
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:mutation
)
do
variables
=
{
...
...
@@ -43,7 +43,7 @@ describe 'Adding an AwardEmoji' do
end
context
'when the given awardable is not an Awardable'
do
let
(
:awardable
)
{
create
(
:label
)
}
let
(
:awardable
)
{
create
(
:label
,
project:
project
)
}
it_behaves_like
'a mutation that does not create an AwardEmoji'
...
...
@@ -52,7 +52,7 @@ describe 'Adding an AwardEmoji' do
end
context
'when the given awardable is an Awardable but still cannot be awarded an emoji'
do
let
(
:awardable
)
{
create
(
:system_note
)
}
let
(
:awardable
)
{
create
(
:system_note
,
project:
project
)
}
it_behaves_like
'a mutation that does not create an AwardEmoji'
...
...
@@ -73,6 +73,13 @@ describe 'Adding an AwardEmoji' do
expect
(
mutation_response
[
'awardEmoji'
][
'name'
]).
to
eq
(
emoji_name
)
end
describe
'marking Todos as done'
do
let
(
:user
)
{
current_user
}
subject
{
post_graphql_mutation
(
mutation
,
current_user:
user
)
}
include_examples
'creating award emojis marks Todos as done'
end
context
'when there were active record validation errors'
do
before
do
expect_next_instance_of
(
AwardEmoji
)
do
|
award
|
...
...
spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb
View file @
15b02da6
...
...
@@ -5,9 +5,9 @@ require 'spec_helper'
describe
'Toggling an AwardEmoji'
do
include
GraphqlHelpers
l
et
(
:current_user
)
{
create
(
:user
)
}
let
(
:awardable
)
{
create
(
:note
)
}
let
(
:project
)
{
awardable
.
project
}
s
et
(
:current_user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
)
}
set
(
:awardable
)
{
create
(
:note
,
project:
project
)
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:mutation
)
do
variables
=
{
...
...
@@ -40,7 +40,7 @@ describe 'Toggling an AwardEmoji' do
end
context
'when the given awardable is not an Awardable'
do
let
(
:awardable
)
{
create
(
:label
)
}
let
(
:awardable
)
{
create
(
:label
,
project:
project
)
}
it_behaves_like
'a mutation that does not create or destroy an AwardEmoji'
...
...
@@ -49,7 +49,7 @@ describe 'Toggling an AwardEmoji' do
end
context
'when the given awardable is an Awardable but still cannot be awarded an emoji'
do
let
(
:awardable
)
{
create
(
:system_note
)
}
let
(
:awardable
)
{
create
(
:system_note
,
project:
project
)
}
it_behaves_like
'a mutation that does not create or destroy an AwardEmoji'
...
...
@@ -81,6 +81,13 @@ describe 'Toggling an AwardEmoji' do
expect
(
mutation_response
[
'toggledOn'
]).
to
eq
(
true
)
end
describe
'marking Todos as done'
do
let
(
:user
)
{
current_user
}
subject
{
post_graphql_mutation
(
mutation
,
current_user:
user
)
}
include_examples
'creating award emojis marks Todos as done'
end
context
'when there were active record validation errors'
do
before
do
expect_next_instance_of
(
AwardEmoji
)
do
|
award
|
...
...
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