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
a980d848
Commit
a980d848
authored
May 17, 2013
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comment out observer-related stuff.
parent
f8e3aadb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
158 additions
and
154 deletions
+158
-154
spec/api/subscription_and_notification_spec.rb
+111
-109
spec/models/at_user_observer_spec.rb
+47
-45
No files found.
spec/api/subscription_and_notification_spec.rb
View file @
a980d848
require
'spec_helper'
describe
"app"
do
describe
"subscriptions and notifications"
do
before
(
:each
)
{
init_with_subscriptions
}
describe
"GET /api/v1/users/:user_id/notifications"
do
it
"get all notifications on the subscribed comment threads for the user"
do
user
=
User
.
find
(
"1"
)
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
last_response
.
should
be_ok
notifications
=
parse
last_response
.
body
so_easy
=
Comment
.
all
.
select
{
|
c
|
c
.
body
==
"this problem is so easy"
}.
first
not_for_me_neither
=
Comment
.
all
.
select
{
|
c
|
c
.
body
==
"not for me neither!"
}.
first
notification_so_easy
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_reply"
and
f
[
"info"
][
"comment_id"
]
==
so_easy
.
id
.
to_s
}.
first
notification_so_easy
.
should_not
be_nil
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_not_for_me_neither
.
should_not
be_nil
end
it
"returns error if user does not exist"
do
#TODO may change later if have user service
get
"/api/v1/users/does_not_exist/notifications"
last_response
.
status
.
should
==
400
end
it
"get all notifications on the subscribed commentable for the user"
do
user
=
User
.
find
(
"1"
)
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
last_response
.
should
be_ok
notifications
=
parse
last_response
.
body
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
length
.
should
==
1
problem_wrong
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
first
problem_wrong
[
"info"
][
"thread_title"
].
should
==
"This problem is wrong"
end
it
"get all notifications on the followed user for the user"
do
user
=
User
.
find
(
"2"
)
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
last_response
.
should
be_ok
notifications
=
parse
last_response
.
body
notifications
.
select
{
|
f
|
f
[
"info"
][
"thread_title"
]
=~
/what to say/
}.
first
.
should_not
be_nil
end
end
describe
"POST /api/v1/users/:user_id/subscriptions"
do
it
"follow user"
do
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
last_response
.
should
be_ok
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
User
.
find
(
"2"
).
followers
.
should
include
user1
end
it
"does not follow the same user twice"
do
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user2
.
external_id
last_response
.
should
be_ok
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
end
it
"does not follow oneself"
do
user
=
create_test_user
(
3
)
post
"/api/v1/users/
#{
user
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user
.
external_id
last_response
.
status
.
should
==
400
user
.
reload
.
followers
.
length
.
should
==
0
end
it
"unfollow user"
do
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
last_response
.
should
be_ok
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
end
it
"respond ok when unfollowing user twice"
do
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"user"
,
source_id:
user1
.
external_id
last_response
.
should
be_ok
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
end
it
"subscribe a commentable"
do
user3
=
create_test_user
(
3
)
post
"/api/v1/users/
#{
user3
.
external_id
}
/subscriptions"
,
source_type:
"other"
,
source_id:
"question_1"
last_response
.
should
be_ok
Commentable
.
find
(
"question_1"
).
subscribers
.
length
.
should
==
3
Commentable
.
find
(
"question_1"
).
subscribers
.
should
include
user3
end
it
"unsubscribe a commentable"
do
user2
=
User
.
find_by
(
external_id:
"2"
)
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"other"
,
source_id:
"question_1"
last_response
.
should
be_ok
Commentable
.
find
(
"question_1"
).
subscribers
.
length
.
should
==
1
Commentable
.
find
(
"question_1"
).
subscribers
.
should_not
include
user2
end
it
"subscribe a comment thread"
do
user1
=
User
.
find_by
(
external_id:
"1"
)
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
source_type:
"thread"
,
source_id:
thread
.
id
last_response
.
should
be_ok
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
subscribers
.
length
.
should
==
2
thread
.
subscribers
.
should
include
user1
end
it
"unsubscribe a comment thread"
do
user2
=
User
.
find_by
(
external_id:
"2"
)
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
source_type:
"thread"
,
source_id:
thread
.
id
last_response
.
should
be_ok
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
subscribers
.
length
.
should
==
0
end
end
end
end
# Commenting out until notifications are used again.
#
#describe "app" do
# describe "subscriptions and notifications" do
# before(:each) { init_with_subscriptions }
# describe "GET /api/v1/users/:user_id/notifications" do
# it "get all notifications on the subscribed comment threads for the user" do
# user = User.find("1")
# get "/api/v1/users/#{user.external_id}/notifications"
# last_response.should be_ok
# notifications = parse last_response.body
# so_easy = Comment.all.select{|c| c.body == "this problem is so easy"}.first
# not_for_me_neither = Comment.all.select{|c| c.body == "not for me neither!"}.first
# notification_so_easy = notifications.select{|f| f["notification_type"] == "post_reply" and f["info"]["comment_id"] == so_easy.id.to_s}.first
# notification_so_easy.should_not be_nil
# 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_not_for_me_neither.should_not be_nil
# end
# it "returns error if user does not exist" do #TODO may change later if have user service
# get "/api/v1/users/does_not_exist/notifications"
# last_response.status.should == 400
# end
# it "get all notifications on the subscribed commentable for the user" do
# user = User.find("1")
# get "/api/v1/users/#{user.external_id}/notifications"
# last_response.should be_ok
# notifications = parse last_response.body
# notifications.select{|f| f["notification_type"] == "post_topic"}.length.should == 1
# problem_wrong = notifications.select{|f| f["notification_type"] == "post_topic"}.first
# problem_wrong["info"]["thread_title"].should == "This problem is wrong"
# end
# it "get all notifications on the followed user for the user" do
# user = User.find("2")
# get "/api/v1/users/#{user.external_id}/notifications"
# last_response.should be_ok
# notifications = parse last_response.body
# notifications.select{|f| f["info"]["thread_title"] =~ /what to say/}.first.should_not be_nil
# end
# end
# describe "POST /api/v1/users/:user_id/subscriptions" do
# it "follow user" do
# user1 = User.find("1")
# user2 = User.find("2")
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
# last_response.should be_ok
# User.find("2").followers.length.should == 1
# User.find("2").followers.should include user1
# end
# it "does not follow the same user twice" do
# user1 = User.find("1")
# user2 = User.find("2")
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "user", source_id: user2.external_id
# last_response.should be_ok
# User.find("2").followers.length.should == 1
# end
# it "does not follow oneself" do
# user = create_test_user(3)
# post "/api/v1/users/#{user.external_id}/subscriptions", source_type: "user", source_id: user.external_id
# last_response.status.should == 400
# user.reload.followers.length.should == 0
# end
# it "unfollow user" do
# user1 = User.find("1")
# user2 = User.find("2")
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
# last_response.should be_ok
# User.find("1").followers.length.should == 0
# end
# it "respond ok when unfollowing user twice" do
# user1 = User.find("1")
# user2 = User.find("2")
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "user", source_id: user1.external_id
# last_response.should be_ok
# User.find("1").followers.length.should == 0
# end
# it "subscribe a commentable" do
# user3 = create_test_user(3)
# post "/api/v1/users/#{user3.external_id}/subscriptions", source_type: "other", source_id: "question_1"
# last_response.should be_ok
# Commentable.find("question_1").subscribers.length.should == 3
# Commentable.find("question_1").subscribers.should include user3
# end
# it "unsubscribe a commentable" do
# user2 = User.find_by(external_id: "2")
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "other", source_id: "question_1"
# last_response.should be_ok
# Commentable.find("question_1").subscribers.length.should == 1
# Commentable.find("question_1").subscribers.should_not include user2
# end
# it "subscribe a comment thread" do
# user1 = User.find_by(external_id: "1")
# thread = CommentThread.where(body: "it is unsolvable").first
# post "/api/v1/users/#{user1.external_id}/subscriptions", source_type: "thread", source_id: thread.id
# last_response.should be_ok
# thread = CommentThread.where(body: "it is unsolvable").first
# thread.subscribers.length.should == 2
# thread.subscribers.should include user1
# end
# it "unsubscribe a comment thread" do
# user2 = User.find_by(external_id: "2")
# thread = CommentThread.where(body: "it is unsolvable").first
# delete "/api/v1/users/#{user2.external_id}/subscriptions", source_type: "thread", source_id: thread.id
# last_response.should be_ok
# thread = CommentThread.where(body: "it is unsolvable").first
# thread.subscribers.length.should == 0
# end
# end
# end
#end
spec/models/at_user_observer_spec.rb
View file @
a980d848
require
'spec_helper'
describe
AtUserObserver
do
before
:each
do
@text
=
"""
hi @tom, I have a question from @pi314 about the following code:
```
class A
def set_some_variable
@some_variable = 1
end
end
```
and also the following code
class A
def get_some_variable
@some_variable
end
end
what is the 'at' symbol doing there? @dementrock
"""
User
.
delete_all
User
.
create!
(
external_id:
"1"
,
username:
"tom"
,
email:
"tom@test.com"
)
User
.
create!
(
external_id:
"2"
,
username:
"pi314"
,
email:
"pi314@test.com"
)
end
describe
"#get_marked_text(text)"
do
it
"returns marked at text"
do
converted
=
AtUserObserver
.
send
:get_marked_text
,
@text
converted
.
should
include
"@tom_0"
converted
.
should
include
"@pi314_1"
converted
.
should
include
"@some_variable_2"
converted
.
should
include
"@some_variable_3"
converted
.
should
include
"@dementrock_4"
end
end
describe
"#get_valid_at_position_list(text)"
do
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
list
.
should
include
({
position:
0
,
username:
"tom"
,
user_id:
"1"
})
list
.
should
include
({
position:
1
,
username:
"pi314"
,
user_id:
"2"
})
list
.
length
.
should
==
2
end
end
end
# Commenting out until notifications are used again.
#
#describe AtUserObserver do
# before :each do
# @text =
#"""
#hi @tom, I have a question from @pi314 about the following code:
#```
#class A
# def set_some_variable
# @some_variable = 1
# end
#end
#```
#and also the following code
# class A
# def get_some_variable
# @some_variable
# end
# end
#what is the 'at' symbol doing there? @dementrock
#"""
# User.delete_all
# User.create!(external_id: "1", username: "tom", email: "tom@test.com")
# User.create!(external_id: "2", username: "pi314", email: "pi314@test.com")
# end
#
# describe "#get_marked_text(text)" do
# it "returns marked at text" do
# converted = AtUserObserver.send :get_marked_text, @text
# converted.should include "@tom_0"
# converted.should include "@pi314_1"
# converted.should include "@some_variable_2"
# converted.should include "@some_variable_3"
# converted.should include "@dementrock_4"
# end
# end
#
# describe "#get_valid_at_position_list(text)" do
# 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
# list.should include({ position: 0, username: "tom", user_id: "1" })
# list.should include({ position: 1, username: "pi314", user_id: "2" })
# list.length.should == 2
# end
# 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