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
...
@@ -10,14 +10,11 @@ module Mutations
check_object_is_awardable!
(
awardable
)
check_object_is_awardable!
(
awardable
)
# TODO this will be handled by AwardEmoji::AddService
service
=
::
AwardEmojis
::
AddService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
# 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
)
{
{
award_emoji:
(
award
if
award
.
persisted?
),
award_emoji:
(
service
[
:award
]
if
service
[
:status
]
==
:success
),
errors:
errors_on_object
(
award
)
errors:
service
[
:errors
]
||
[]
}
}
end
end
end
end
...
...
app/graphql/mutations/award_emojis/remove.rb
View file @
15b02da6
...
@@ -10,22 +10,11 @@ module Mutations
...
@@ -10,22 +10,11 @@ module Mutations
check_object_is_awardable!
(
awardable
)
check_object_is_awardable!
(
awardable
)
# TODO this check can be removed once AwardEmoji services are available.
service
=
::
AwardEmojis
::
DestroyService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
# 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
)
{
{
# Mutation response is always a `nil` award_emoji
# Mutation response is always a `nil` award_emoji
errors:
[]
errors:
service
[
:errors
]
||
[]
}
}
end
end
end
end
...
...
app/graphql/mutations/award_emojis/toggle.rb
View file @
15b02da6
...
@@ -15,23 +15,15 @@ module Mutations
...
@@ -15,23 +15,15 @@ module Mutations
check_object_is_awardable!
(
awardable
)
check_object_is_awardable!
(
awardable
)
# TODO this will be handled by AwardEmoji::ToggleService
service
=
::
AwardEmojis
::
ToggleService
.
new
(
awardable
,
args
[
:name
],
current_user
).
execute
# 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
)
toggled_on
=
awardable
.
awarded_emoji?
(
args
[
:name
],
current_user
)
toggled_on
=
awardable
.
awarded_emoji?
(
args
[
:name
],
current_user
)
{
{
# For consistency with the AwardEmojis::Remove mutation, only return
# For consistency with the AwardEmojis::Remove mutation, only return
# the AwardEmoji if it was created and not destroyed
# the AwardEmoji if it was created and not destroyed
award_emoji:
(
award
if
toggled_on
),
award_emoji:
(
service
[
:award
]
if
toggled_on
),
errors:
errors
,
errors:
service
[
:errors
]
||
[]
,
toggled_on:
toggled_on
toggled_on:
toggled_on
}
}
end
end
...
...
spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
View file @
15b02da6
...
@@ -5,9 +5,9 @@ require 'spec_helper'
...
@@ -5,9 +5,9 @@ require 'spec_helper'
describe
'Adding an AwardEmoji'
do
describe
'Adding an AwardEmoji'
do
include
GraphqlHelpers
include
GraphqlHelpers
l
et
(
:current_user
)
{
create
(
:user
)
}
s
et
(
:current_user
)
{
create
(
:user
)
}
let
(
:awardable
)
{
create
(
:note
)
}
set
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
awardable
.
project
}
set
(
:awardable
)
{
create
(
:note
,
project:
project
)
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:mutation
)
do
let
(
:mutation
)
do
variables
=
{
variables
=
{
...
@@ -43,7 +43,7 @@ describe 'Adding an AwardEmoji' do
...
@@ -43,7 +43,7 @@ describe 'Adding an AwardEmoji' do
end
end
context
'when the given awardable is not an Awardable'
do
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'
it_behaves_like
'a mutation that does not create an AwardEmoji'
...
@@ -52,7 +52,7 @@ describe 'Adding an AwardEmoji' do
...
@@ -52,7 +52,7 @@ describe 'Adding an AwardEmoji' do
end
end
context
'when the given awardable is an Awardable but still cannot be awarded an emoji'
do
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'
it_behaves_like
'a mutation that does not create an AwardEmoji'
...
@@ -73,6 +73,13 @@ describe 'Adding an AwardEmoji' do
...
@@ -73,6 +73,13 @@ describe 'Adding an AwardEmoji' do
expect
(
mutation_response
[
'awardEmoji'
][
'name'
]).
to
eq
(
emoji_name
)
expect
(
mutation_response
[
'awardEmoji'
][
'name'
]).
to
eq
(
emoji_name
)
end
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
context
'when there were active record validation errors'
do
before
do
before
do
expect_next_instance_of
(
AwardEmoji
)
do
|
award
|
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'
...
@@ -5,9 +5,9 @@ require 'spec_helper'
describe
'Toggling an AwardEmoji'
do
describe
'Toggling an AwardEmoji'
do
include
GraphqlHelpers
include
GraphqlHelpers
l
et
(
:current_user
)
{
create
(
:user
)
}
s
et
(
:current_user
)
{
create
(
:user
)
}
let
(
:awardable
)
{
create
(
:note
)
}
set
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
awardable
.
project
}
set
(
:awardable
)
{
create
(
:note
,
project:
project
)
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:emoji_name
)
{
'thumbsup'
}
let
(
:mutation
)
do
let
(
:mutation
)
do
variables
=
{
variables
=
{
...
@@ -40,7 +40,7 @@ describe 'Toggling an AwardEmoji' do
...
@@ -40,7 +40,7 @@ describe 'Toggling an AwardEmoji' do
end
end
context
'when the given awardable is not an Awardable'
do
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'
it_behaves_like
'a mutation that does not create or destroy an AwardEmoji'
...
@@ -49,7 +49,7 @@ describe 'Toggling an AwardEmoji' do
...
@@ -49,7 +49,7 @@ describe 'Toggling an AwardEmoji' do
end
end
context
'when the given awardable is an Awardable but still cannot be awarded an emoji'
do
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'
it_behaves_like
'a mutation that does not create or destroy an AwardEmoji'
...
@@ -81,6 +81,13 @@ describe 'Toggling an AwardEmoji' do
...
@@ -81,6 +81,13 @@ describe 'Toggling an AwardEmoji' do
expect
(
mutation_response
[
'toggledOn'
]).
to
eq
(
true
)
expect
(
mutation_response
[
'toggledOn'
]).
to
eq
(
true
)
end
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
context
'when there were active record validation errors'
do
before
do
before
do
expect_next_instance_of
(
AwardEmoji
)
do
|
award
|
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