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
685778b1
Commit
685778b1
authored
Jun 20, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added validation for comments if not super comment
parent
a7918b01
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
6 deletions
+11
-6
app.rb
+2
-4
models/comment.rb
+5
-0
spec/app_spec.rb
+4
-2
No files found.
app.rb
View file @
685778b1
...
@@ -22,8 +22,7 @@ end
...
@@ -22,8 +22,7 @@ end
# create a new top-level comment
# create a new top-level comment
post
'/api/v1/commentables/:commentable_type/:commentable_id/comments'
do
|
commentable_type
,
commentable_id
|
post
'/api/v1/commentables/:commentable_type/:commentable_id/comments'
do
|
commentable_type
,
commentable_id
|
comment_thread
=
CommentThread
.
find_or_create_by_commentable_type_and_commentable_id
(
commentable_type
,
commentable_id
)
comment_thread
=
CommentThread
.
find_or_create_by_commentable_type_and_commentable_id
(
commentable_type
,
commentable_id
)
comment_params
=
params
.
select
{
|
key
,
value
|
%w{body title user_id course_id}
.
include?
key
}
comment_params
=
params
.
select
{
|
key
,
value
|
%w{body title user_id course_id}
.
include?
key
}.
merge
({
:comment_thread_id
=>
comment_thread
.
id
})
comment_params
.
merge
:comment_thread_id
=>
comment_thread
.
id
comment
=
comment_thread
.
root_comments
.
create
(
comment_params
)
comment
=
comment_thread
.
root_comments
.
create
(
comment_params
)
if
comment
.
valid?
if
comment
.
valid?
comment
.
to_json
comment
.
to_json
...
@@ -49,8 +48,7 @@ post '/api/v1/comments/:comment_id' do |comment_id|
...
@@ -49,8 +48,7 @@ post '/api/v1/comments/:comment_id' do |comment_id|
if
comment
.
nil?
or
comment
.
is_root?
if
comment
.
nil?
or
comment
.
is_root?
error
400
,
{
:error
=>
"invalid comment id"
}.
to_json
error
400
,
{
:error
=>
"invalid comment id"
}.
to_json
else
else
comment_params
=
params
.
select
{
|
key
,
value
|
%w{body title user_id course_id}
.
include?
key
}
comment_params
=
params
.
select
{
|
key
,
value
|
%w{body title user_id course_id}
.
include?
key
}.
merge
({
:comment_thread_id
=>
comment
.
comment_thread_id
})
comment_params
.
merge
:comment_thread_id
=>
comment
.
root
.
comment_thread
.
id
sub_comment
=
comment
.
children
.
create
(
comment_params
)
sub_comment
=
comment
.
children
.
create
(
comment_params
)
if
comment
.
valid?
if
comment
.
valid?
comment
.
to_json
comment
.
to_json
...
...
models/comment.rb
View file @
685778b1
...
@@ -11,6 +11,11 @@ class Comment < ActiveRecord::Base
...
@@ -11,6 +11,11 @@ class Comment < ActiveRecord::Base
belongs_to
:comment_thread
belongs_to
:comment_thread
validates_presence_of
:body
,
:unless
=>
:is_root?
validates_presence_of
:user_id
,
:unless
=>
:is_root?
validates_presence_of
:course_id
,
:unless
=>
:is_root?
validates_presence_of
:comment_thread_id
def
self
.
hash_tree
(
nodes
)
def
self
.
hash_tree
(
nodes
)
nodes
.
map
do
|
node
,
sub_nodes
|
nodes
.
map
do
|
node
,
sub_nodes
|
{
{
...
...
spec/app_spec.rb
View file @
685778b1
...
@@ -168,8 +168,10 @@ describe "app" do
...
@@ -168,8 +168,10 @@ describe "app" do
end
end
describe
"PUT on /api/v1/votes/comments/:comment_id/users/:user_id"
do
describe
"PUT on /api/v1/votes/comments/:comment_id/users/:user_id"
do
before
:each
do
before
:each
do
CommentThread
.
create!
:commentable_type
=>
"questions"
,
:commentable_id
=>
1
comment_thread
=
CommentThread
.
create!
:commentable_type
=>
"questions"
,
:commentable_id
=>
1
CommentThread
.
first
.
root_comments
.
create
:body
=>
"top comment"
,
:title
=>
"top"
,
:user_id
=>
1
,
:course_id
=>
1
comment
=
CommentThread
.
first
.
root_comments
.
create
:body
=>
"top comment"
,
:title
=>
"top"
,
:user_id
=>
1
,
:course_id
=>
1
comment
.
comment_thread
=
comment_thread
comment
.
save!
end
end
it
"votes up on a comment"
do
it
"votes up on a comment"
do
comment
=
CommentThread
.
first
.
comments
.
first
comment
=
CommentThread
.
first
.
comments
.
first
...
...
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