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
c5d51bba
Commit
c5d51bba
authored
Sep 06, 2012
by
Matthew Mongeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endoresed information for threads.
parent
95c6f3d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
models/comment_thread.rb
+5
-0
spec/models/comment_thread_spec.rb
+24
-0
No files found.
models/comment_thread.rb
View file @
c5d51bba
...
...
@@ -145,6 +145,10 @@ class CommentThread < Content
subscriptions
.
map
(
&
:subscriber
)
end
def
endorsed?
comments
.
where
(
endorsed:
true
).
exists?
end
def
to_hash
(
params
=
{})
doc
=
as_document
.
slice
(
*
%w[title body course_id anonymous commentable_id created_at updated_at at_position_list closed]
)
.
merge
(
"id"
=>
_id
)
...
...
@@ -153,6 +157,7 @@ class CommentThread < Content
.
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
.
merge
(
"tags"
=>
tags_array
)
.
merge
(
"type"
=>
"thread"
)
.
merge
(
"endorsed"
=>
endorsed?
)
if
params
[
:recursive
]
doc
=
doc
.
merge
(
"children"
=>
root_comments
.
map
{
|
c
|
c
.
to_hash
(
recursive:
true
)})
...
...
spec/models/comment_thread.rb
→
spec/models/comment_thread
_spec
.rb
View file @
c5d51bba
...
...
@@ -20,4 +20,28 @@ describe CommentThread do
CommentThread
.
tag_name_valid?
(
"_this-is-a-tag"
).
should
be_false
CommentThread
.
tag_name_valid?
(
"this-is+a-tag"
).
should
be_false
end
context
"endorsed?"
do
it
"knows if it is #endorsed?"
do
thread
=
CommentThread
.
new
criteria
=
build_criteria
(
thread
,
:exists?
=>
true
)
thread
.
endorsed?
.
should
be_true
end
it
"knows when it is not #endorsed?"
do
thread
=
CommentThread
.
new
criteria
=
build_criteria
(
thread
,
:exists?
=>
false
)
thread
.
endorsed?
.
should
be_false
end
def
build_criteria
(
thread
,
options
)
double
(
"criteria"
).
tap
do
|
criteria
|
comments
=
double
(
"relation"
)
comments
.
stub
(
:where
).
with
(
endorsed:
true
).
and_return
(
criteria
)
thread
.
stub
(
:comments
).
and_return
(
comments
)
criteria
.
stub
(
options
)
end
end
end
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