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
3e6177cf
Commit
3e6177cf
authored
Jul 17, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed naming
parent
c5fa9f00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
24 deletions
+25
-24
app.rb
+8
-8
spec/app_spec.rb
+17
-16
No files found.
app.rb
View file @
3e6177cf
...
@@ -115,26 +115,26 @@ end
...
@@ -115,26 +115,26 @@ end
post
'/api/v1/users/:user_id/subscriptions'
do
|
user_id
|
post
'/api/v1/users/:user_id/subscriptions'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
source
=
case
params
[
"s
ubscribed
_type"
]
source
=
case
params
[
"s
ource
_type"
]
when
"user"
when
"user"
User
.
find_or_create_by
(
external_id:
params
[
"s
ubscribed
_id"
])
User
.
find_or_create_by
(
external_id:
params
[
"s
ource
_id"
])
when
"thread"
when
"thread"
CommentThread
.
find
(
params
[
"s
ubscribed
_id"
])
CommentThread
.
find
(
params
[
"s
ource
_id"
])
else
else
Commentable
.
find_or_create_by
(
commentable_type:
params
[
"s
ubscribed_type"
],
commentable_id:
params
[
"subscribed
_id"
])
Commentable
.
find_or_create_by
(
commentable_type:
params
[
"s
ource_type"
],
commentable_id:
params
[
"source
_id"
])
end
end
user
.
subscribe
(
source
).
to_hash
.
to_json
user
.
subscribe
(
source
).
to_hash
.
to_json
end
end
delete
'/api/v1/users/:user_id/subscriptions'
do
|
user_id
|
delete
'/api/v1/users/:user_id/subscriptions'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
source
=
case
params
[
"s
ubscribed
_type"
]
source
=
case
params
[
"s
ource
_type"
]
when
"user"
when
"user"
User
.
find_or_create_by
(
external_id:
params
[
"s
ubscribed
_id"
])
User
.
find_or_create_by
(
external_id:
params
[
"s
ource
_id"
])
when
"thread"
when
"thread"
CommentThread
.
find
(
params
[
"s
ubscribed
_id"
])
CommentThread
.
find
(
params
[
"s
ource
_id"
])
else
else
Commentable
.
find_or_create_by
(
commentable_type:
params
[
"s
ubscribed_type"
],
commentable_id:
params
[
"subscribed
_id"
])
Commentable
.
find_or_create_by
(
commentable_type:
params
[
"s
ource_type"
],
commentable_id:
params
[
"source
_id"
])
end
end
user
.
unsubscribe
(
source
).
to_hash
.
to_json
user
.
unsubscribe
(
source
).
to_hash
.
to_json
end
end
...
...
spec/app_spec.rb
View file @
3e6177cf
...
@@ -340,16 +340,16 @@ describe "app" do
...
@@ -340,16 +340,16 @@ describe "app" do
before
(
:each
)
{
init_with_subscriptions
}
before
(
:each
)
{
init_with_subscriptions
}
describe
"GET /api/v1/users/:user_id/notifications"
do
describe
"GET /api/v1/users/:user_id/notifications"
do
it
"get all notifications on the subscribed comment threads for the user"
do
it
"get all notifications on the subscribed comment threads for the user"
do
#
user = User.find("1")
user
=
User
.
find
(
"1"
)
#
get "/api/v1/users/#{user.external_id}/notifications"
get
"/api/v1/users/
#{
user
.
external_id
}
/notifications"
#
last_response.should be_ok
last_response
.
should
be_ok
#
notifications = parse last_response.body
notifications
=
parse
last_response
.
body
#
so_easy = Comment.all.select{|c| c.body == "this problem is so easy"}.first
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
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
=
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_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
=
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
notification_not_for_me_neither
.
should_not
be_nil
end
end
it
"get all notifications on the subscribed commentable for the user"
do
it
"get all notifications on the subscribed commentable for the user"
do
user
=
User
.
find
(
"1"
)
user
=
User
.
find
(
"1"
)
...
@@ -360,12 +360,13 @@ describe "app" do
...
@@ -360,12 +360,13 @@ describe "app" do
problem_wrong
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
first
problem_wrong
=
notifications
.
select
{
|
f
|
f
[
"notification_type"
]
==
"post_topic"
}.
first
problem_wrong
[
"info"
][
"thread_title"
].
should
==
"This problem is wrong"
problem_wrong
[
"info"
][
"thread_title"
].
should
==
"This problem is wrong"
end
end
# TODO spec for followed user
end
end
describe
"POST /api/v1/users/:user_id/subscriptions"
do
describe
"POST /api/v1/users/:user_id/subscriptions"
do
it
"follow user"
do
it
"follow user"
do
user1
=
User
.
find
(
"1"
)
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
user2
=
User
.
find
(
"2"
)
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"user"
,
subscribed
_id:
user2
.
external_id
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
s
ource_type:
"user"
,
source
_id:
user2
.
external_id
last_response
.
should
be_ok
last_response
.
should
be_ok
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
User
.
find
(
"2"
).
followers
.
length
.
should
==
1
User
.
find
(
"2"
).
followers
.
should
include
user1
User
.
find
(
"2"
).
followers
.
should
include
user1
...
@@ -373,20 +374,20 @@ describe "app" do
...
@@ -373,20 +374,20 @@ describe "app" do
it
"unfollow user"
do
it
"unfollow user"
do
user1
=
User
.
find
(
"1"
)
user1
=
User
.
find
(
"1"
)
user2
=
User
.
find
(
"2"
)
user2
=
User
.
find
(
"2"
)
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"user"
,
subscribed
_id:
user1
.
external_id
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ource_type:
"user"
,
source
_id:
user1
.
external_id
last_response
.
should
be_ok
last_response
.
should
be_ok
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
User
.
find
(
"1"
).
followers
.
length
.
should
==
0
end
end
it
"subscribe a commentable"
do
it
"subscribe a commentable"
do
user3
=
User
.
find_or_create_by
(
external_id:
"3"
)
user3
=
User
.
find_or_create_by
(
external_id:
"3"
)
post
"/api/v1/users/
#{
user3
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"questions"
,
subscribed
_id:
"1"
post
"/api/v1/users/
#{
user3
.
external_id
}
/subscriptions"
,
s
ource_type:
"questions"
,
source
_id:
"1"
last_response
.
should
be_ok
last_response
.
should
be_ok
Commentable
.
first
.
subscribers
.
length
.
should
==
3
Commentable
.
first
.
subscribers
.
length
.
should
==
3
Commentable
.
first
.
subscribers
.
should
include
user3
Commentable
.
first
.
subscribers
.
should
include
user3
end
end
it
"unsubscribe a commentable"
do
it
"unsubscribe a commentable"
do
user2
=
User
.
find_or_create_by
(
external_id:
"2"
)
user2
=
User
.
find_or_create_by
(
external_id:
"2"
)
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"questions"
,
subscribed
_id:
"1"
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ource_type:
"questions"
,
source
_id:
"1"
last_response
.
should
be_ok
last_response
.
should
be_ok
Commentable
.
first
.
subscribers
.
length
.
should
==
1
Commentable
.
first
.
subscribers
.
length
.
should
==
1
Commentable
.
first
.
subscribers
.
should_not
include
user2
Commentable
.
first
.
subscribers
.
should_not
include
user2
...
@@ -394,7 +395,7 @@ describe "app" do
...
@@ -394,7 +395,7 @@ describe "app" do
it
"subscribe a comment thread"
do
it
"subscribe a comment thread"
do
user1
=
User
.
find_or_create_by
(
external_id:
"1"
)
user1
=
User
.
find_or_create_by
(
external_id:
"1"
)
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"thread"
,
subscribed
_id:
thread
.
id
post
"/api/v1/users/
#{
user1
.
external_id
}
/subscriptions"
,
s
ource_type:
"thread"
,
source
_id:
thread
.
id
last_response
.
should
be_ok
last_response
.
should
be_ok
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
subscribers
.
length
.
should
==
2
thread
.
subscribers
.
length
.
should
==
2
...
@@ -403,7 +404,7 @@ describe "app" do
...
@@ -403,7 +404,7 @@ describe "app" do
it
"unsubscribe a comment thread"
do
it
"unsubscribe a comment thread"
do
user2
=
User
.
find_or_create_by
(
external_id:
"2"
)
user2
=
User
.
find_or_create_by
(
external_id:
"2"
)
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ubscribed_type:
"thread"
,
subscribed
_id:
thread
.
id
delete
"/api/v1/users/
#{
user2
.
external_id
}
/subscriptions"
,
s
ource_type:
"thread"
,
source
_id:
thread
.
id
last_response
.
should
be_ok
last_response
.
should
be_ok
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
=
CommentThread
.
where
(
body:
"it is unsolvable"
).
first
thread
.
subscribers
.
length
.
should
==
0
thread
.
subscribers
.
length
.
should
==
0
...
...
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