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
71fe495b
Commit
71fe495b
authored
Jul 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add uniqueness check for feeds; does not send notifications to author; use autosave
parent
47c2e04a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
21 deletions
+52
-21
models/comment.rb
+3
-4
models/comment_thread.rb
+4
-5
models/commentable.rb
+1
-1
models/feed.rb
+3
-3
models/user.rb
+3
-7
spec/app_spec.rb
+38
-1
No files found.
models/comment.rb
View file @
71fe495b
...
@@ -10,8 +10,8 @@ class Comment
...
@@ -10,8 +10,8 @@ class Comment
field
:course_id
,
type:
String
field
:course_id
,
type:
String
field
:endorsed
,
type:
Boolean
,
default:
false
field
:endorsed
,
type:
Boolean
,
default:
false
belongs_to
:author
,
class_name:
"User"
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
,
autosave:
true
belongs_to
:comment_thread
,
index:
true
belongs_to
:comment_thread
,
index:
true
,
autosave:
true
attr_accessible
:body
,
:course_id
,
:endorsed
attr_accessible
:body
,
:course_id
,
:endorsed
...
@@ -63,8 +63,7 @@ class Comment
...
@@ -63,8 +63,7 @@ class Comment
)
)
feed
.
actor
=
author
feed
.
actor
=
author
feed
.
target
=
self
feed
.
target
=
self
feed
.
subscribers
<<
get_comment_thread
.
watchers
feed
.
subscribers
<<
(
get_comment_thread
.
watchers
+
author
.
followers
).
uniq_by
(
&
:id
).
delete
(
author
)
# doesn't send notification to author
feed
.
subscribers
<<
author
.
followers
feed
.
save!
feed
.
save!
end
end
...
...
models/comment_thread.rb
View file @
71fe495b
...
@@ -9,10 +9,10 @@ class CommentThread
...
@@ -9,10 +9,10 @@ class CommentThread
field
:body
,
type:
String
field
:body
,
type:
String
field
:course_id
,
type:
String
,
index:
true
field
:course_id
,
type:
String
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
,
autosave:
true
belongs_to
:commentable
,
index:
true
belongs_to
:commentable
,
index:
true
,
autosave:
true
has_many
:comments
,
dependent: :destroy
# Use destroy to envoke callback on the top-level comments TODO async
has_many
:comments
,
dependent: :destroy
# Use destroy to envoke callback on the top-level comments TODO async
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_comment_threads
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_comment_threads
,
autosave:
true
attr_accessible
:title
,
:body
,
:course_id
attr_accessible
:title
,
:body
,
:course_id
...
@@ -45,8 +45,7 @@ class CommentThread
...
@@ -45,8 +45,7 @@ class CommentThread
)
)
feed
.
actor
=
author
feed
.
actor
=
author
feed
.
target
=
self
feed
.
target
=
self
feed
.
subscribers
<<
commentable
.
watchers
feed
.
subscribers
<<
(
commentable
.
watchers
+
author
.
followers
).
uniq_by
(
&
:id
).
delete
(
author
)
# doesn't send notification to author
feed
.
subscribers
<<
author
.
followers
feed
.
save!
feed
.
save!
end
end
...
...
models/commentable.rb
View file @
71fe495b
...
@@ -5,7 +5,7 @@ class Commentable
...
@@ -5,7 +5,7 @@ class Commentable
field
:commentable_id
,
type:
String
field
:commentable_id
,
type:
String
has_many
:comment_threads
,
dependent: :destroy
has_many
:comment_threads
,
dependent: :destroy
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_commentables
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_commentables
,
autosave:
true
attr_accessible
:commentable_type
,
:commentable_id
attr_accessible
:commentable_type
,
:commentable_id
...
...
models/feed.rb
View file @
71fe495b
...
@@ -5,8 +5,8 @@ class Feed
...
@@ -5,8 +5,8 @@ class Feed
field
:feed_type
,
type:
String
field
:feed_type
,
type:
String
field
:info
,
type:
Hash
field
:info
,
type:
Hash
belongs_to
:actor
,
class_name:
"User"
,
inverse_of: :activities
,
index:
true
belongs_to
:actor
,
class_name:
"User"
,
inverse_of: :activities
,
index:
true
,
autosave:
true
belongs_to
:target
,
inverse_of: :activities
,
polymorphic:
true
belongs_to
:target
,
inverse_of: :activities
,
polymorphic:
true
,
autosave:
true
attr_accessible
:feed_type
,
:info
attr_accessible
:feed_type
,
:info
...
@@ -14,7 +14,7 @@ class Feed
...
@@ -14,7 +14,7 @@ class Feed
validates_presence_of
:actor
validates_presence_of
:actor
validates_presence_of
:target
validates_presence_of
:target
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
,
autosave:
true
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[_id feed_type info actor target]
)
as_document
.
slice
(
*
%w[_id feed_type info actor target]
)
...
...
models/user.rb
View file @
71fe495b
...
@@ -7,9 +7,9 @@ class User
...
@@ -7,9 +7,9 @@ class User
has_many
:comments
has_many
:comments
has_many
:comment_threads
,
inverse_of: :author
has_many
:comment_threads
,
inverse_of: :author
has_many
:activities
,
class_name:
"Feed"
,
inverse_of: :actor
has_many
:activities
,
class_name:
"Feed"
,
inverse_of: :actor
has_and_belongs_to_many
:subscribed_feeds
,
class_name:
"Feed"
,
inverse_of: :subscribers
has_and_belongs_to_many
:subscribed_feeds
,
class_name:
"Feed"
,
inverse_of: :subscribers
,
autosave:
true
has_and_belongs_to_many
:followers
,
class_name:
"User"
,
inverse_of: :followings
has_and_belongs_to_many
:followers
,
class_name:
"User"
,
inverse_of: :followings
,
autosave:
true
has_and_belongs_to_many
:followings
,
class_name:
"User"
,
inverse_of: :followers
has_and_belongs_to_many
:followings
,
class_name:
"User"
,
inverse_of: :followers
,
autosave:
true
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[_id]
)
as_document
.
slice
(
*
%w[_id]
)
...
@@ -18,13 +18,11 @@ class User
...
@@ -18,13 +18,11 @@ class User
def
follow
(
user
)
def
follow
(
user
)
if
id
!=
user
.
id
and
not
following
.
include?
user
if
id
!=
user
.
id
and
not
following
.
include?
user
following
<<
user
following
<<
user
save!
end
end
end
end
def
unfollow
(
user
)
def
unfollow
(
user
)
following
.
delete
(
user
)
following
.
delete
(
user
)
save!
end
end
def
self
.
watching
(
class_plural_sym
)
def
self
.
watching
(
class_plural_sym
)
...
@@ -39,13 +37,11 @@ class User
...
@@ -39,13 +37,11 @@ class User
def watch_
#{
class_single
}
(watching_object)
def watch_
#{
class_single
}
(watching_object)
if not watched_
#{
class_plural
}
.include? watching_object
if not watched_
#{
class_plural
}
.include? watching_object
watched_
#{
class_plural
}
<< watching_object
watched_
#{
class_plural
}
<< watching_object
save!
end
end
end
end
def unwatch_
#{
class_single
}
(watching_object)
def unwatch_
#{
class_single
}
(watching_object)
watched_
#{
class_plural
}
.delete(watching_object)
watched_
#{
class_plural
}
.delete(watching_object)
save!
end
end
END
END
end
end
...
...
spec/app_spec.rb
View file @
71fe495b
...
@@ -71,6 +71,43 @@ def init_without_feeds
...
@@ -71,6 +71,43 @@ def init_without_feeds
end
end
end
end
def
init_with_feeds
Comment
.
delete_all
CommentThread
.
delete_all
Commentable
.
delete_all
User
.
delete_all
Feed
.
delete_all
user1
=
User
.
create!
(
id:
"1"
)
user2
=
User
.
create!
(
id:
"2"
)
user1
.
followers
<<
user2
commentable
=
Commentable
.
new
(
commentable_type:
"questions"
,
commentable_id:
"1"
)
commentable
.
watchers
<<
[
user1
,
user2
]
commentable
.
save!
comment_thread
=
commentable
.
comment_threads
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
)
comment_thread
.
author
=
user1
comment_thread
.
watchers
<<
user1
comment_thread
.
save!
comment
=
comment_thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
user1
comment
.
save!
comment1
=
comment
.
children
.
new
(
body:
"not for me!"
,
course_id:
"1"
)
comment1
.
author
=
user1
comment1
.
save!
comment2
=
comment1
.
children
.
new
(
body:
"not for me neither!"
,
course_id:
"1"
)
comment2
.
author
=
user1
comment2
.
save!
comment_thread
=
commentable
.
comment_threads
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
)
comment_thread
.
author
=
user
comment_thread
.
save!
end
describe
"app"
do
describe
"app"
do
describe
"commentables"
do
describe
"commentables"
do
before
(
:each
)
{
init_without_feeds
}
before
(
:each
)
{
init_without_feeds
}
...
@@ -295,9 +332,9 @@ describe "app" do
...
@@ -295,9 +332,9 @@ describe "app" do
end
end
end
end
describe
"feeds"
do
describe
"feeds"
do
#before(:each) { init_with_feeds }
describe
"GET /api/v1/users/:user_id/feeds"
do
describe
"GET /api/v1/users/:user_id/feeds"
do
it
"get all subscribed feeds for the user"
do
it
"get all subscribed feeds for the user"
do
end
end
end
end
describe
"POST /api/v1/users/:user_id/follow"
do
describe
"POST /api/v1/users/:user_id/follow"
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