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
2dded1a2
Commit
2dded1a2
authored
Jun 23, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include depth information
parent
0c9a488c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
10 deletions
+13
-10
Rakefile
+9
-8
models/comment.rb
+2
-2
spec/app_spec.rb
+2
-0
No files found.
Rakefile
View file @
2dded1a2
...
...
@@ -27,15 +27,16 @@ namespace :db do
Vote
.
delete_all
User
.
delete_all
depth_limit
=
YAML
.
load_file
(
"config/application.yml"
)[
"depth_limit"
]
comment_thread
=
CommentThread
.
create!
:commentable_type
=>
"questions"
,
:commentable_id
=>
1
5
.
times
do
comment_thread
.
root_comments
.
create
:body
=>
"top comment"
,
:title
=>
"top
#{
rand
(
10
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
end
10
.
times
do
comment
=
Comment
.
all
.
reject
{
|
c
|
c
.
is_root?
or
c
.
depth
-
1
>=
depth_limit
}.
sample
comment
.
children
.
create
:body
=>
"comment body"
,
:title
=>
"comment title
#{
rand
(
50
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
(
1
..
3
).
each
do
|
question_id
|
comment_thread
=
CommentThread
.
create!
:commentable_type
=>
"questions"
,
:commentable_id
=>
question_id
5
.
times
do
comment_thread
.
root_comments
.
create
:body
=>
"top comment"
,
:title
=>
"top
#{
rand
(
10
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
end
10
.
times
do
comment
=
Comment
.
all
.
reject
{
|
c
|
c
.
is_root?
or
c
.
depth
-
1
>=
depth_limit
or
c
.
comment_thread_id
!=
comment_thread
.
id
}.
sample
comment
.
children
.
create
:body
=>
"comment body"
,
:title
=>
"comment title
#{
rand
(
50
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
end
end
Comment
.
all
.
reject
{
|
c
|
c
.
is_root?
}.
each
do
|
c
|
(
1
..
20
).
each
do
|
id
|
user
=
User
.
find_or_create_by_id
(
id
)
...
...
models/comment.rb
View file @
2dded1a2
...
...
@@ -18,7 +18,7 @@ class Comment < ActiveRecord::Base
validates_presence_of
:comment_thread_id
def
self
.
hash_tree
(
nodes
)
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
:children
=>
hash_tree
(
sub_nodes
).
compact
)}
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
:children
=>
hash_tree
(
sub_nodes
).
compact
,
:depth
=>
node
.
depth
)}
end
def
to_hash_tree
...
...
@@ -26,7 +26,7 @@ class Comment < ActiveRecord::Base
end
def
to_hash
attributes
.
merge
(
:votes
=>
{
:up
=>
votes_for
,
:down
=>
votes_against
})
attributes
.
merge
(
:votes
=>
{
:up
=>
votes_for
,
:down
=>
votes_against
,
:plusminus
=>
plusminus
})
end
def
to_json
...
...
spec/app_spec.rb
View file @
2dded1a2
...
...
@@ -91,11 +91,13 @@ describe "app" do
c
[
"created_at"
].
should_not
be_nil
c
[
"updated_at"
].
should_not
be_nil
c
[
"children"
].
length
.
should
==
2
c
[
"depth"
].
should
==
1
children
=
c
[
"children"
].
reject
{
|
comment
|
comment
[
"title"
]
!=
"comment title 0"
}.
first
children
.
should_not
be_nil
children
[
"id"
].
should
==
sub_comment
[
0
].
id
children
[
"created_at"
].
should_not
be_nil
children
[
"updated_at"
].
should_not
be_nil
children
[
"depth"
].
should
==
2
end
end
describe
"GET on /api/v1/comments/:comment_id"
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