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
774887b4
Commit
774887b4
authored
Sep 25, 2014
by
jmclaus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make thread_type editable.
parent
07866196
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
api/comment_threads.rb
+1
-1
models/comment_thread.rb
+14
-1
spec/api/comment_thread_spec.rb
+9
-1
No files found.
api/comment_threads.rb
View file @
774887b4
...
...
@@ -52,7 +52,7 @@ end
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
filter_blocked_content
params
[
"body"
]
thread
.
update_attributes
(
params
.
slice
(
*
%w[title body closed commentable_id group_id]
))
thread
.
update_attributes
(
params
.
slice
(
*
%w[title body closed commentable_id group_id
thread_type
]
))
if
thread
.
errors
.
any?
error
400
,
thread
.
errors
.
full_messages
.
to_json
...
...
models/comment_thread.rb
View file @
774887b4
...
...
@@ -53,7 +53,7 @@ class CommentThread < Content
has_many
:comments
,
dependent: :destroy
#, autosave: true# Use destroy to envoke callback on the top-level comments TODO async
has_many
:activities
,
autosave:
true
attr_accessible
:title
,
:body
,
:course_id
,
:commentable_id
,
:anonymous
,
:anonymous_to_peers
,
:closed
attr_accessible
:title
,
:body
,
:course_id
,
:commentable_id
,
:anonymous
,
:anonymous_to_peers
,
:closed
,
:thread_type
validates_presence_of
:thread_type
validates_presence_of
:title
...
...
@@ -64,6 +64,7 @@ class CommentThread < Content
before_create
:set_last_activity_at
before_update
:set_last_activity_at
,
:unless
=>
lambda
{
closed_changed?
}
after_update
:clear_endorsements
before_destroy
:destroy_subscriptions
...
...
@@ -141,6 +142,18 @@ private
self
.
last_activity_at
=
Time
.
now
.
utc
unless
last_activity_at_changed?
end
def
clear_endorsements
if
self
.
thread_type_changed?
# We use 'set' instead of 'update_attributes' because the Comment model has a 'before_update' callback that sets
# the last activity time on the thread. Therefore the callbacks would be mutually recursive and we end up with a
# 'SystemStackError'. The 'set' method skips callbacks and therefore bypasses this issue.
self
.
comments
.
each
do
|
comment
|
comment
.
set
:endorsed
,
false
comment
.
set
:endorsement
,
nil
end
end
end
def
destroy_subscriptions
subscriptions
.
delete_all
end
...
...
spec/api/comment_thread_spec.rb
View file @
774887b4
...
...
@@ -556,12 +556,20 @@ describe "app" do
it
"update information of comment thread"
do
thread
=
CommentThread
.
first
put
"/api/v1/threads/
#{
thread
.
id
}
"
,
body:
"new body"
,
title:
"new title"
,
commentable_id:
"new_commentable_id"
comment
=
thread
.
comments
.
first
comment
.
endorsed
=
true
comment
.
endorsement
=
{
:user_id
=>
"42"
,
:time
=>
DateTime
.
now
}
comment
.
save
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
changed_thread
=
CommentThread
.
find
(
thread
.
id
)
changed_thread
.
body
.
should
==
"new body"
changed_thread
.
title
.
should
==
"new title"
changed_thread
.
commentable_id
.
should
==
"new_commentable_id"
changed_thread
.
thread_type
.
should
==
"question"
comment
.
reload
comment
.
endorsed
.
should
==
false
comment
.
endorsement
.
should
==
nil
check_thread_result_json
(
nil
,
changed_thread
,
parse
(
last_response
.
body
))
end
it
"returns 400 when the thread does not exist"
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