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
b45a2b8f
Commit
b45a2b8f
authored
Jul 26, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more specs & fixed bugs caused by anonymity
parent
f8f8e800
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
8 deletions
+59
-8
models/comment.rb
+7
-3
models/comment_thread.rb
+6
-2
models/notification.rb
+0
-1
spec/app_spec.rb
+46
-2
No files found.
models/comment.rb
View file @
b45a2b8f
...
...
@@ -41,7 +41,7 @@ class Comment < Content
else
as_document
.
slice
(
*
%w[body course_id endorsed created_at updated_at]
).
merge
(
"id"
=>
_id
).
merge
(
"user_id"
=>
author
.
id
).
merge
(
"user_id"
=>
(
author
.
id
if
author
)
).
merge
(
"thread_id"
=>
comment_thread
.
id
).
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
end
...
...
@@ -61,8 +61,12 @@ private
)
notification
.
actor
=
author
notification
.
target
=
self
notification
.
receivers
<<
(
comment_thread
.
subscribers
+
author
.
followers
).
uniq_by
(
&
:id
)
notification
.
receivers
.
delete
(
author
)
receivers
=
comment_thread
.
subscribers
if
author
receivers
=
(
receivers
+
author
.
followers
).
uniq_by
(
&
:id
)
end
receivers
.
delete
(
author
)
notification
.
receivers
<<
receivers
notification
.
save!
end
end
...
...
models/comment_thread.rb
View file @
b45a2b8f
...
...
@@ -83,8 +83,12 @@ private
)
notification
.
actor
=
author
notification
.
target
=
self
notification
.
receivers
<<
(
commentable
.
subscribers
+
author
.
followers
).
uniq_by
(
&
:id
)
notification
.
receivers
.
delete
(
author
)
receivers
=
commentable
.
subscribers
if
author
receivers
=
(
receivers
+
author
.
followers
).
uniq_by
(
&
:id
)
end
receivers
.
delete
(
author
)
notification
.
receivers
<<
receivers
notification
.
save!
end
end
...
...
models/notification.rb
View file @
b45a2b8f
...
...
@@ -11,7 +11,6 @@ class Notification
attr_accessible
:notification_type
,
:info
validates_presence_of
:notification_type
validates_presence_of
:actor
if
not
CommentService
.
config
[
"allow_anonymity"
]
validates_presence_of
:target
has_and_belongs_to_many
:receivers
,
class_name:
"User"
,
inverse_of: :notifications
,
autosave:
true
...
...
spec/app_spec.rb
View file @
b45a2b8f
...
...
@@ -129,12 +129,16 @@ describe "app" do
last_response
.
should
be_ok
Commentable
.
find
(
"question_1"
).
comment_threads
.
count
.
should
==
0
end
it
"handle normally when commentable does not exist"
do
delete
'/api/v1/does_not_exist/threads'
last_response
.
should
be_ok
end
end
describe
"GET /api/v1/:commentable_id/threads"
do
it
"get all comment threads associated with a commentable object"
do
get
"/api/v1/question_1/threads"
last_response
.
should
be_ok
threads
=
Yajl
::
Parser
.
parse
last_response
.
body
threads
=
parse
last_response
.
body
threads
.
length
.
should
==
2
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
...
...
@@ -142,7 +146,7 @@ describe "app" do
it
"get all comment threads and comments associated with a commentable object"
do
get
"/api/v1/question_1/threads"
,
recursive:
true
last_response
.
should
be_ok
threads
=
Yajl
::
Parser
.
parse
last_response
.
body
threads
=
parse
last_response
.
body
threads
.
length
.
should
==
2
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
...
...
@@ -158,6 +162,12 @@ describe "app" do
not_for_me
[
"children"
].
length
.
should
==
1
not_for_me
[
"children"
].
first
[
"body"
].
should
==
"not for me neither!"
end
it
"returns an empty array when the commentable object does not exist (no threads)"
do
get
"/api/v1/does_not_exist/threads"
last_response
.
should
be_ok
threads
=
parse
last_response
.
body
threads
.
length
.
should
==
0
end
end
describe
"POST /api/v1/:commentable_id/threads"
do
it
"create a new comment thread for the commentable object"
do
...
...
@@ -166,8 +176,21 @@ describe "app" do
CommentThread
.
count
.
should
==
3
CommentThread
.
where
(
title:
"Interesting question"
).
first
.
should_not
be_nil
end
it
"allows anonymous thread"
do
post
'/api/v1/question_1/threads'
,
title:
"Interesting question"
,
body:
"cool"
,
course_id:
"1"
last_response
.
should
be_ok
CommentThread
.
count
.
should
==
3
CommentThread
.
where
(
title:
"Interesting question"
).
first
.
should_not
be_nil
end
it
"create a new comment thread for a new commentable object"
do
post
'/api/v1/does_not_exist/threads'
,
title:
"Interesting question"
,
body:
"cool"
,
course_id:
"1"
,
user_id:
"1"
last_response
.
should
be_ok
Commentable
.
find
(
"does_not_exist"
).
comment_threads
.
length
.
should
==
1
Commentable
.
find
(
"does_not_exist"
).
comment_threads
.
first
.
body
.
should
==
"cool"
end
end
end
describe
"comment threads"
do
before
(
:each
)
{
init_without_subscriptions
}
describe
"GET /api/v1/threads/:thread_id"
do
...
...
@@ -195,6 +218,10 @@ describe "app" do
response_thread
[
"children"
].
length
.
should
==
thread
.
root_comments
.
length
response_thread
[
"children"
].
index
{
|
c
|
c
[
"body"
]
==
thread
.
root_comments
.
first
.
body
}.
should_not
be_nil
end
it
"returns error message when the thread does not exist"
do
get
"/api/v1/threads/does_not_exist"
last_response
.
status
.
should
==
404
end
end
describe
"PUT /api/v1/threads/:thread_id"
do
it
"update information of comment thread"
do
...
...
@@ -205,6 +232,10 @@ describe "app" do
changed_thread
.
body
.
should
==
"new body"
changed_thread
.
title
.
should
==
"new title"
end
it
"returns error message when the thread does not exist"
do
put
"/api/v1/threads/does_not_exist"
,
body:
"new body"
,
title:
"new title"
last_response
.
status
.
should
==
404
end
end
describe
"POST /api/v1/threads/:thread_id/comments"
do
it
"create a comment to the comment thread"
do
...
...
@@ -218,6 +249,19 @@ describe "app" do
comment
.
should_not
be_nil
comment
[
"user_id"
].
should
==
user
.
id
end
it
"allows anonymous comment"
do
thread
=
CommentThread
.
first
.
to_hash
(
recursive:
true
)
post
"/api/v1/threads/
#{
thread
[
"id"
]
}
/comments"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
nil
last_response
.
should
be_ok
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
end
it
"returns error message when the thread does not exist"
do
post
"/api/v1/threads/does_not_exist/comments"
,
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
last_response
.
status
.
should
==
404
end
end
describe
"DELETE /api/v1/threads/:thread_id"
do
it
"delete the comment thread and its comments"
do
...
...
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