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
bc407596
Commit
bc407596
authored
Jul 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed comment_thread to thread & removed commentable in url
parent
83989fc2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
141 deletions
+140
-141
app.rb
+45
-46
models/comment.rb
+2
-2
models/comment_thread.rb
+2
-2
spec/app_spec.rb
+91
-91
No files found.
app.rb
View file @
bc407596
...
...
@@ -21,68 +21,67 @@ Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file}
# DELETE /api/v1/commentables/:commentable_type/:commentable_id
# delete the commentable object and all of its associated comment threads and comments
delete
'/api/v1/commentables/:commentable_type/:commentable_id'
do
|
commentable_type
,
commentable_id
|
delete
'/api/v1/:commentable_type/:commentable_id/comments'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_initialize_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
.
destroy
commentable
.
to_hash
.
to_json
end
# GET /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads
# GET /api/v1/commentables/:commentable_type/:commentable_id/threads
# get all comment threads associated with a commentable object
# additional parameters accepted: recursive
get
'/api/v1/
commentables/:commentable_type/:commentable_id/comment_
threads'
do
|
commentable_type
,
commentable_id
|
get
'/api/v1/
:commentable_type/:commentable_id/
threads'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
.
comment_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
params
[
"recursive"
])}.
to_json
end
# POST /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads
# POST /api/v1/commentables/:commentable_type/:commentable_id/threads
# create a new comment thread for the commentable object
post
'/api/v1/
commentables/:commentable_type/:commentable_id/comment_
threads'
do
|
commentable_type
,
commentable_id
|
post
'/api/v1/
:commentable_type/:commentable_id/
threads'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
comment_
thread
=
commentable
.
comment_threads
.
new
(
params
.
slice
(
*
%w[title body course_id]
))
comment_
thread
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
comment_
thread
.
save!
comment_
thread
.
to_hash
.
to_json
thread
=
commentable
.
comment_threads
.
new
(
params
.
slice
(
*
%w[title body course_id]
))
thread
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
thread
.
save!
thread
.
to_hash
.
to_json
end
# GET /api/v1/
comment_threads/:comment_
thread_id
# GET /api/v1/
threads/:
thread_id
# get information of a single comment thread
# additional parameters accepted: recursive
get
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
get
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
end
# PUT /api/v1/
comment_threads/:comment_
thread_id
# PUT /api/v1/
threads/:
thread_id
# update information of comment thread
put
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
comment_
thread
.
to_hash
.
to_json
put
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
thread
.
to_hash
.
to_json
end
# POST /api/v1/
comment_threads/:comment_
thread_id/comments
# POST /api/v1/
threads/:
thread_id/comments
# create a comment to the comment thread
post
'/api/v1/
comment_threads/:comment_thread_id/comments'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment
=
comment_
thread
.
comments
.
new
(
params
.
slice
(
*
%w[body course_id]
))
post
'/api/v1/
threads/:thread_id/comments'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
comment
=
thread
.
comments
.
new
(
params
.
slice
(
*
%w[body course_id]
))
comment
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
comment
.
save!
comment
.
to_hash
.
to_json
end
# DELETE /api/v1/
comment_threads/:comment_
thread_id
# DELETE /api/v1/
threads/:
thread_id
# delete the comment thread and its comments
delete
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
destroy
comment_
thread
.
to_hash
.
to_json
delete
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
destroy
thread
.
to_hash
.
to_json
end
# GET /api/v1/comments/:comment_id
...
...
@@ -143,24 +142,24 @@ delete '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_
Comment
.
find
(
comment_id
).
to_hash
.
to_json
end
# PUT /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id
# PUT /api/v1/votes/
threads/:
thread_id/users/:user_id
# create or update the vote on the comment thread
put
'/api/v1/votes/
comment_threads/:comment_thread_id/users/:user_id'
do
|
comment_
thread_id
,
user_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
put
'/api/v1/votes/
threads/:thread_id/users/:user_id'
do
|
thread_id
,
user_id
|
thread
=
CommentThread
.
find
(
thread_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
vote
(
comment_
thread
,
params
[
"value"
].
intern
)
CommentThread
.
find
(
comment_
thread_id
).
to_hash
.
to_json
user
.
vote
(
thread
,
params
[
"value"
].
intern
)
CommentThread
.
find
(
thread_id
).
to_hash
.
to_json
end
# DELETE /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id
# DELETE /api/v1/votes/
threads/:
thread_id/users/:user_id
# unvote on the comment thread
delete
'/api/v1/votes/
comment_threads/:comment_thread_id/users/:user_id'
do
|
comment_
thread_id
,
user_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
delete
'/api/v1/votes/
threads/:thread_id/users/:user_id'
do
|
thread_id
,
user_id
|
thread
=
CommentThread
.
find
(
thread_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
unvote
(
comment_
thread
)
CommentThread
.
find
(
comment_
thread_id
).
to_hash
.
to_json
user
.
unvote
(
thread
)
CommentThread
.
find
(
thread_id
).
to_hash
.
to_json
end
# GET /api/v1/users/:user_id/feeds
...
...
@@ -213,23 +212,23 @@ post '/api/v1/users/:user_id/unwatch/commentable' do |user_id|
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/watch/
comment_
thread
# POST /api/v1/users/:user_id/watch/thread
# watch a comment thread
post
'/api/v1/users/:user_id/watch/
comment_
thread'
do
|
user_id
|
post
'/api/v1/users/:user_id/watch/thread'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
comment_thread
=
CommentThread
.
find
(
params
[
"comment_
thread_id"
])
user
.
watch_comment_thread
(
comment_
thread
)
thread
=
CommentThread
.
find
(
params
[
"
thread_id"
])
user
.
watch_comment_thread
(
thread
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/unwatch/
comment_
thread
# POST /api/v1/users/:user_id/unwatch/thread
# unwatch a comment thread
post
'/api/v1/users/:user_id/unwatch/
comment_
thread'
do
|
user_id
|
post
'/api/v1/users/:user_id/unwatch/thread'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
comment_thread
=
CommentThread
.
find
(
params
[
"comment_
thread_id"
])
user
.
unwatch_comment_thread
(
comment_
thread
)
thread
=
CommentThread
.
find
(
params
[
"
thread_id"
])
user
.
unwatch_comment_thread
(
thread
)
user
.
to_hash
.
to_json
end
...
...
models/comment.rb
View file @
bc407596
...
...
@@ -58,8 +58,8 @@ private
feed
=
Feed
.
new
(
feed_type:
"post_reply"
,
info:
{
comment_
thread_id:
get_comment_thread
.
id
,
comment_
thread_title:
get_comment_thread
.
title
,
thread_id:
get_comment_thread
.
id
,
thread_title:
get_comment_thread
.
title
,
comment_id:
id
,
},
)
...
...
models/comment_thread.rb
View file @
bc407596
...
...
@@ -41,8 +41,8 @@ private
info:
{
commentable_id:
commentable
.
commentable_id
,
commentable_type:
commentable
.
commentable_type
,
comment_
thread_id:
id
,
comment_
thread_title:
title
,
thread_id:
id
,
thread_title:
title
,
},
)
feed
.
actor
=
author
...
...
spec/app_spec.rb
View file @
bc407596
...
...
@@ -20,11 +20,11 @@ def init_without_feeds
user
=
User
.
create!
(
external_id:
"1"
)
comment_
thread
=
commentable
.
comment_threads
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
)
comment_
thread
.
author
=
user
comment_
thread
.
save!
thread
=
commentable
.
comment_threads
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
)
thread
.
author
=
user
thread
.
save!
comment
=
comment_
thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
=
thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"not for me!"
,
course_id:
"1"
)
...
...
@@ -34,24 +34,24 @@ def init_without_feeds
comment2
.
author
=
user
comment2
.
save!
comment
=
comment_
thread
.
comments
.
new
(
body:
"see the textbook on page 69. it's quite similar"
,
course_id:
"1"
)
comment
=
thread
.
comments
.
new
(
body:
"see the textbook on page 69. it's quite similar"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"thank you!"
,
course_id:
"1"
)
comment1
.
author
=
user
comment1
.
save!
comment_
thread
=
commentable
.
comment_threads
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
)
comment_
thread
.
author
=
user
comment_
thread
.
save!
thread
=
commentable
.
comment_threads
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
)
thread
.
author
=
user
thread
.
save!
comment
=
comment_
thread
.
comments
.
new
(
body:
"how do you know?"
,
course_id:
"1"
)
comment
=
thread
.
comments
.
new
(
body:
"how do you know?"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"because blablabla"
,
course_id:
"1"
)
comment1
.
author
=
user
comment1
.
save!
comment
=
comment_
thread
.
comments
.
new
(
body:
"no wonder I can't solve it"
,
course_id:
"1"
)
comment
=
thread
.
comments
.
new
(
body:
"no wonder I can't solve it"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"+1"
,
course_id:
"1"
)
...
...
@@ -88,12 +88,12 @@ def init_with_feeds
commentable
.
watchers
<<
[
user1
,
user2
]
commentable
.
save!
comment_
thread
=
commentable
.
comment_threads
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
)
comment_
thread
.
author
=
user1
comment_
thread
.
watchers
<<
user2
comment_
thread
.
save!
thread
=
commentable
.
comment_threads
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
)
thread
.
author
=
user1
thread
.
watchers
<<
user2
thread
.
save!
comment
=
comment_
thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
=
thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
user2
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"not for me!"
,
course_id:
"1"
)
...
...
@@ -103,9 +103,9 @@ def init_with_feeds
comment2
.
author
=
user2
comment2
.
save!
comment_
thread
=
commentable
.
comment_threads
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
)
comment_
thread
.
author
=
user2
comment_
thread
.
save!
thread
=
commentable
.
comment_threads
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
)
thread
.
author
=
user2
thread
.
save!
end
...
...
@@ -114,29 +114,29 @@ describe "app" do
before
(
:each
)
{
init_without_feeds
}
describe
"DELETE /api/v1/commentables/:commentable_type/:commentable_id"
do
it
"delete the commentable object and all of its associated comment threads and comments"
do
delete
'/api/v1/
commentables/questions/1
'
delete
'/api/v1/
questions/1/comments
'
last_response
.
should
be_ok
Commentable
.
count
.
should
==
0
end
end
describe
"GET /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads"
do
describe
"GET /api/v1/commentables/:commentable_type/:commentable_id/threads"
do
it
"get all comment threads associated with a commentable object"
do
get
"/api/v1/
commentables/questions/1/comment_
threads"
get
"/api/v1/
questions/1/
threads"
last_response
.
should
be_ok
comment_
threads
=
Yajl
::
Parser
.
parse
last_response
.
body
comment_
threads
.
length
.
should
==
2
comment_
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
comment_
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
threads
=
Yajl
::
Parser
.
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
end
it
"get all comment threads and comments associated with a commentable object"
do
get
"/api/v1/
commentables/questions/1/comment_
threads"
,
recursive:
true
get
"/api/v1/
questions/1/
threads"
,
recursive:
true
last_response
.
should
be_ok
comment_
threads
=
Yajl
::
Parser
.
parse
last_response
.
body
comment_
threads
.
length
.
should
==
2
comment_
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
comment_
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
comment_thread
=
comment_
threads
.
select
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
first
children
=
comment_
thread
[
"children"
]
threads
=
Yajl
::
Parser
.
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
thread
=
threads
.
select
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
first
children
=
thread
[
"children"
]
children
.
length
.
should
==
2
children
.
index
{
|
c
|
c
[
"body"
]
==
"this problem is so easy"
}.
should_not
be_nil
children
.
index
{
|
c
|
c
[
"body"
]
=~
/^see the textbook/
}.
should_not
be_nil
...
...
@@ -148,9 +148,9 @@ describe "app" do
not_for_me
[
"children"
].
first
[
"body"
].
should
==
"not for me neither!"
end
end
describe
"POST /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads"
do
describe
"POST /api/v1/commentables/:commentable_type/:commentable_id/threads"
do
it
"create a new comment thread for the commentable object"
do
post
'/api/v1/
commentables/questions/1/comment_
threads'
,
title:
"Interesting question"
,
body:
"cool"
,
course_id:
"1"
,
user_id:
"1"
post
'/api/v1/
questions/1/
threads'
,
title:
"Interesting question"
,
body:
"cool"
,
course_id:
"1"
,
user_id:
"1"
last_response
.
should
be_ok
CommentThread
.
count
.
should
==
3
CommentThread
.
where
(
title:
"Interesting question"
).
first
.
should_not
be_nil
...
...
@@ -159,62 +159,62 @@ describe "app" do
end
describe
"comment threads"
do
before
(
:each
)
{
init_without_feeds
}
describe
"GET /api/v1/
comment_threads/:comment_
thread_id"
do
describe
"GET /api/v1/
threads/:
thread_id"
do
it
"get information of a single comment thread"
do
comment_
thread
=
CommentThread
.
first
get
"/api/v1/
comment_threads/
#{
comment_
thread
.
id
}
"
thread
=
CommentThread
.
first
get
"/api/v1/
threads/
#{
thread
.
id
}
"
last_response
.
should
be_ok
response_thread
=
parse
last_response
.
body
comment_
thread
.
title
.
should
==
response_thread
[
"title"
]
comment_
thread
.
body
.
should
==
response_thread
[
"body"
]
comment_
thread
.
course_id
.
should
==
response_thread
[
"course_id"
]
comment_
thread
.
votes_point
.
should
==
response_thread
[
"votes"
][
"point"
]
thread
.
title
.
should
==
response_thread
[
"title"
]
thread
.
body
.
should
==
response_thread
[
"body"
]
thread
.
course_id
.
should
==
response_thread
[
"course_id"
]
thread
.
votes_point
.
should
==
response_thread
[
"votes"
][
"point"
]
response_thread
[
"children"
].
should
be_nil
end
it
"get information of a single comment thread with its comments"
do
comment_
thread
=
CommentThread
.
first
get
"/api/v1/
comment_threads/
#{
comment_
thread
.
id
}
"
,
recursive:
true
thread
=
CommentThread
.
first
get
"/api/v1/
threads/
#{
thread
.
id
}
"
,
recursive:
true
last_response
.
should
be_ok
response_thread
=
parse
last_response
.
body
comment_
thread
.
title
.
should
==
response_thread
[
"title"
]
comment_
thread
.
body
.
should
==
response_thread
[
"body"
]
comment_
thread
.
course_id
.
should
==
response_thread
[
"course_id"
]
comment_
thread
.
votes_point
.
should
==
response_thread
[
"votes"
][
"point"
]
thread
.
title
.
should
==
response_thread
[
"title"
]
thread
.
body
.
should
==
response_thread
[
"body"
]
thread
.
course_id
.
should
==
response_thread
[
"course_id"
]
thread
.
votes_point
.
should
==
response_thread
[
"votes"
][
"point"
]
response_thread
[
"children"
].
should_not
be_nil
response_thread
[
"children"
].
length
.
should
==
comment_
thread
.
comments
.
length
response_thread
[
"children"
].
index
{
|
c
|
c
[
"body"
]
==
comment_
thread
.
comments
.
first
.
body
}.
should_not
be_nil
response_thread
[
"children"
].
length
.
should
==
thread
.
comments
.
length
response_thread
[
"children"
].
index
{
|
c
|
c
[
"body"
]
==
thread
.
comments
.
first
.
body
}.
should_not
be_nil
end
end
describe
"PUT /api/v1/
comment_threads/:comment_
thread_id"
do
describe
"PUT /api/v1/
threads/:
thread_id"
do
it
"update information of comment thread"
do
comment_
thread
=
CommentThread
.
first
put
"/api/v1/
comment_threads/
#{
comment_
thread
.
id
}
"
,
body:
"new body"
,
title:
"new title"
thread
=
CommentThread
.
first
put
"/api/v1/
threads/
#{
thread
.
id
}
"
,
body:
"new body"
,
title:
"new title"
last_response
.
should
be_ok
changed_thread
=
CommentThread
.
find
(
comment_
thread
.
id
)
changed_thread
=
CommentThread
.
find
(
thread
.
id
)
changed_thread
.
body
.
should
==
"new body"
changed_thread
.
title
.
should
==
"new title"
end
end
# POST /api/v1/
comment_threads/:comment_
thread_id/comments
describe
"POST /api/v1/
comment_threads/:comment_
thread_id/comments"
do
# POST /api/v1/
threads/:
thread_id/comments
describe
"POST /api/v1/
threads/:
thread_id/comments"
do
it
"create a comment to the comment thread"
do
comment_
thread
=
CommentThread
.
first
.
to_hash
(
recursive:
true
)
thread
=
CommentThread
.
first
.
to_hash
(
recursive:
true
)
user
=
User
.
first
post
"/api/v1/
comment_threads/
#{
comment_
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
(
comment_
thread
[
"_id"
]).
to_hash
(
recursive:
true
)
changed_thread
[
"children"
].
length
.
should
==
comment_
thread
[
"children"
].
length
+
1
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
comment
[
"user_id"
].
should
==
user
.
id
end
end
describe
"DELETE /api/v1/
comment_threads/:comment_
thread_id"
do
describe
"DELETE /api/v1/
threads/:
thread_id"
do
it
"delete the comment thread and its comments"
do
comment_
thread
=
CommentThread
.
first
.
to_hash
delete
"/api/v1/
comment_threads/
#{
comment_
thread
[
'_id'
]
}
"
thread
=
CommentThread
.
first
.
to_hash
delete
"/api/v1/
threads/
#{
thread
[
'_id'
]
}
"
last_response
.
should
be_ok
CommentThread
.
where
(
title:
comment_
thread
[
"title"
]).
first
.
should
be_nil
CommentThread
.
where
(
title:
thread
[
"title"
]).
first
.
should
be_nil
end
end
end
...
...
@@ -306,28 +306,28 @@ describe "app" do
comment
.
down_votes_count
.
should
==
prev_down_votes
end
end
describe
"PUT /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id"
do
describe
"PUT /api/v1/votes/
threads/:
thread_id/users/:user_id"
do
it
"create or update the vote on the comment thread"
do
user
=
User
.
first
comment_
thread
=
CommentThread
.
first
prev_up_votes
=
comment_
thread
.
up_votes_count
prev_down_votes
=
comment_
thread
.
down_votes_count
put
"/api/v1/votes/
comment_threads/
#{
comment_
thread
.
id
}
/users/
#{
user
.
id
}
"
,
value:
"down"
comment_thread
=
CommentThread
.
find
(
comment_
thread
.
id
)
comment_
thread
.
up_votes_count
.
should
==
prev_up_votes
-
1
comment_
thread
.
down_votes_count
.
should
==
prev_down_votes
+
1
thread
=
CommentThread
.
first
prev_up_votes
=
thread
.
up_votes_count
prev_down_votes
=
thread
.
down_votes_count
put
"/api/v1/votes/
threads/
#{
thread
.
id
}
/users/
#{
user
.
id
}
"
,
value:
"down"
thread
=
CommentThread
.
find
(
thread
.
id
)
thread
.
up_votes_count
.
should
==
prev_up_votes
-
1
thread
.
down_votes_count
.
should
==
prev_down_votes
+
1
end
end
describe
"DELETE /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id"
do
describe
"DELETE /api/v1/votes/
threads/:
thread_id/users/:user_id"
do
it
"unvote on the comment thread"
do
user
=
User
.
first
comment_
thread
=
CommentThread
.
first
prev_up_votes
=
comment_
thread
.
up_votes_count
prev_down_votes
=
comment_
thread
.
down_votes_count
delete
"/api/v1/votes/
comment_threads/
#{
comment_
thread
.
id
}
/users/
#{
user
.
id
}
"
comment_thread
=
CommentThread
.
find
(
comment_
thread
.
id
)
comment_
thread
.
up_votes_count
.
should
==
prev_up_votes
-
1
comment_
thread
.
down_votes_count
.
should
==
prev_down_votes
thread
=
CommentThread
.
first
prev_up_votes
=
thread
.
up_votes_count
prev_down_votes
=
thread
.
down_votes_count
delete
"/api/v1/votes/
threads/
#{
thread
.
id
}
/users/
#{
user
.
id
}
"
thread
=
CommentThread
.
find
(
thread
.
id
)
thread
.
up_votes_count
.
should
==
prev_up_votes
-
1
thread
.
down_votes_count
.
should
==
prev_down_votes
end
end
end
...
...
@@ -353,7 +353,7 @@ describe "app" do
feeds
=
parse
last_response
.
body
feeds
.
select
{
|
f
|
f
[
"feed_type"
]
==
"post_topic"
}.
length
.
should
==
1
problem_wrong
=
feeds
.
select
{
|
f
|
f
[
"feed_type"
]
==
"post_topic"
}.
first
problem_wrong
[
"info"
][
"
comment_
thread_title"
].
should
==
"This problem is wrong"
problem_wrong
[
"info"
][
"thread_title"
].
should
==
"This problem is wrong"
end
end
describe
"POST /api/v1/users/:user_id/follow"
do
...
...
@@ -393,25 +393,25 @@ describe "app" do
Commentable
.
first
.
watchers
.
should_not
include
user2
end
end
describe
"POST /api/v1/users/:user_id/watch/
comment_
thread"
do
describe
"POST /api/v1/users/:user_id/watch/thread"
do
it
"watch a comment thread"
do
user1
=
User
.
find_or_create_by
(
external_id:
"1"
)
comment_
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user1
.
external_id
}
/watch/
comment_thread"
,
comment_thread_id:
comment_
thread
.
id
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user1
.
external_id
}
/watch/
thread"
,
thread_id:
thread
.
id
last_response
.
should
be_ok
comment_
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
comment_
thread
.
watchers
.
length
.
should
==
2
comment_
thread
.
watchers
.
should
include
user1
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
watchers
.
length
.
should
==
2
thread
.
watchers
.
should
include
user1
end
end
describe
"POST /api/v1/users/:user_id/unwatch/
comment_
thread"
do
describe
"POST /api/v1/users/:user_id/unwatch/thread"
do
it
"unwatch a comment thread"
do
user2
=
User
.
find_or_create_by
(
external_id:
"2"
)
comment_
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user2
.
external_id
}
/unwatch/
comment_thread"
,
comment_thread_id:
comment_
thread
.
id
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user2
.
external_id
}
/unwatch/
thread"
,
thread_id:
thread
.
id
last_response
.
should
be_ok
comment_
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
comment_
thread
.
watchers
.
length
.
should
==
0
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
watchers
.
length
.
should
==
0
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