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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
f7c70eaa
Commit
f7c70eaa
authored
Sep 11, 2012
by
Riyad Preukschas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add *votes_in_percent
parent
a5164ea2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
app/roles/votes.rb
app/roles/votes.rb
+16
-0
spec/roles/votes_spec.rb
spec/roles/votes_spec.rb
+50
-0
No files found.
app/roles/votes.rb
View file @
f7c70eaa
...
...
@@ -4,11 +4,27 @@ module Votes
notes
.
select
(
&
:upvote?
).
size
end
def
upvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
/
votes_count
*
upvotes
end
end
# Return the number of -1 comments (downvotes)
def
downvotes
notes
.
select
(
&
:downvote?
).
size
end
def
downvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
-
upvotes_in_percent
end
end
# Return the total number of votes
def
votes_count
upvotes
+
downvotes
...
...
spec/roles/votes_spec.rb
View file @
f7c70eaa
...
...
@@ -79,4 +79,54 @@ describe Issue do
issue
.
votes_count
.
should
==
3
end
end
describe
"#upvotes_in_percent"
do
it
"with no notes has a 0% score"
do
issue
.
upvotes_in_percent
.
should
==
0
end
it
"should count a single 1 note as 100%"
do
issue
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
issue
.
upvotes_in_percent
.
should
==
100
end
it
"should count multiple +1 notes as 100%"
do
issue
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
issue
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
issue
.
upvotes_in_percent
.
should
==
100
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
issue
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
issue
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
issue
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
issue
.
notes
<<
create
(
:note
,
note:
"+1 me too"
)
issue
.
upvotes_in_percent
.
should
==
75
end
end
describe
"#downvotes_in_percent"
do
it
"with no notes has a 0% score"
do
issue
.
downvotes_in_percent
.
should
==
0
end
it
"should count a single -1 note as 100%"
do
issue
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
issue
.
downvotes_in_percent
.
should
==
100
end
it
"should count multiple -1 notes as 100%"
do
issue
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
issue
.
notes
<<
create
(
:note
,
note:
"-1 Away with this"
)
issue
.
downvotes_in_percent
.
should
==
100
end
it
"should count fractions for multiple +1 and -1 notes correctly"
do
issue
.
notes
<<
create
(
:note
,
note:
"+1 This is awesome"
)
issue
.
notes
<<
create
(
:note
,
note:
"+1 I want this"
)
issue
.
notes
<<
create
(
:note
,
note:
"-1 This is bad"
)
issue
.
notes
<<
create
(
:note
,
note:
"+1 me too"
)
issue
.
downvotes_in_percent
.
should
==
25
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