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
9203bad1
Commit
9203bad1
authored
Jul 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
specs for comment threads & comments & passed
parent
b8b278a1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
24 deletions
+24
-24
Rakefile
+1
-5
app.rb
+7
-9
models/comment.rb
+10
-6
models/comment_thread.rb
+4
-4
spec/app_spec.rb
+0
-0
spec/spec_helper.rb
+2
-0
No files found.
Rakefile
View file @
9203bad1
...
@@ -4,11 +4,7 @@ require 'bundler'
...
@@ -4,11 +4,7 @@ require 'bundler'
Bundler
.
setup
Bundler
.
setup
Bundler
.
require
Bundler
.
require
require
'./models/comment.rb'
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
require
'./models/comment_thread.rb'
require
'./models/user.rb'
require
'./models/commentable.rb'
require
'./models/feed.rb'
desc
"Load the environment"
desc
"Load the environment"
task
:environment
do
task
:environment
do
...
...
app.rb
View file @
9203bad1
...
@@ -4,11 +4,7 @@ require 'bundler'
...
@@ -4,11 +4,7 @@ require 'bundler'
Bundler
.
setup
Bundler
.
setup
Bundler
.
require
Bundler
.
require
require
'./models/comment'
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
require
'./models/comment_thread'
require
'./models/commentable'
require
'./models/user'
require
'./models/feed'
env_index
=
ARGV
.
index
(
"-e"
)
env_index
=
ARGV
.
index
(
"-e"
)
env_arg
=
ARGV
[
env_index
+
1
]
if
env_index
env_arg
=
ARGV
[
env_index
+
1
]
if
env_index
...
@@ -55,7 +51,7 @@ config = YAML.load_file("config/application.yml")
...
@@ -55,7 +51,7 @@ config = YAML.load_file("config/application.yml")
# delete the commentable object and all of its associated comment threads and comments
# delete the commentable object and all of its associated comment threads and comments
delete
'/api/v1/commentables/:commentable_type/:commentable_id'
do
|
commentable_type
,
commentable_id
|
delete
'/api/v1/commentables/:commentable_type/:commentable_id'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_
creat
e_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
=
Commentable
.
find_or_
initializ
e_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
.
destroy
commentable
.
destroy
commentable
.
to_hash
.
to_json
commentable
.
to_hash
.
to_json
end
end
...
@@ -94,7 +90,8 @@ end
...
@@ -94,7 +90,8 @@ end
put
'/api/v1/comment_threads/:comment_thread_id'
do
|
comment_thread_id
|
put
'/api/v1/comment_threads/:comment_thread_id'
do
|
comment_thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_thread_id
)
comment_thread
=
CommentThread
.
find
(
comment_thread_id
)
comment_thread
.
update!
(
params
.
slice
(
*
%w[title body endorsed]
)).
to_hash
.
to_json
comment_thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
comment_thread
.
to_hash
.
to_json
end
end
# POST /api/v1/comment_threads/:comment_thread_id/comments
# POST /api/v1/comment_threads/:comment_thread_id/comments
...
@@ -130,7 +127,8 @@ end
...
@@ -130,7 +127,8 @@ end
put
'/api/v1/comments/:comment_id'
do
|
comment_id
|
put
'/api/v1/comments/:comment_id'
do
|
comment_id
|
comment
=
Comment
.
find
(
comment_id
)
comment
=
Comment
.
find
(
comment_id
)
comment
.
update!
(
params
.
slice
(
*
%w[body endorsed]
)).
to_hash
.
to_json
comment
.
update_attributes!
(
params
.
slice
(
*
%w[body endorsed]
))
comment
.
to_hash
.
to_json
end
end
# POST /api/v1/comments/:comment_id
# POST /api/v1/comments/:comment_id
...
@@ -138,7 +136,7 @@ end
...
@@ -138,7 +136,7 @@ end
post
'/api/v1/comments/:comment_id'
do
|
comment_id
|
post
'/api/v1/comments/:comment_id'
do
|
comment_id
|
comment
=
Comment
.
find
(
comment_id
)
comment
=
Comment
.
find
(
comment_id
)
sub_comment
=
comment
.
children
.
new
(
params
.
slice
(
*
%w[body]
))
sub_comment
=
comment
.
children
.
new
(
params
.
slice
(
*
%w[body
course_id
]
))
sub_comment
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
sub_comment
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
sub_comment
.
save!
sub_comment
.
save!
sub_comment
.
to_hash
.
to_json
sub_comment
.
to_hash
.
to_json
...
...
models/comment.rb
View file @
9203bad1
...
@@ -13,7 +13,7 @@ class Comment
...
@@ -13,7 +13,7 @@ class Comment
belongs_to
:author
,
class_name:
"User"
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
belongs_to
:comment_thread
,
index:
true
belongs_to
:comment_thread
,
index:
true
attr_accessible
:body
,
:course_id
attr_accessible
:body
,
:course_id
,
:endorsed
validates_presence_of
:body
validates_presence_of
:body
validates_presence_of
:course_id
# do we really need this?
validates_presence_of
:course_id
# do we really need this?
...
@@ -26,8 +26,12 @@ class Comment
...
@@ -26,8 +26,12 @@ class Comment
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
)}
end
end
def
comment_thread
def
get_comment_thread
comment_thread
||
root
.
comment_thread
if
comment_thread
comment_thread
else
root
.
comment_thread
end
end
end
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
...
@@ -52,14 +56,14 @@ class Comment
...
@@ -52,14 +56,14 @@ class Comment
feed
=
Feed
.
new
(
feed
=
Feed
.
new
(
feed_type:
"post_reply"
,
feed_type:
"post_reply"
,
info:
{
info:
{
comment_thread_id:
comment_thread
.
id
,
comment_thread_id:
get_
comment_thread
.
id
,
comment_thread_title:
comment_thread
.
title
,
comment_thread_title:
get_
comment_thread
.
title
,
comment_id:
id
,
comment_id:
id
,
},
},
)
)
feed
.
actor
=
author
feed
.
actor
=
author
feed
.
target
=
self
feed
.
target
=
self
feed
.
subscribers
<<
comment_thread
.
watchers
feed
.
subscribers
<<
get_
comment_thread
.
watchers
feed
.
subscribers
<<
author
.
followers
feed
.
subscribers
<<
author
.
followers
feed
.
save!
feed
.
save!
end
end
...
...
models/comment_thread.rb
View file @
9203bad1
...
@@ -37,10 +37,10 @@ class CommentThread
...
@@ -37,10 +37,10 @@ class CommentThread
feed
=
Feed
.
new
(
feed
=
Feed
.
new
(
feed_type:
"post_topic"
,
feed_type:
"post_topic"
,
info:
{
info:
{
commentable_id:
commentable
.
id
,
commentable_id:
commentable
.
commentable_
id
,
commentable_type:
commentable
.
type
,
commentable_type:
commentable
.
commentable_
type
,
comment_thread_id:
comment_thread
.
id
,
comment_thread_id:
id
,
comment_thread_title:
comment_thread
.
title
,
comment_thread_title:
title
,
},
},
)
)
feed
.
actor
=
author
feed
.
actor
=
author
...
...
spec/app_spec.rb
View file @
9203bad1
This diff is collapsed.
Click to expand it.
spec/spec_helper.rb
View file @
9203bad1
...
@@ -10,6 +10,8 @@ set :run, false
...
@@ -10,6 +10,8 @@ set :run, false
set
:raise_errors
,
true
set
:raise_errors
,
true
set
:logging
,
false
set
:logging
,
false
Delayed
::
Worker
.
delay_jobs
=
false
def
app
def
app
Sinatra
::
Application
Sinatra
::
Application
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