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
d8c77ab2
Commit
d8c77ab2
authored
Jul 28, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tag feature
parent
4edecb12
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
4 deletions
+57
-4
app.rb
+5
-0
models/comment_thread.rb
+9
-4
spec/comment_thread_spec.rb
+33
-0
spec/commentable_spec.rb
+10
-0
No files found.
app.rb
View file @
d8c77ab2
...
...
@@ -32,6 +32,7 @@ end
post
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
.
tags
=
params
[
"tags"
]
||
""
thread
.
author
=
user
thread
.
save!
if
params
[
"auto_subscribe"
]
and
author
...
...
@@ -46,6 +47,10 @@ end
put
'/api/v1/threads/:thread_id'
do
|
thread_id
|
thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
if
params
[
"tags"
]
thread
.
tags
=
params
[
"tags"
]
thread
.
save!
end
thread
.
to_hash
.
to_json
end
...
...
models/comment_thread.rb
View file @
d8c77ab2
...
...
@@ -20,6 +20,9 @@ class CommentThread < Content
string
:course_id
string
:commentable_id
string
:author_id
string
:tags
,
multiple:
true
do
end
end
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
,
autosave:
true
...
...
@@ -53,10 +56,12 @@ class CommentThread < Content
end
def
to_hash
(
params
=
{})
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]
))
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]
))
.
merge
(
"tags"
=>
tags_array
)
if
params
[
:recursive
]
doc
=
doc
.
merge
(
"children"
=>
root_comments
.
map
{
|
c
|
c
.
to_hash
(
recursive:
true
)})
end
...
...
spec/comment_thread_spec.rb
View file @
d8c77ab2
...
...
@@ -32,6 +32,23 @@ describe "app" do
get
"/api/v1/threads/does_not_exist"
last_response
.
status
.
should
==
400
end
it
"get information of a single comment thread with its tags"
do
thread
=
CommentThread
.
new
thread
.
title
=
"new thread"
thread
.
body
=
"hahaah"
thread
.
course_id
=
"1"
thread
.
commentable_id
=
"1"
thread
.
author
=
User
.
first
thread
.
tags
=
"taga, tagb, tagc"
thread
.
save!
get
"/api/v1/threads/
#{
thread
.
id
}
"
last_response
.
should
be_ok
response_thread
=
parse
last_response
.
body
response_thread
[
"tags"
].
length
.
should
==
3
response_thread
[
"tags"
].
should
include
"taga"
response_thread
[
"tags"
].
should
include
"tagb"
response_thread
[
"tags"
].
should
include
"tagc"
end
end
describe
"PUT /api/v1/threads/:thread_id"
do
it
"update information of comment thread"
do
...
...
@@ -46,6 +63,22 @@ describe "app" do
put
"/api/v1/threads/does_not_exist"
,
body:
"new body"
,
title:
"new title"
last_response
.
status
.
should
==
400
end
it
"updates tag of comment thread"
do
thread
=
CommentThread
.
first
put
"/api/v1/threads/
#{
thread
.
id
}
"
,
tags:
"haha, hoho, huhu"
last_response
.
should
be_ok
thread
.
reload
thread
.
tags_array
.
length
.
should
==
3
thread
.
tags_array
.
should
include
"haha"
thread
.
tags_array
.
should
include
"hoho"
thread
.
tags_array
.
should
include
"huhu"
put
"/api/v1/threads/
#{
thread
.
id
}
"
,
tags:
"aha, oho"
last_response
.
should
be_ok
thread
.
reload
thread
.
tags_array
.
length
.
should
==
2
thread
.
tags_array
.
should
include
"aha"
thread
.
tags_array
.
should
include
"oho"
end
end
describe
"POST /api/v1/threads/:thread_id/comments"
do
it
"create a comment to the comment thread"
do
...
...
spec/commentable_spec.rb
View file @
d8c77ab2
...
...
@@ -68,6 +68,16 @@ describe "app" do
Commentable
.
find
(
"does_not_exist"
).
comment_threads
.
length
.
should
==
1
Commentable
.
find
(
"does_not_exist"
).
comment_threads
.
first
.
body
.
should
==
"cool"
end
it
"create a new comment thread with tag"
do
post
'/api/v1/question_1/threads'
,
title:
"Interesting question"
,
body:
"cool"
,
course_id:
"1"
,
user_id:
"1"
,
tags:
"a, b, c"
last_response
.
should
be_ok
CommentThread
.
count
.
should
==
3
thread
=
CommentThread
.
where
(
title:
"Interesting question"
).
first
thread
.
tags_array
.
length
.
should
==
3
thread
.
tags_array
.
should
include
"a"
thread
.
tags_array
.
should
include
"b"
thread
.
tags_array
.
should
include
"c"
end
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