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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
2f9c2149
Commit
2f9c2149
authored
May 25, 2016
by
ZJ van de Weg
Committed by
Z.J. van de Weg
Jun 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend awardables on comments
parent
fc809d68
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
2 deletions
+61
-2
app/assets/javascripts/notes.js.coffee
app/assets/javascripts/notes.js.coffee
+1
-1
app/controllers/concerns/toggle_award_emoji.rb
app/controllers/concerns/toggle_award_emoji.rb
+10
-1
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+3
-0
app/models/note.rb
app/models/note.rb
+1
-0
spec/controllers/projects/notes_controller_spec.rb
spec/controllers/projects/notes_controller_spec.rb
+36
-0
spec/models/note_spec.rb
spec/models/note_spec.rb
+10
-0
No files found.
app/assets/javascripts/notes.js.coffee
View file @
2f9c2149
...
...
@@ -162,7 +162,7 @@ class @Notes
renderNote
:
(
note
)
->
unless
note
.
valid
if
note
.
award
flash
=
new
Flash
(
'You have already
used this award
emoji!'
,
'alert'
)
flash
=
new
Flash
(
'You have already
awarded this
emoji!'
,
'alert'
)
flash
.
pinTo
(
'.header-content'
)
return
...
...
app/controllers/concerns/toggle_award_emoji.rb
View file @
2f9c2149
...
...
@@ -9,13 +9,22 @@ module ToggleAwardEmoji
name
=
params
.
require
(
:name
)
awardable
.
toggle_award_emoji
(
name
,
current_user
)
TodoService
.
new
.
new_award_emoji
(
awardable
,
current_user
)
TodoService
.
new
.
new_award_emoji
(
to_todoable
(
awardable
)
,
current_user
)
render
json:
{
ok:
true
}
end
private
def
to_todoable
(
awardable
)
case
awardable
when
Note
awardable
.
noteable
else
awardable
end
end
def
awardable
raise
NotImplementedError
end
...
...
app/controllers/projects/notes_controller.rb
View file @
2f9c2149
class
Projects::NotesController
<
Projects
::
ApplicationController
include
ToggleAwardEmoji
# Authorize
before_action
:authorize_read_note!
before_action
:authorize_create_note!
,
only:
[
:create
]
...
...
@@ -61,6 +63,7 @@ class Projects::NotesController < Projects::ApplicationController
def
note
@note
||=
@project
.
notes
.
find
(
params
[
:id
])
end
alias_method
:awardable
,
:note
def
note_to_html
(
note
)
render_to_string
(
...
...
app/models/note.rb
View file @
2f9c2149
...
...
@@ -3,6 +3,7 @@ class Note < ActiveRecord::Base
include
Gitlab
::
CurrentSettings
include
Participable
include
Mentionable
include
Awardable
default_value_for
:system
,
false
...
...
spec/controllers/projects/notes_controller_spec.rb
0 → 100644
View file @
2f9c2149
require
(
'spec_helper'
)
describe
Projects
::
NotesController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:note
)
{
create
(
:note
,
noteable:
issue
,
project:
project
)
}
describe
'POST #toggle_award_emoji'
do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
it
"toggles the award emoji"
do
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
"removes the already let award emoji"
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
end
spec/models/note_spec.rb
View file @
2f9c2149
...
...
@@ -9,6 +9,16 @@ describe Note, models: true do
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
end
describe
'modules'
do
subject
{
described_class
}
it
{
is_expected
.
to
include_module
(
Participable
)
}
it
{
is_expected
.
to
include_module
(
Mentionable
)
}
it
{
is_expected
.
to
include_module
(
Awardable
)
}
it
{
is_expected
.
to
include_module
(
Gitlab
::
CurrentSettings
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:note
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
...
...
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