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
bb116a19
Commit
bb116a19
authored
Sep 09, 2016
by
wajeeha-khalid
Committed by
GitHub
Sep 09, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #186 from edx/jia/MA-2139
MA-2139: Mark thread as read for leaner on thread/comment creation
parents
b8321560
3d506614
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
6 deletions
+27
-6
api/comment_threads.rb
+2
-0
api/commentables.rb
+7
-1
api/comments.rb
+2
-0
spec/api/comment_spec.rb
+3
-1
spec/api/comment_thread_spec.rb
+3
-2
spec/api/commentable_spec.rb
+2
-2
spec/spec_helper.rb
+8
-0
No files found.
api/comment_threads.rb
View file @
bb116a19
...
@@ -77,6 +77,8 @@ post "#{APIPREFIX}/threads/:thread_id/comments" do |thread_id|
...
@@ -77,6 +77,8 @@ post "#{APIPREFIX}/threads/:thread_id/comments" do |thread_id|
error
400
,
comment
.
errors
.
full_messages
.
to_json
error
400
,
comment
.
errors
.
full_messages
.
to_json
else
else
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
# Mark thread as read for owner user on comment creation
user
.
mark_as_read
(
thread
)
comment
.
to_hash
.
to_json
comment
.
to_hash
.
to_json
end
end
end
end
...
...
api/commentables.rb
View file @
bb116a19
...
@@ -42,11 +42,17 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
...
@@ -42,11 +42,17 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
thread
.
author
=
user
thread
.
author
=
user
thread
.
save
thread
.
save
if
thread
.
errors
.
any?
if
thread
.
errors
.
any?
error
400
,
thread
.
errors
.
full_messages
.
to_json
error
400
,
thread
.
errors
.
full_messages
.
to_json
else
else
# Mark thread as read for owner user on creation
user
.
mark_as_read
(
thread
)
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
presenter
=
ThreadPresenter
.
factory
(
thread
,
nil
)
# Initialize ThreadPresenter; if non-null user is passed it also calculates
# user specific data on initialization such as thread "read" status
presenter
=
ThreadPresenter
.
factory
(
thread
,
user
)
thread
=
presenter
.
to_hash
thread
=
presenter
.
to_hash
thread
[
"resp_total"
]
=
0
thread
[
"resp_total"
]
=
0
thread
.
to_json
thread
.
to_json
...
...
api/comments.rb
View file @
bb116a19
...
@@ -44,6 +44,8 @@ post "#{APIPREFIX}/comments/:comment_id" do |comment_id|
...
@@ -44,6 +44,8 @@ post "#{APIPREFIX}/comments/:comment_id" do |comment_id|
error
400
,
comment
.
errors
.
full_messages
.
to_json
error
400
,
comment
.
errors
.
full_messages
.
to_json
else
else
user
.
subscribe
(
comment
.
comment_thread
)
if
bool_auto_subscribe
user
.
subscribe
(
comment
.
comment_thread
)
if
bool_auto_subscribe
# Mark thread as read for owner user on response creation
user
.
mark_as_read
(
comment
.
comment_thread
)
sub_comment
.
to_hash
.
to_json
sub_comment
.
to_hash
.
to_json
end
end
end
end
...
...
spec/api/comment_spec.rb
View file @
bb116a19
...
@@ -155,7 +155,7 @@ describe 'Comment API' do
...
@@ -155,7 +155,7 @@ describe 'Comment API' do
end
end
describe
'POST /api/v1/comments/:comment_id'
do
describe
'POST /api/v1/comments/:comment_id'
do
it
'creates a sub comment to the comment'
do
it
'creates a sub comment to the comment
and marks thread as read for user
'
do
comment
=
thread
.
comments
.
first
comment
=
thread
.
comments
.
first
previous_child_count
=
comment
.
children
.
length
previous_child_count
=
comment
.
children
.
length
user
=
thread
.
author
user
=
thread
.
author
...
@@ -172,6 +172,8 @@ describe 'Comment API' do
...
@@ -172,6 +172,8 @@ describe 'Comment API' do
sub_comment
.
course_id
.
should
==
course_id
sub_comment
.
course_id
.
should
==
course_id
sub_comment
.
author
.
should
==
user
sub_comment
.
author
.
should
==
user
sub_comment
.
child_count
.
should
==
0
sub_comment
.
child_count
.
should
==
0
test_thread_marked_as_read
(
thread
.
id
,
user
.
id
)
end
end
it
'returns 400 when the comment does not exist'
do
it
'returns 400 when the comment does not exist'
do
...
...
spec/api/comment_thread_spec.rb
View file @
bb116a19
...
@@ -666,7 +666,6 @@ describe "app" do
...
@@ -666,7 +666,6 @@ describe "app" do
thread
=
CommentThread
.
first
thread
=
CommentThread
.
first
comment
=
thread
.
comments
.
first
comment
=
thread
.
comments
.
first
comment
.
endorsed
=
true
comment
.
endorsed
=
true
comment
.
endorsement
=
{
:user_id
=>
"42"
,
:time
=>
DateTime
.
now
}
comment
.
save
comment
.
save
put
"/api/v1/threads/
#{
thread
.
id
}
"
,
body:
"new body"
,
title:
"new title"
,
commentable_id:
"new_commentable_id"
,
thread_type:
"question"
put
"/api/v1/threads/
#{
thread
.
id
}
"
,
body:
"new body"
,
title:
"new title"
,
commentable_id:
"new_commentable_id"
,
thread_type:
"question"
last_response
.
should
be_ok
last_response
.
should
be_ok
...
@@ -716,7 +715,7 @@ describe "app" do
...
@@ -716,7 +715,7 @@ describe "app" do
let
:default_params
do
let
:default_params
do
{
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
}
{
body:
"new comment"
,
course_id:
"1"
,
user_id:
User
.
first
.
id
}
end
end
it
"create
a comment to the comment thread
"
do
it
"create
s a comment to the comment thread and marks thread as read for user
"
do
thread
=
CommentThread
.
first
thread
=
CommentThread
.
first
user
=
User
.
first
user
=
User
.
first
orig_count
=
thread
.
comment_count
orig_count
=
thread
.
comment_count
...
@@ -729,6 +728,8 @@ describe "app" do
...
@@ -729,6 +728,8 @@ describe "app" do
comment
.
should_not
be_nil
comment
.
should_not
be_nil
comment
.
author_id
.
should
==
user
.
id
comment
.
author_id
.
should
==
user
.
id
retrieved
[
"child_count"
].
should
==
0
retrieved
[
"child_count"
].
should
==
0
test_thread_marked_as_read
(
thread
.
id
,
user
.
id
)
end
end
it
"allows anonymous comment"
do
it
"allows anonymous comment"
do
thread
=
CommentThread
.
first
thread
=
CommentThread
.
first
...
...
spec/api/commentable_spec.rb
View file @
bb116a19
...
@@ -125,11 +125,11 @@ describe 'app' do
...
@@ -125,11 +125,11 @@ describe 'app' do
subject
{
post
"/api/v1/
#{
commentable_id
}
/threads"
,
parameters
}
subject
{
post
"/api/v1/
#{
commentable_id
}
/threads"
,
parameters
}
shared_examples_for
'CommentThread creation API'
do
|
context
=
'course'
|
shared_examples_for
'CommentThread creation API'
do
|
context
=
'course'
|
it
'creates a new CommentThread'
do
it
'creates a new CommentThread
and marks it as read for owner user
'
do
expect
(
CommentThread
.
count
).
to
eq
0
expect
(
CommentThread
.
count
).
to
eq
0
body
=
parse
(
subject
.
body
)
body
=
parse
(
subject
.
body
)
expect
(
body
).
to
include
(
'read'
=>
fals
e
,
expect
(
body
).
to
include
(
'read'
=>
tru
e
,
'unread_comments_count'
=>
0
,
'unread_comments_count'
=>
0
,
'endorsed'
=>
false
,
'endorsed'
=>
false
,
'resp_total'
=>
0
)
'resp_total'
=>
0
)
...
...
spec/spec_helper.rb
View file @
bb116a19
...
@@ -409,3 +409,11 @@ def create_comment_thread_and_comments
...
@@ -409,3 +409,11 @@ def create_comment_thread_and_comments
thread
thread
end
end
def
test_thread_marked_as_read
(
thread_id
,
user_id
)
# get thread to assert its "read" status
get
"/api/v1/threads/
#{
thread_id
}
"
,
user_id:
user_id
last_response
.
should
be_ok
retrieved_thread
=
parse
last_response
.
body
retrieved_thread
[
"read"
].
should
==
true
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