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
a179a115
Commit
a179a115
authored
Jul 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more details for comment thread retrieval spec & bug fix
parent
18327d93
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
10 deletions
+23
-10
models/comment.rb
+1
-1
spec/app_spec.rb
+21
-9
spec/spec_helper.rb
+1
-0
No files found.
models/comment.rb
View file @
a179a115
...
...
@@ -32,7 +32,7 @@ class Comment
def
to_hash
(
params
=
{})
if
params
[
:recursive
]
self
.
class
.
hash_tree
(
subtree
(
order_by:
[[
:parent_ids
,
:asc
],
[
:created_at
,
:asc
]]))
self
.
class
.
hash_tree
(
subtree
(
order_by:
[[
:parent_ids
,
:asc
],
[
:created_at
,
:asc
]]))
.
first
else
as_document
.
slice
(
*
%w[body course_id endorsed _id]
).
merge
(
"user_id"
=>
author
.
external_id
).
...
...
spec/app_spec.rb
View file @
a179a115
require
'spec_helper'
require
'yajl'
describe
"app"
do
before
:each
do
...
...
@@ -23,6 +22,10 @@ describe "app" do
comment
=
comment
.
children
.
create!
(
body:
"not for me!"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment
=
comment
.
children
.
create!
(
body:
"not for me neither!"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
comment
=
comment_thread
.
comments
.
create!
(
body:
"see the textbook on page 69. it's quite similar"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
save!
...
...
@@ -47,15 +50,15 @@ describe "app" do
comment
.
author
=
user
comment
.
save!
users
=
(
1
..
10
).
map
{
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
)}
Comment
.
all
.
each
do
|
c
|
(
1
..
10
).
each
do
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
).
vote
(
c
,
[
:up
,
:down
].
sample
)
end
users
.
each
{
|
user
|
user
.
vote
(
c
,
[
:up
,
:down
].
sample
)}
end
CommentThread
.
all
.
each
do
|
c
|
(
1
..
10
).
each
do
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
).
vote
(
c
,
[
:up
,
:down
].
sample
)
end
users
.
each
{
|
user
|
user
.
vote
(
c
,
[
:up
,
:down
].
sample
)}
end
end
...
...
@@ -77,8 +80,17 @@ describe "app" do
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
.
first
comment_thread
[
"children"
].
length
.
should
==
2
comment_thread
=
comment_threads
.
select
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
first
children
=
comment_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
so_easy
=
children
.
select
{
|
c
|
c
[
"body"
]
==
"this problem is so easy"
}.
first
so_easy
[
"children"
].
length
.
should
==
1
not_for_me
=
so_easy
[
"children"
].
first
not_for_me
[
"body"
].
should
==
"not for me!"
not_for_me
[
"children"
].
length
.
should
==
1
not_for_me
[
"children"
].
first
[
"body"
].
should
==
"not for me neither!"
end
end
...
...
spec/spec_helper.rb
View file @
a179a115
...
...
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'app')
require
'sinatra'
require
'rack/test'
require
'yajl'
# setup test environment
set
:environment
,
:test
...
...
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