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
83989fc2
Commit
83989fc2
authored
Jul 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
another autosave bug; fix seed task
parent
d89aa9ee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
14 deletions
+35
-14
Rakefile
+21
-12
config/application.rb
+12
-0
models/user.rb
+2
-2
No files found.
Rakefile
View file @
83989fc2
...
...
@@ -4,7 +4,6 @@ require 'bundler'
Bundler
.
setup
Bundler
.
require
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
desc
"Load the environment"
task
:environment
do
...
...
@@ -12,6 +11,12 @@ task :environment do
Sinatra
::
Base
.
environment
=
env
Mongoid
.
load!
(
"config/mongoid.yml"
)
Mongoid
.
logger
.
level
=
Logger
::
INFO
module
CommentService
class
<<
self
;
attr_accessor
:config
;
end
end
CommentService
.
config
=
YAML
.
load_file
(
"config/application.yml"
)
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
end
namespace
:test
do
...
...
@@ -78,27 +83,31 @@ namespace :db do
level_limit
=
YAML
.
load_file
(
"config/application.yml"
)[
"level_limit"
]
user
=
User
.
create!
(
id:
"1"
)
users
=
(
1
..
10
).
map
{
|
id
|
User
.
find_or_create_by
(
external_id:
id
.
to_s
)}
10
.
times
do
users
.
sample
.
follow
(
users
.
sample
)
end
def
generate_comments
(
commentable_type
,
commentable_id
,
level_limit
,
user
)
def
generate_comments
(
commentable_type
,
commentable_id
,
level_limit
,
user
s
)
commentable
=
Commentable
.
create!
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
5
.
times
do
comment_thread
=
commentable
.
comment_threads
.
new
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
,
body:
"This is a post"
,
title:
"Post No.
#{
rand
(
10
)
}
"
,
course_id:
"1"
)
comment_thread
.
author
=
user
comment_thread
.
author
=
user
s
.
sample
comment_thread
.
save!
3
.
times
do
comment
=
comment_thread
.
comments
.
new
(
body:
"top comment"
,
course_id:
"1"
)
comment
.
author
=
user
comment
.
author
=
user
s
.
sample
comment
.
endorsed
=
[
true
,
false
].
sample
comment
.
save!
end
10
.
times
do
comment
=
Comment
.
where
(
comment_thread_id:
comment_thread
.
id
).
reject
{
|
c
|
c
.
depth
>=
level_limit
}.
sample
sub_comment
=
comment
.
children
.
new
(
body:
"comment body"
,
course_id:
"1"
)
sub_comment
.
author
=
user
sub_comment
.
author
=
user
s
.
sample
sub_comment
.
endorsed
=
[
true
,
false
].
sample
sub_comment
.
save!
end
...
...
@@ -106,16 +115,16 @@ namespace :db do
end
end
generate_comments
(
"questions"
,
1
,
level_limit
,
user
)
generate_comments
(
"questions"
,
2
,
level_limit
,
user
)
generate_comments
(
"courses"
,
1
,
level_limit
,
user
)
generate_comments
(
"lectures"
,
1
,
level_limit
,
user
)
generate_comments
(
"lectures"
,
2
,
level_limit
,
user
)
generate_comments
(
"questions"
,
1
,
level_limit
,
user
s
)
generate_comments
(
"questions"
,
2
,
level_limit
,
user
s
)
generate_comments
(
"courses"
,
1
,
level_limit
,
user
s
)
generate_comments
(
"lectures"
,
1
,
level_limit
,
user
s
)
generate_comments
(
"lectures"
,
2
,
level_limit
,
user
s
)
puts
"voting"
users
=
[]
(
1
..
10
).
each
do
|
id
|
users
<<
User
.
find_or_create_by
(
id:
id
.
to_s
)
users
<<
User
.
find_or_create_by
(
external_
id:
id
.
to_s
)
end
CommentThread
.
all
.
each
do
|
c
|
...
...
config/application.rb
0 → 100644
View file @
83989fc2
env_index
=
ARGV
.
index
(
"-e"
)
env_arg
=
ARGV
[
env_index
+
1
]
if
env_index
env
=
env_arg
||
ENV
[
"SINATRA_ENV"
]
||
"development"
module
CommentService
class
<<
self
;
attr_accessor
:config
;
end
end
CommentService
.
config
=
YAML
.
load_file
(
"config/application.yml"
)
Mongoid
.
load!
(
"config/mongoid.yml"
)
Mongoid
.
logger
.
level
=
Logger
::
INFO
models/user.rb
View file @
83989fc2
...
...
@@ -8,8 +8,8 @@ class User
has_many
:comment_threads
,
inverse_of: :author
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
:followers
,
class_name:
"User"
,
inverse_of: :followings
has_and_belongs_to_many
:followings
,
class_name:
"User"
,
inverse_of: :followers
,
autosave:
true
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
#
, autosave: true
validates_presence_of
:external_id
validates_uniqueness_of
:external_id
...
...
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