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
e32f8e54
Commit
e32f8e54
authored
Aug 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed spec
parent
ceaf5c0c
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
14 deletions
+26
-14
app.rb
+1
-1
models/activity.rb
+1
-1
models/comment_thread.rb
+0
-1
models/commentable.rb
+6
-1
models/notification.rb
+1
-4
models/observers/at_user_observer.rb
+1
-2
models/observers/post_reply_observer.rb
+1
-2
models/observers/post_topic_observer.rb
+9
-2
spec/spec_helper.rb
+6
-0
No files found.
app.rb
View file @
e32f8e54
...
...
@@ -37,11 +37,11 @@ DEFAULT_PER_PAGE = 20
require
'./api/search'
require
'./api/commentables'
require
'./api/tags'
require
'./api/comment_threads'
require
'./api/comments'
require
'./api/users'
require
'./api/votes'
require
'./api/tags'
require
'./api/notifications_and_subscriptions'
if
environment
.
to_s
==
"development"
...
...
models/activity.rb
View file @
e32f8e54
...
...
@@ -10,7 +10,7 @@ class Activity
belongs_to
:target
,
inverse_of: :activities
,
polymorphic:
true
,
index:
true
,
autosave:
true
validates_presence_of
:actor
validates_presence_of
:target
#
validates_presence_of :target
end
models/comment_thread.rb
View file @
e32f8e54
...
...
@@ -82,7 +82,6 @@ class CommentThread < Content
end
def
self
.
perform_search
(
params
,
options
=
{})
puts
"params:
#{
params
}
"
page
=
[
1
,
options
[
:page
]
||
1
].
max
per_page
=
options
[
:per_page
]
||
20
sort_key
=
options
[
:sort_key
]
...
...
models/commentable.rb
View file @
e32f8e54
class
Commentable
attr_accessor
:id
attr_accessor
:id
,
:_type
alias_attribute
:_id
,
:id
class
<<
self
;
alias_method
:find
,
:new
;
end
def
initialize
(
id
)
self
.
id
=
id
self
.
_type
=
self
.
class
.
to_s
end
def
self
.
where
(
params
=
{})
params
[
:id
]
?
[
self
.
new
(
params
[:
id
])]
:
self
end
def
comment_threads
...
...
models/notification.rb
View file @
e32f8e54
...
...
@@ -5,13 +5,10 @@ class Notification
field
:notification_type
,
type:
String
field
:info
,
type:
Hash
#belongs_to :actor, class_name: "User", inverse_of: :activities, index: true, autosave: true
#belongs_to :target, inverse_of: :activities, polymorphic: true, index: true, autosave: true
attr_accessible
:notification_type
,
:info
validates_presence_of
:notification_type
validates_presence_of
:
target
validates_presence_of
:
info
has_and_belongs_to_many
:receivers
,
class_name:
"User"
,
inverse_of: :notifications
,
autosave:
true
...
...
models/observers/at_user_observer.rb
View file @
e32f8e54
...
...
@@ -43,11 +43,10 @@ class AtUserObserver < Mongoid::Observer
thread_title:
thread_title
,
thread_id:
thread_id
,
actor_username:
content
.
author_with_anonymity
(
:username
),
actor_id:
content
.
author_with_anonymity
(
:id
),
commentable_id:
commentable_id
,
}
)
notification
.
actor
=
content
.
author_with_anonymity
notification
.
target
=
content
receivers
=
new_user_ids
.
map
{
|
id
|
User
.
find
(
id
)
}
receivers
.
delete
(
content
.
author
)
notification
.
receivers
<<
receivers
...
...
models/observers/post_reply_observer.rb
View file @
e32f8e54
...
...
@@ -24,10 +24,9 @@ class PostReplyObserver < Mongoid::Observer
comment_id:
comment
.
id
,
commentable_id:
comment
.
comment_thread
.
commentable_id
,
actor_username:
comment
.
author_with_anonymity
(
:username
),
actor_id:
comment
.
author_with_anonymity
(
:id
),
},
)
notification
.
actor
=
comment
.
author_with_anonymity
notification
.
target
=
comment
receivers
=
(
comment
.
comment_thread
.
subscribers
+
comment
.
author_with_anonymity
(
:followers
,
[])).
uniq_by
(
&
:id
)
receivers
.
delete
(
comment
.
author
)
notification
.
receivers
<<
receivers
...
...
models/observers/post_topic_observer.rb
View file @
e32f8e54
...
...
@@ -6,6 +6,14 @@ class PostTopicObserver < Mongoid::Observer
end
def
self
.
generate_notifications
(
comment_thread
)
activity
=
Activity
.
new
activity
.
happend_at
=
comment_thread
.
created_at
activity
.
anonymous
=
comment_thread
.
anonymous
activity
.
actor
=
comment_thread
.
author
#activity.target_id = comment_thread.commentable.id
#activity.target_type = comment_thread.commentable._type
activity
.
activity_type
=
"post_topic"
activity
.
save!
if
comment_thread
.
commentable
.
subscribers
or
(
author
.
followers
if
not
anonymous
)
notification
=
Notification
.
new
(
notification_type:
"post_topic"
,
...
...
@@ -14,10 +22,9 @@ class PostTopicObserver < Mongoid::Observer
thread_id:
comment_thread
.
id
,
thread_title:
comment_thread
.
title
,
actor_username:
comment_thread
.
author_with_anonymity
(
:username
),
actor_id:
comment_thread
.
author_with_anonymity
(
:id
),
},
)
notification
.
actor
=
comment_thread
.
author_with_anonymity
notification
.
target
=
comment_thread
receivers
=
(
comment_thread
.
commentable
.
subscribers
+
comment_thread
.
author_with_anonymity
(
:followers
,
[])).
uniq_by
(
&
:id
)
receivers
.
delete
(
comment_thread
.
author
)
notification
.
receivers
<<
receivers
...
...
spec/spec_helper.rb
View file @
e32f8e54
ENV
[
"SINATRA_ENV"
]
=
"test"
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'app'
)
require
'sinatra'
...
...
@@ -20,6 +22,10 @@ RSpec.configure do |config|
config
.
include
Rack
::
Test
::
Methods
end
Mongoid
.
configure
do
|
config
|
config
.
connect_to
"cs_comments_service_test"
end
def
parse
(
text
)
Yajl
::
Parser
.
parse
text
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