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
73a39949
Commit
73a39949
authored
Jul 20, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return id instead of _id to hide mongo implementation detail
parent
6bb64416
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
11 deletions
+13
-11
models/comment.rb
+2
-1
models/comment_thread.rb
+2
-1
models/notification.rb
+1
-1
models/subscription.rb
+1
-1
spec/app_spec.rb
+7
-7
No files found.
models/comment.rb
View file @
73a39949
...
...
@@ -47,7 +47,8 @@ class Comment < Content
if
params
[
:recursive
]
self
.
class
.
hash_tree
(
subtree
(
sort:
sort_by_parent_and_time
)).
first
else
as_document
.
slice
(
*
%w[body course_id endorsed _id created_at updated_at]
).
as_document
.
slice
(
*
%w[body course_id endorsed created_at updated_at]
).
merge
(
"id"
=>
_id
).
merge
(
"user_id"
=>
author
.
id
).
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
end
...
...
models/comment_thread.rb
View file @
73a39949
...
...
@@ -37,7 +37,8 @@ class CommentThread < Content
end
def
to_hash
(
params
=
{})
doc
=
as_document
.
slice
(
*
%w[title body course_id _id created_at updated_at]
).
doc
=
as_document
.
slice
(
*
%w[title body course_id created_at updated_at]
).
merge
(
"id"
=>
_id
).
merge
(
"user_id"
=>
(
author
.
id
if
author
)).
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
if
params
[
:recursive
]
...
...
models/notification.rb
View file @
73a39949
...
...
@@ -17,6 +17,6 @@ class Notification
has_and_belongs_to_many
:receivers
,
class_name:
"User"
,
inverse_of: :notifications
,
autosave:
true
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[
_id notification_type info actor target]
)
as_document
.
slice
(
*
%w[
notification_type info actor target]
).
merge
(
"id"
=>
_id
)
end
end
models/subscription.rb
View file @
73a39949
...
...
@@ -9,7 +9,7 @@ class Subscription
index
[[
:subscriber_id
,
Mongo
::
ASCENDING
],
[
:source_id
,
Mongo
::
ASCENDING
],
[
:source_type
,
Mongo
::
ASCENDING
]]
def
to_hash
as_document
as_document
.
slice
(
*
%w[subscriber_id source_id source_type]
)
end
def
subscriber
...
...
spec/app_spec.rb
View file @
73a39949
...
...
@@ -199,9 +199,9 @@ describe "app" do
it
"create a comment to the comment thread"
do
thread
=
CommentThread
.
first
.
to_hash
(
recursive:
true
)
user
=
User
.
first
post
"/api/v1/threads/
#{
thread
[
"
_
id"
]
}
/comments"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
post
"/api/v1/threads/
#{
thread
[
"id"
]
}
/comments"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
last_response
.
should
be_ok
changed_thread
=
CommentThread
.
find
(
thread
[
"
_
id"
]).
to_hash
(
recursive:
true
)
changed_thread
=
CommentThread
.
find
(
thread
[
"id"
]).
to_hash
(
recursive:
true
)
changed_thread
[
"children"
].
length
.
should
==
thread
[
"children"
].
length
+
1
comment
=
changed_thread
[
"children"
].
select
{
|
c
|
c
[
"body"
]
==
"new comment"
}.
first
comment
.
should_not
be_nil
...
...
@@ -211,7 +211,7 @@ describe "app" do
describe
"DELETE /api/v1/threads/:thread_id"
do
it
"delete the comment thread and its comments"
do
thread
=
CommentThread
.
first
.
to_hash
delete
"/api/v1/threads/
#{
thread
[
'
_
id'
]
}
"
delete
"/api/v1/threads/
#{
thread
[
'id'
]
}
"
last_response
.
should
be_ok
CommentThread
.
where
(
title:
thread
[
"title"
]).
first
.
should
be_nil
end
...
...
@@ -228,7 +228,7 @@ describe "app" do
retrieved
=
parse
last_response
.
body
retrieved
[
"body"
].
should
==
comment
.
body
retrieved
[
"endorsed"
].
should
==
comment
.
endorsed
retrieved
[
"
_
id"
].
should
==
comment
.
id
.
to_s
retrieved
[
"id"
].
should
==
comment
.
id
.
to_s
retrieved
[
"children"
].
should
be_nil
retrieved
[
"votes"
][
"point"
].
should
==
comment
.
votes_point
end
...
...
@@ -239,7 +239,7 @@ describe "app" do
retrieved
=
parse
last_response
.
body
retrieved
[
"body"
].
should
==
comment
.
body
retrieved
[
"endorsed"
].
should
==
comment
.
endorsed
retrieved
[
"
_
id"
].
should
==
comment
.
id
.
to_s
retrieved
[
"id"
].
should
==
comment
.
id
.
to_s
retrieved
[
"votes"
][
"point"
].
should
==
comment
.
votes_point
retrieved
[
"children"
].
length
.
should
==
comment
.
children
.
length
retrieved
[
"children"
].
select
{
|
c
|
c
[
"body"
]
==
comment
.
children
.
first
.
body
}.
first
.
should_not
be_nil
...
...
@@ -259,9 +259,9 @@ describe "app" do
it
"create a sub comment to the comment"
do
comment
=
Comment
.
first
.
to_hash
(
recursive:
true
)
user
=
User
.
first
post
"/api/v1/comments/
#{
comment
[
"
_
id"
]
}
"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
post
"/api/v1/comments/
#{
comment
[
"id"
]
}
"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
last_response
.
should
be_ok
changed_comment
=
Comment
.
find
(
comment
[
"
_
id"
]).
to_hash
(
recursive:
true
)
changed_comment
=
Comment
.
find
(
comment
[
"id"
]).
to_hash
(
recursive:
true
)
changed_comment
[
"children"
].
length
.
should
==
comment
[
"children"
].
length
+
1
subcomment
=
changed_comment
[
"children"
].
select
{
|
c
|
c
[
"body"
]
==
"new comment"
}.
first
subcomment
.
should_not
be_nil
...
...
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