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
6074efe7
Commit
6074efe7
authored
May 22, 2013
by
Arjun Singh
Browse files
Options
Browse Files
Download
Plain Diff
Merge hotfix/speedups_5_12_new
parents
5ca634ba
a980d848
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
237 additions
and
170 deletions
+237
-170
Rakefile
+3
-3
api/comment_threads.rb
+1
-1
api/users.rb
+15
-4
app.rb
+9
-4
models/comment.rb
+26
-3
models/comment_thread.rb
+1
-1
spec/api/comment_thread_spec.rb
+23
-0
spec/api/subscription_and_notification_spec.rb
+111
-109
spec/models/at_user_observer_spec.rb
+47
-45
spec/spec_helper.rb
+1
-0
No files found.
Rakefile
View file @
6074efe7
...
@@ -24,10 +24,10 @@ task :environment do
...
@@ -24,10 +24,10 @@ task :environment do
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/observers/*.rb'
].
each
{
|
file
|
require
file
}
#
Dir[File.dirname(__FILE__) + '/models/observers/*.rb'].each {|file| require file}
Mongoid
.
observers
=
PostReplyObserver
,
PostTopicObserver
,
AtUserObserver
#
Mongoid.observers = PostReplyObserver, PostTopicObserver, AtUserObserver
Mongoid
.
instantiate_observers
#
Mongoid.instantiate_observers
end
end
...
...
api/comment_threads.rb
View file @
6074efe7
...
@@ -16,7 +16,7 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
...
@@ -16,7 +16,7 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
thread
=
CommentThread
.
find
(
thread_id
)
thread
=
CommentThread
.
find
(
thread_id
)
if
params
[
"user_id"
]
and
bool_mark_as_read
if
params
[
"user_id"
]
and
bool_mark_as_read
user
=
User
.
only
([
:id
,
:read_states
]).
find_by
(
external_id:
params
[
"user_id"
])
user
=
User
.
only
([
:id
,
:
username
,
:
read_states
]).
find_by
(
external_id:
params
[
"user_id"
])
user
.
mark_as_read
(
thread
)
if
user
user
.
mark_as_read
(
thread
)
if
user
end
end
...
...
api/users.rb
View file @
6074efe7
...
@@ -30,9 +30,20 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
...
@@ -30,9 +30,20 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
paged_active_contents
=
active_contents
.
page
(
page
).
per
(
per_page
)
paged_active_contents
=
active_contents
.
page
(
page
).
per
(
per_page
)
paged_active_threads
=
paged_active_contents
.
map
(
&
get_thread_id
)
paged_thread_ids
=
paged_active_contents
.
map
(
&
get_thread_id
).
uniq
.
uniq
.
map
(
&
get_thread
)
collection
=
paged_active_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
true
)}
# Find all the threads by id, and then put them in the order found earlier.
# Necessary because CommentThread.find does return results in the same
# order as the provided ids.
paged_active_threads
=
CommentThread
.
find
(
paged_thread_ids
).
sort_by
do
|
t
|
paged_thread_ids
.
index
(
t
.
id
)
end
# Fetch all the usernames in bulk to save on queries. Since we're using the
# identity map, the users won't need to be fetched again later.
User
.
only
(
:username
).
find
(
paged_active_threads
.
map
{
|
x
|
x
.
author_id
})
collection
=
paged_active_threads
.
map
{
|
t
|
t
.
to_hash
recursive:
true
}
collection
=
author_contents_only
(
collection
,
user_id
)
collection
=
author_contents_only
(
collection
,
user_id
)
{
{
...
@@ -40,7 +51,7 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
...
@@ -40,7 +51,7 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
num_pages:
num_pages
,
num_pages:
num_pages
,
page:
page
,
page:
page
,
}.
to_json
}.
to_json
end
end
put
"
#{
APIPREFIX
}
/users/:user_id"
do
|
user_id
|
put
"
#{
APIPREFIX
}
/users/:user_id"
do
|
user_id
|
...
...
app.rb
View file @
6074efe7
...
@@ -36,10 +36,11 @@ Mongoid.logger.level = Logger::INFO
...
@@ -36,10 +36,11 @@ Mongoid.logger.level = Logger::INFO
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/observers/*.rb'
].
each
{
|
file
|
require
file
}
Mongoid
.
observers
=
PostReplyObserver
,
PostTopicObserver
,
AtUserObserver
# Comment out observers until notifications are actually set up properly.
Mongoid
.
instantiate_observers
#Dir[File.dirname(__FILE__) + '/models/observers/*.rb'].each {|file| require file}
#Mongoid.observers = PostReplyObserver, PostTopicObserver, AtUserObserver
#Mongoid.instantiate_observers
APIPREFIX
=
CommentService
::
API_PREFIX
APIPREFIX
=
CommentService
::
API_PREFIX
DEFAULT_PAGE
=
1
DEFAULT_PAGE
=
1
...
@@ -51,8 +52,12 @@ if RACK_ENV.to_s != "test" # disable api_key auth in test environment
...
@@ -51,8 +52,12 @@ if RACK_ENV.to_s != "test" # disable api_key auth in test environment
end
end
end
end
# these files must be required in order
# Enable the identity map. The middleware ensures that the identity map is
# cleared for every request.
Mongoid
.
identity_map_enabled
=
true
use
Rack
::
Mongoid
::
Middleware
::
IdentityMap
# these files must be required in order
require
'./api/search'
require
'./api/search'
require
'./api/commentables'
require
'./api/commentables'
require
'./api/tags'
require
'./api/tags'
...
...
models/comment.rb
View file @
6074efe7
...
@@ -39,6 +39,22 @@ class Comment < Content
...
@@ -39,6 +39,22 @@ class Comment < Content
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
# This should really go somewhere else, but sticking it here for now. This is
# used to flatten out the subtree fetched by calling self.subtree. This is
# equivalent to calling descendants_and_self; however, calling
# descendants_and_self and subtree both is very inefficient. It's cheaper to
# just flatten out the subtree, and simpler than duplicating the code that
# actually creates the subtree.
def
self
.
flatten_subtree
(
x
)
if
x
.
is_a?
Array
x
.
flatten
.
map
{
|
y
|
self
.
flatten_subtree
(
y
)}
elsif
x
.
is_a?
Hash
x
.
to_a
.
map
{
|
y
|
self
.
flatten_subtree
(
y
)}.
flatten
else
x
end
end
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
sort_by_parent_and_time
=
Proc
.
new
do
|
x
,
y
|
sort_by_parent_and_time
=
Proc
.
new
do
|
x
,
y
|
arr_cmp
=
x
.
parent_ids
.
map
(
&
:to_s
)
<=>
y
.
parent_ids
.
map
(
&
:to_s
)
arr_cmp
=
x
.
parent_ids
.
map
(
&
:to_s
)
<=>
y
.
parent_ids
.
map
(
&
:to_s
)
...
@@ -49,15 +65,22 @@ class Comment < Content
...
@@ -49,15 +65,22 @@ class Comment < Content
end
end
end
end
if
params
[
:recursive
]
if
params
[
:recursive
]
self
.
class
.
hash_tree
(
subtree
(
sort:
sort_by_parent_and_time
)).
first
subtree_hash
=
subtree
(
sort:
sort_by_parent_and_time
)
# Flatten out the subtree and fetch all users in bulk; makes getting the
# usernames faster. Should probably denormalize usernames.
flattened_subtree
=
Comment
.
flatten_subtree
(
subtree_hash
)
User
.
only
(
:username
).
find
(
flattened_subtree
.
map
{
|
x
|
x
.
author_id
})
self
.
class
.
hash_tree
(
subtree_hash
).
first
else
else
as_document
.
slice
(
*
%w[body course_id endorsed anonymous anonymous_to_peers created_at updated_at at_position_list]
)
as_document
.
slice
(
*
%w[body course_id endorsed anonymous anonymous_to_peers created_at updated_at at_position_list]
)
.
merge
(
"id"
=>
_id
)
.
merge
(
"id"
=>
_id
)
.
merge
(
"user_id"
=>
author
.
id
)
.
merge
(
"user_id"
=>
author
_
id
)
.
merge
(
"username"
=>
author
.
username
)
.
merge
(
"username"
=>
author
.
username
)
.
merge
(
"depth"
=>
depth
)
.
merge
(
"depth"
=>
depth
)
.
merge
(
"closed"
=>
comment_thread
.
closed
)
.
merge
(
"closed"
=>
comment_thread
.
closed
)
.
merge
(
"thread_id"
=>
comment_thread
.
id
)
.
merge
(
"thread_id"
=>
comment_thread
_
id
)
.
merge
(
"commentable_id"
=>
comment_thread
.
commentable_id
)
.
merge
(
"commentable_id"
=>
comment_thread
.
commentable_id
)
.
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
.
merge
(
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
))
.
merge
(
"abuse_flaggers"
=>
abuse_flaggers
)
.
merge
(
"abuse_flaggers"
=>
abuse_flaggers
)
...
...
models/comment_thread.rb
View file @
6074efe7
...
@@ -172,7 +172,7 @@ class CommentThread < Content
...
@@ -172,7 +172,7 @@ class CommentThread < Content
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
doc
=
as_document
.
slice
(
*
%w[title body course_id anonymous anonymous_to_peers commentable_id created_at updated_at at_position_list closed]
)
doc
=
as_document
.
slice
(
*
%w[title body course_id anonymous anonymous_to_peers commentable_id created_at updated_at at_position_list closed]
)
.
merge
(
"id"
=>
_id
,
"user_id"
=>
author
.
id
,
.
merge
(
"id"
=>
_id
,
"user_id"
=>
author
_
id
,
"username"
=>
author
.
username
,
"username"
=>
author
.
username
,
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
),
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
),
"abuse_flaggers"
=>
abuse_flaggers
,
"abuse_flaggers"
=>
abuse_flaggers
,
...
...
spec/api/comment_thread_spec.rb
View file @
6074efe7
...
@@ -16,6 +16,28 @@ describe "app" do
...
@@ -16,6 +16,28 @@ describe "app" do
thread
.
commentable_id
.
should
==
response_thread
[
"commentable_id"
]
thread
.
commentable_id
.
should
==
response_thread
[
"commentable_id"
]
response_thread
[
"children"
].
should
be_nil
response_thread
[
"children"
].
should
be_nil
end
end
# This is a test to ensure that the username is included even if the
# thread's author is the one looking at the comment. This is because of a
# regression in which we used User.only(:id, :read_states). This worked
# before we included the identity map, but afterwards, the user was
# missing the username and was not refetched.
it
"includes the username even if the thread is being marked as read for the thread author"
do
thread
=
CommentThread
.
first
expected_username
=
thread
.
author
.
username
# We need to clear the IdentityMap after getting the expected data to
# ensure that this spec fails when it should. If we don't do this, then
# in the cases where the User is fetched without its username, the spec
# won't fail because the User will already be in the identity map.
Mongoid
::
IdentityMap
.
clear
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
{
:user_id
=>
thread
.
author_id
,
:mark_as_read
=>
true
}
last_response
.
should
be_ok
response_thread
=
parse
last_response
.
body
response_thread
[
"username"
].
should
==
expected_username
end
it
"get information of a single comment thread with its comments"
do
it
"get information of a single comment thread with its comments"
do
thread
=
CommentThread
.
first
thread
=
CommentThread
.
first
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
recursive:
true
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
recursive:
true
...
@@ -29,6 +51,7 @@ describe "app" do
...
@@ -29,6 +51,7 @@ describe "app" do
response_thread
[
"children"
].
length
.
should
==
thread
.
root_comments
.
length
response_thread
[
"children"
].
length
.
should
==
thread
.
root_comments
.
length
response_thread
[
"children"
].
index
{
|
c
|
c
[
"body"
]
==
thread
.
root_comments
.
first
.
body
}.
should_not
be_nil
response_thread
[
"children"
].
index
{
|
c
|
c
[
"body"
]
==
thread
.
root_comments
.
first
.
body
}.
should_not
be_nil
end
end
it
"returns 400 when the thread does not exist"
do
it
"returns 400 when the thread does not exist"
do
get
"/api/v1/threads/does_not_exist"
get
"/api/v1/threads/does_not_exist"
last_response
.
status
.
should
==
400
last_response
.
status
.
should
==
400
...
...
spec/api/subscription_and_notification_spec.rb
View file @
6074efe7
require
'spec_helper'
require
'spec_helper'
describe
"app"
do
# Commenting out until notifications are used again.
describe
"subscriptions and notifications"
do
#
before
(
:each
)
{
init_with_subscriptions
}
#describe "app" do
describe
"GET /api/v1/users/:user_id/notifications"
do
# describe "subscriptions and notifications" do
it
"get all notifications on the subscribed comment threads for the user"
do
# before(:each) { init_with_subscriptions }
user
=
User
.
find
(
"1"
)
# describe "GET /api/v1/users/:user_id/notifications" do
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
# it "get all notifications on the subscribed comment threads for the user" do
last_response
.
should
be_ok
# user = User.find("1")
notifications
=
parse
last_response
.
body
# get "/api/v1/users/#{user.external_id}/notifications"
so_easy
=
Comment
.
all
.
select
{
|
c
|
c
.
body
==
"this problem is so easy"
}.
first
# last_response.should be_ok
not_for_me_neither
=
Comment
.
all
.
select
{
|
c
|
c
.
body
==
"not for me neither!"
}.
first
# notifications = parse last_response.body
notification_so_easy
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_reply"
and
f
[
"info"
][
"comment_id"
]
==
so_easy
.
id
.
to_s
}.
first
# so_easy = Comment.all.select{|c| c.body == "this problem is so easy"}.first
notification_so_easy
.
should_not
be_nil
# not_for_me_neither = Comment.all.select{|c| c.body == "not for me neither!"}.first
notification_not_for_me_neither
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_reply"
and
f
[
"info"
][
"comment_id"
]
==
not_for_me_neither
.
id
.
to_s
}.
first
# notification_so_easy = notifications.select{|f| f["notification_type"] == "post_reply" and f["info"]["comment_id"] == so_easy.id.to_s}.first
notification_not_for_me_neither
.
should_not
be_nil
# notification_so_easy.should_not be_nil
end
# notification_not_for_me_neither = notifications.select{|f| f["notification_type"] == "post_reply" and f["info"]["comment_id"] == not_for_me_neither.id.to_s}.first
it
"returns error if user does not exist"
do
#TODO may change later if have user service
# notification_not_for_me_neither.should_not be_nil
get
"/api/v1/users/does_not_exist/notifications"
# end
last_response
.
status
.
should
==
400
# it "returns error if user does not exist" do #TODO may change later if have user service
end
# get "/api/v1/users/does_not_exist/notifications"
it
"get all notifications on the subscribed commentable for the user"
do
# last_response.status.should == 400
user
=
User
.
find
(
"1"
)
# end
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
# it "get all notifications on the subscribed commentable for the user" do
last_response
.
should
be_ok
# user = User.find("1")
notifications
=
parse
last_response
.
body
# get "/api/v1/users/#{user.external_id}/notifications"
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
length
.
should
==
1
# last_response.should be_ok
problem_wrong
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
first
# notifications = parse last_response.body
problem_wrong
[
"info"
][
"thread_title"
].
should
==
"This problem is wrong"
# notifications.select{|f| f["notification_type"] == "post_topic"}.length.should == 1
end
# problem_wrong = notifications.select{|f| f["notification_type"] == "post_topic"}.first
it
"get all notifications on the followed user for the user"
do
# problem_wrong["info"]["thread_title"].should == "This problem is wrong"
user
=
User
.
find
(
"2"
)
# end
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
# it "get all notifications on the followed user for the user" do
last_response
.
should
be_ok
# user = User.find("2")
notifications
=
parse
last_response
.
body
# get "/api/v1/users/#{user.external_id}/notifications"
notifications
.
select
{
|
f
|
f
[
"info"
][
"thread_title"
]
=~
/what to say/
}.
first
.
should_not
be_nil
# last_response.should be_ok
end
# notifications = parse last_response.body
end
# notifications.select{|f| f["info"]["thread_title"] =~ /what to say/}.first.should_not be_nil
describe
"POST /api/v1/users/:user_id/subscriptions"
do
# end
it
"follow user"
do
# end
user1
=
User
.
find
(
"1"
)
# describe "POST /api/v1/users/:user_id/subscriptions" do
user2
=
User
.
find
(
"2"
)
# it "follow user" do
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
# user1 = User.find("1")
last_response
.
should
be_ok
# user2 = User.find("2")
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
User
.
find
(
"2"
).
followers
.
should
include
user1
# last_response.should be_ok
end
# User.find("2").followers.length.should == 1
it
"does not follow the same user twice"
do
# User.find("2").followers.should include user1
user1
=
User
.
find
(
"1"
)
# end
user2
=
User
.
find
(
"2"
)
# it "does not follow the same user twice" do
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
# user1 = User.find("1")
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
# user2 = User.find("2")
last_response
.
should
be_ok
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
end
# last_response.should be_ok
it
"does not follow oneself"
do
# User.find("2").followers.length.should == 1
user
=
create_test_user
(
3
)
# end
post
"/api/v1/users/
#{
user
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user
.
external_id
# it "does not follow oneself" do
last_response
.
status
.
should
==
400
# user = create_test_user(3)
user
.
reload
.
followers
.
length
.
should
==
0
# post "/api/v1/users/#{user.external_id}/subscriptions", source_type: "user", source_id: user.external_id
end
# last_response.status.should == 400
it
"unfollow user"
do
# user.reload.followers.length.should == 0
user1
=
User
.
find
(
"1"
)
# end
user2
=
User
.
find
(
"2"
)
# it "unfollow user" do
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
# user1 = User.find("1")
last_response
.
should
be_ok
# user2 = User.find("2")
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
end
# last_response.should be_ok
it
"respond ok when unfollowing user twice"
do
# User.find("1").followers.length.should == 0
user1
=
User
.
find
(
"1"
)
# end
user2
=
User
.
find
(
"2"
)
# it "respond ok when unfollowing user twice" do
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
# user1 = User.find("1")
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
# user2 = User.find("2")
last_response
.
should
be_ok
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
end
# last_response.should be_ok
it
"subscribe a commentable"
do
# User.find("1").followers.length.should == 0
user3
=
create_test_user
(
3
)
# end
post
"/api/v1/users/
#{
user3
.
external_id
}
/subscriptions"
,
source_type:
"other"
,
source_id:
"question_1"
# it "subscribe a commentable" do
last_response
.
should
be_ok
# user3 = create_test_user(3)
Commentable
.
find
(
"question_1"
).
subscribers
.
length
.
should
==
3
# post "/api/v1/users/#{user3.external_id}/subscriptions", source_type: "other", source_id: "question_1"
Commentable
.
find
(
"question_1"
).
subscribers
.
should
include
user3
# last_response.should be_ok
end
# Commentable.find("question_1").subscribers.length.should == 3
it
"unsubscribe a commentable"
do
# Commentable.find("question_1").subscribers.should include user3
user2
=
User
.
find_by
(
external_id:
"2"
)
# end
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"other"
,
source_id:
"question_1"
# it "unsubscribe a commentable" do
last_response
.
should
be_ok
# user2 = User.find_by(external_id: "2")
Commentable
.
find
(
"question_1"
).
subscribers
.
length
.
should
==
1
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "other", source_id: "question_1"
Commentable
.
find
(
"question_1"
).
subscribers
.
should_not
include
user2
# last_response.should be_ok
end
# Commentable.find("question_1").subscribers.length.should == 1
it
"subscribe a comment thread"
do
# Commentable.find("question_1").subscribers.should_not include user2
user1
=
User
.
find_by
(
external_id:
"1"
)
# end
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
# it "subscribe a comment thread" do
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"thread"
,
source_id:
thread
.
id
# user1 = User.find_by(external_id: "1")
last_response
.
should
be_ok
# thread = CommentThread.where(body: "it is unsolvable").first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "thread", source_id: thread.id
thread
.
subscribers
.
length
.
should
==
2
# last_response.should be_ok
thread
.
subscribers
.
should
include
user1
# thread = CommentThread.where(body: "it is unsolvable").first
end
# thread.subscribers.length.should == 2
it
"unsubscribe a comment thread"
do
# thread.subscribers.should include user1
user2
=
User
.
find_by
(
external_id:
"2"
)
# end
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
# it "unsubscribe a comment thread" do
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"thread"
,
source_id:
thread
.
id
# user2 = User.find_by(external_id: "2")
last_response
.
should
be_ok
# thread = CommentThread.where(body: "it is unsolvable").first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "thread", source_id: thread.id
thread
.
subscribers
.
length
.
should
==
0
# last_response.should be_ok
end
# thread = CommentThread.where(body: "it is unsolvable").first
end
# thread.subscribers.length.should == 0
end
# end
end
# end
# end
#end
spec/models/at_user_observer_spec.rb
View file @
6074efe7
require
'spec_helper'
require
'spec_helper'
describe
AtUserObserver
do
# Commenting out until notifications are used again.
before
:each
do
#
@text
=
#describe AtUserObserver do
"""
# before :each do
hi @tom, I have a question from @pi314 about the following code:
# @text =
```
#"""
class A
#hi @tom, I have a question from @pi314 about the following code:
def set_some_variable
#```
@some_variable = 1
#class A
end
# def set_some_variable
end
# @some_variable = 1
```
# end
and also the following code
#end
class A
#```
def get_some_variable
#and also the following code
@some_variable
# class A
end
# def get_some_variable
end
# @some_variable
what is the 'at' symbol doing there? @dementrock
# end
"""
# end
User
.
delete_all
#what is the 'at' symbol doing there? @dementrock
User
.
create!
(
external_id:
"1"
,
username:
"tom"
,
email:
"tom@test.com"
)
#"""
User
.
create!
(
external_id:
"2"
,
username:
"pi314"
,
email:
"pi314@test.com"
)
# User.delete_all
end
# User.create!(external_id: "1", username: "tom", email: "tom@test.com")
# User.create!(external_id: "2", username: "pi314", email: "pi314@test.com")
describe
"#get_marked_text(text)"
do
# end
it
"returns marked at text"
do
#
converted
=
AtUserObserver
.
send
:get_marked_text
,
@text
# describe "#get_marked_text(text)" do
converted
.
should
include
"@tom_0"
# it "returns marked at text" do
converted
.
should
include
"@pi314_1"
# converted = AtUserObserver.send :get_marked_text, @text
converted
.
should
include
"@some_variable_2"
# converted.should include "@tom_0"
converted
.
should
include
"@some_variable_3"
# converted.should include "@pi314_1"
converted
.
should
include
"@dementrock_4"
# converted.should include "@some_variable_2"
end
# converted.should include "@some_variable_3"
end
# converted.should include "@dementrock_4"
# end
describe
"#get_valid_at_position_list(text)"
do
# end
it
"returns the list of positions for the valid @ notifications, filtering out the ones in code blocks"
do
#
list
=
AtUserObserver
.
send
:get_valid_at_position_list
,
@text
# describe "#get_valid_at_position_list(text)" do
list
.
should
include
({
position:
0
,
username:
"tom"
,
user_id:
"1"
})
# it "returns the list of positions for the valid @ notifications, filtering out the ones in code blocks" do
list
.
should
include
({
position:
1
,
username:
"pi314"
,
user_id:
"2"
})
# list = AtUserObserver.send :get_valid_at_position_list, @text
list
.
length
.
should
==
2
# list.should include({ position: 0, username: "tom", user_id: "1" })
end
# list.should include({ position: 1, username: "pi314", user_id: "2" })
end
# list.length.should == 2
end
# end
# end
#end
spec/spec_helper.rb
View file @
6074efe7
...
@@ -23,6 +23,7 @@ RSpec.configure do |config|
...
@@ -23,6 +23,7 @@ RSpec.configure do |config|
config
.
treat_symbols_as_metadata_keys_with_true_values
=
true
config
.
treat_symbols_as_metadata_keys_with_true_values
=
true
config
.
filter_run
focus:
true
config
.
filter_run
focus:
true
config
.
run_all_when_everything_filtered
=
true
config
.
run_all_when_everything_filtered
=
true
config
.
before
(
:each
)
{
Mongoid
::
IdentityMap
.
clear
}
end
end
Mongoid
.
configure
do
|
config
|
Mongoid
.
configure
do
|
config
|
...
...
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