Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
7cc9a131
Commit
7cc9a131
authored
Aug 24, 2016
by
Toby Lawrence
Committed by
GitHub
Aug 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #204 from edx/perf/pluck-not-map-voting-ids
Plucking instead of mapping.
parents
3d902ee8
e9435879
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
+58
-2
models/user.rb
+2
-2
spec/api/user_spec.rb
+23
-0
spec/models/user_spec.rb
+22
-0
spec/spec_helper.rb
+11
-0
No files found.
models/user.rb
View file @
7cc9a131
...
...
@@ -111,11 +111,11 @@ class User
end
def
upvoted_ids
Content
.
up_voted_by
(
self
).
map
(
&
:
id
)
Content
.
up_voted_by
(
self
).
pluck
(
:_
id
)
end
def
downvoted_ids
Content
.
down_voted_by
(
self
).
map
(
&
:
id
)
Content
.
down_voted_by
(
self
).
pluck
(
:_
id
)
end
def
followers
...
...
spec/api/user_spec.rb
View file @
7cc9a131
...
...
@@ -45,7 +45,12 @@ describe "app" do
last_response
.
status
.
should
==
400
end
end
describe
"GET /api/v1/users/:user_id"
do
let
(
:author
)
{
User
.
find_by
(
external_id:
"1"
)
}
let
(
:reader
)
{
User
.
find_by
(
external_id:
"2"
)
}
let
(
:thread
)
{
make_standalone_thread
(
author
)
}
it
"returns user information"
do
get
"/api/v1/users/1"
last_response
.
status
.
should
==
200
...
...
@@ -54,10 +59,28 @@ describe "app" do
res
[
"external_id"
].
should
==
user1
.
external_id
res
[
"username"
].
should
==
user1
.
username
end
it
"returns 404 if user does not exist"
do
get
"/api/v1/users/3"
last_response
.
status
.
should
==
404
end
it
"returns no threads when user hasn't voted"
do
get
"/api/v1/users/1"
,
complete:
"true"
last_response
.
status
.
should
==
200
res
=
parse
(
last_response
.
body
)
res
[
"upvoted_ids"
].
should
==
[]
end
it
"returns threads when user votes"
do
reader
.
vote
(
thread
,
:up
)
get
"/api/v1/users/2"
,
complete:
"true"
last_response
.
status
.
should
==
200
res
=
parse
(
last_response
.
body
)
res
[
"upvoted_ids"
].
should
==
[
thread
.
id
.
to_s
]
end
describe
"Returns threads_count and comments_count"
do
before
(
:each
)
{
setup_10_threads
}
...
...
spec/models/user_spec.rb
0 → 100644
View file @
7cc9a131
require
'spec_helper'
require
'unicode_shared_examples'
describe
User
do
let
(
:author
)
{
create_test_user
(
666
)
}
let
(
:reader
)
{
create_test_user
(
667
)
}
let
(
:thread
)
{
make_standalone_thread
(
author
)
}
before
(
:each
)
do
[
Comment
,
CommentThread
,
User
].
each
(
&
:delete_all
).
each
(
&
:remove_indexes
).
each
(
&
:create_indexes
)
end
it
"should have no votes if it never voted"
do
reader
.
upvoted_ids
.
should
==
[]
end
it
"should have one vote if it voted once"
do
reader
.
upvoted_ids
.
should
==
[]
reader
.
vote
(
thread
,
:up
)
reader
.
upvoted_ids
.
should
==
[
thread
.
_id
]
end
end
spec/spec_helper.rb
View file @
7cc9a131
...
...
@@ -342,6 +342,17 @@ def make_comment(author, parent, text)
comment
end
def
make_standalone_thread
(
author
)
make_thread
(
author
,
"standalone thread 0"
,
DFLT_COURSE_ID
,
"pdq"
,
:discussion
,
:standalone
)
end
# add standalone threads and comments to the @threads and @comments hashes
# using the namespace "standalone t#{index}" for threads and "standalone t#{index} c#{i}" for comments
# takes an index param if used within an iterator, otherwise will namespace using 0 for thread index
...
...
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