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
Léo-Paul Géneau
gitlab-ce
Commits
581b2c5e
Commit
581b2c5e
authored
9 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'vote-count' of
https://github.com/mc1arke/gitlabhq
into mc1arke-vote-count
Conflicts: CHANGELOG
parents
111d95f7
505a492c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
36 deletions
+128
-36
CHANGELOG
CHANGELOG
+1
-0
app/assets/stylesheets/generic/typography.scss
app/assets/stylesheets/generic/typography.scss
+4
-0
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+14
-2
app/models/note.rb
app/models/note.rb
+17
-0
app/views/projects/notes/_note.html.haml
app/views/projects/notes/_note.html.haml
+18
-8
spec/lib/votes_spec.rb
spec/lib/votes_spec.rb
+74
-26
No files found.
CHANGELOG
View file @
581b2c5e
...
@@ -15,6 +15,7 @@ v 7.8.0
...
@@ -15,6 +15,7 @@ v 7.8.0
-
-
-
-
- Show tags in commit view (Hannes Rosenögger)
- Show tags in commit view (Hannes Rosenögger)
- Only count a user's vote once on a merge request or issue (Michael Clarke)
-
-
-
-
-
-
...
...
This diff is collapsed.
Click to expand it.
app/assets/stylesheets/generic/typography.scss
View file @
581b2c5e
...
@@ -128,3 +128,7 @@ a:focus {
...
@@ -128,3 +128,7 @@ a:focus {
textarea
.js-gfm-input
{
textarea
.js-gfm-input
{
font-family
:
$monospace_font
;
font-family
:
$monospace_font
;
}
}
.strikethrough
{
text-decoration
:
line-through
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/models/concerns/issuable.rb
View file @
581b2c5e
...
@@ -88,7 +88,7 @@ module Issuable
...
@@ -88,7 +88,7 @@ module Issuable
# Return the number of -1 comments (downvotes)
# Return the number of -1 comments (downvotes)
def
downvotes
def
downvotes
notes
.
select
(
&
:downvote?
).
size
filter_superceded_votes
(
notes
.
select
(
&
:downvote?
),
notes
).
size
end
end
def
downvotes_in_percent
def
downvotes_in_percent
...
@@ -101,7 +101,7 @@ module Issuable
...
@@ -101,7 +101,7 @@ module Issuable
# Return the number of +1 comments (upvotes)
# Return the number of +1 comments (upvotes)
def
upvotes
def
upvotes
notes
.
select
(
&
:upvote?
).
size
filter_superceded_votes
(
notes
.
select
(
&
:upvote?
),
notes
).
size
end
end
def
upvotes_in_percent
def
upvotes_in_percent
...
@@ -154,4 +154,16 @@ module Issuable
...
@@ -154,4 +154,16 @@ module Issuable
self
.
labels
<<
label
self
.
labels
<<
label
end
end
end
end
private
def
filter_superceded_votes
(
votes
,
notes
)
filteredvotes
=
[]
+
votes
votes
.
each
do
|
vote
|
if
vote
.
superceded?
(
notes
)
filteredvotes
.
delete
(
vote
)
end
end
filteredvotes
end
end
end
This diff is collapsed.
Click to expand it.
app/models/note.rb
View file @
581b2c5e
...
@@ -459,6 +459,23 @@ class Note < ActiveRecord::Base
...
@@ -459,6 +459,23 @@ class Note < ActiveRecord::Base
)
)
end
end
def
superceded?
(
notes
)
return
false
unless
vote?
notes
.
each
do
|
note
|
next
if
note
==
self
if
note
.
vote?
&&
self
[
:author_id
]
==
note
[
:author_id
]
&&
self
[
:created_at
]
<=
note
[
:created_at
]
return
true
end
end
false
end
def
vote?
upvote?
||
downvote?
end
def
votable?
def
votable?
for_issue?
||
(
for_merge_request?
&&
!
for_diff_line?
)
for_issue?
||
(
for_merge_request?
&&
!
for_diff_line?
)
end
end
...
...
This diff is collapsed.
Click to expand it.
app/views/projects/notes/_note.html.haml
View file @
581b2c5e
...
@@ -28,6 +28,16 @@
...
@@ -28,6 +28,16 @@
%span
.note-last-update
%span
.note-last-update
=
note_timestamp
(
note
)
=
note_timestamp
(
note
)
-
if
note
.
superceded?
(
@notes
)
-
if
note
.
upvote?
%span
.vote.upvote.label.label-gray.strikethrough
%i
.fa.fa-thumbs-up
\+1
-
if
note
.
downvote?
%span
.vote.downvote.label.label-gray.strikethrough
%i
.fa.fa-thumbs-down
\-1
-
else
-
if
note
.
upvote?
-
if
note
.
upvote?
%span
.vote.upvote.label.label-success
%span
.vote.upvote.label.label-success
%i
.fa.fa-thumbs-up
%i
.fa.fa-thumbs-up
...
...
This diff is collapsed.
Click to expand it.
spec/lib/votes_spec.rb
View file @
581b2c5e
...
@@ -20,11 +20,17 @@ describe Issue, 'Votes' do
...
@@ -20,11 +20,17 @@ describe Issue, 'Votes' do
issue
.
upvotes
.
should
==
1
issue
.
upvotes
.
should
==
1
end
end
it
"should recognize multiple +1 notes"
do
it
'should recognize multiple +1 notes'
do
add_note
"+1 This is awesome"
add_note
'+1 This is awesome'
,
create
(
:user
)
add_note
"+1 I want this"
add_note
'+1 I want this'
,
create
(
:user
)
issue
.
upvotes
.
should
==
2
issue
.
upvotes
.
should
==
2
end
end
it
'should not count 2 +1 votes from the same user'
do
add_note
'+1 This is awesome'
add_note
'+1 I want this'
issue
.
upvotes
.
should
==
1
end
end
end
describe
"#downvotes"
do
describe
"#downvotes"
do
...
@@ -45,8 +51,8 @@ describe Issue, 'Votes' do
...
@@ -45,8 +51,8 @@ describe Issue, 'Votes' do
end
end
it
"should recognize multiple -1 notes"
do
it
"should recognize multiple -1 notes"
do
add_note
"-1 This is bad"
add_note
(
'-1 This is bad'
,
create
(
:user
))
add_note
"-1 Away with this"
add_note
(
'-1 Away with this'
,
create
(
:user
))
issue
.
downvotes
.
should
==
2
issue
.
downvotes
.
should
==
2
end
end
end
end
...
@@ -73,11 +79,17 @@ describe Issue, 'Votes' do
...
@@ -73,11 +79,17 @@ describe Issue, 'Votes' do
end
end
it
"should recognize multiple notes"
do
it
"should recognize multiple notes"
do
add_note
"+1 This is awesome"
add_note
(
'+1 This is awesome'
,
create
(
:user
))
add_note
"-1 This is bad"
add_note
(
'-1 This is bad'
,
create
(
:user
))
add_note
"+1 I want this"
add_note
(
'+1 I want this'
,
create
(
:user
))
issue
.
votes_count
.
should
==
3
issue
.
votes_count
.
should
==
3
end
end
it
'should not count 2 -1 votes from the same user'
do
add_note
'-1 This is suspicious'
add_note
'-1 This is bad'
issue
.
votes_count
.
should
==
1
end
end
end
describe
"#upvotes_in_percent"
do
describe
"#upvotes_in_percent"
do
...
@@ -90,17 +102,17 @@ describe Issue, 'Votes' do
...
@@ -90,17 +102,17 @@ describe Issue, 'Votes' do
issue
.
upvotes_in_percent
.
should
==
100
issue
.
upvotes_in_percent
.
should
==
100
end
end
it
"should count multiple +1 notes as 100%"
do
it
'should count multiple +1 notes as 100%'
do
add_note
"+1 This is awesome"
add_note
(
'+1 This is awesome'
,
create
(
:user
))
add_note
"+1 I want this"
add_note
(
'+1 I want this'
,
create
(
:user
))
issue
.
upvotes_in_percent
.
should
==
100
issue
.
upvotes_in_percent
.
should
==
100
end
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
it
'should count fractions for multiple +1 and -1 notes correctly'
do
add_note
"+1 This is awesome"
add_note
(
'+1 This is awesome'
,
create
(
:user
))
add_note
"+1 I want this"
add_note
(
'+1 I want this'
,
create
(
:user
))
add_note
"-1 This is bad"
add_note
(
'-1 This is bad'
,
create
(
:user
))
add_note
"+1 me too"
add_note
(
'+1 me too'
,
create
(
:user
))
issue
.
upvotes_in_percent
.
should
==
75
issue
.
upvotes_in_percent
.
should
==
75
end
end
end
end
...
@@ -115,22 +127,58 @@ describe Issue, 'Votes' do
...
@@ -115,22 +127,58 @@ describe Issue, 'Votes' do
issue
.
downvotes_in_percent
.
should
==
100
issue
.
downvotes_in_percent
.
should
==
100
end
end
it
"should count multiple -1 notes as 100%"
do
it
'should count multiple -1 notes as 100%'
do
add_note
"-1 This is bad"
add_note
(
'-1 This is bad'
,
create
(
:user
))
add_note
"-1 Away with this"
add_note
(
'-1 Away with this'
,
create
(
:user
))
issue
.
downvotes_in_percent
.
should
==
100
issue
.
downvotes_in_percent
.
should
==
100
end
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
it
'should count fractions for multiple +1 and -1 notes correctly'
do
add_note
"+1 This is awesome"
add_note
(
'+1 This is awesome'
,
create
(
:user
))
add_note
"+1 I want this"
add_note
(
'+1 I want this'
,
create
(
:user
))
add_note
"-1 This is bad"
add_note
(
'-1 This is bad'
,
create
(
:user
))
add_note
"+1 me too"
add_note
(
'+1 me too'
,
create
(
:user
))
issue
.
downvotes_in_percent
.
should
==
25
issue
.
downvotes_in_percent
.
should
==
25
end
end
end
end
def
add_note
(
text
)
describe
'#filter_superceded_votes'
do
issue
.
notes
<<
create
(
:note
,
note:
text
,
project:
issue
.
project
)
it
'should count a users vote only once amongst multiple votes'
do
add_note
(
'-1 This needs work before I will accept it'
)
add_note
(
'+1 I want this'
,
create
(
:user
))
add_note
(
'+1 This is is awesome'
,
create
(
:user
))
add_note
(
'+1 this looks good now'
)
add_note
(
'+1 This is awesome'
,
create
(
:user
))
add_note
(
'+1 me too'
,
create
(
:user
))
issue
.
downvotes
.
should
==
0
issue
.
upvotes
.
should
==
5
end
it
'should count each users vote only once'
do
add_note
'-1 This needs work before it will be accepted'
add_note
'+1 I like this'
add_note
'+1 I still like this'
add_note
'+1 I really like this'
add_note
'+1 Give me this now!!!!'
p
issue
.
downvotes
.
should
==
0
p
issue
.
upvotes
.
should
==
1
end
it
'should count a users vote only once without caring about comments'
do
add_note
'-1 This needs work before it will be accepted'
add_note
'Comment 1'
add_note
'Another comment'
add_note
'+1 vote'
add_note
'final comment'
p
issue
.
downvotes
.
should
==
0
p
issue
.
upvotes
.
should
==
1
end
end
def
add_note
(
text
,
author
=
issue
.
author
)
issue
.
notes
<<
create
(
:note
,
note:
text
,
project:
issue
.
project
,
author_id:
author
.
id
)
end
end
end
end
This diff is collapsed.
Click to expand it.
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