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
a23e6f5f
Commit
a23e6f5f
authored
Apr 24, 2013
by
Kevin Chugh
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from rll/feature/kevin/flagging
update object identifier in API cal
parents
fb968957
b9a8f441
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
11 deletions
+42
-11
Rakefile
+1
-1
api/flags.rb
+5
-4
spec/api/abuse_spec.rb
+36
-6
No files found.
Rakefile
View file @
a23e6f5f
...
...
@@ -156,7 +156,7 @@ namespace :db do
"comment_count"
=>
0
,
"title"
=>
Faker
::
Lorem
.
sentence
(
6
),
"author_id"
=>
rand
(
1
..
10
).
to_s
,
"body"
=>
Faker
::
Lorem
.
paragraphs
.
join
(
"
\n\n
"
),
"course_id"
=>
COURSE_ID
,
"created_at"
=>
Time
.
now
,
"commentable_id"
=>
COURSE_ID
,
"closed"
=>
[
true
,
false
].
sample
,
"updated_at"
=>
Time
.
now
,
"last_activity_at"
=>
Time
.
now
,
"votes"
=>
{
"count"
=>
0
,
"down"
=>
[],
"down_count"
=>
0
,
"point"
=>
0
,
"up"
=>
[],
"up_count"
=>
[]
,
"spoiler_count"
=>
[]
}}
"votes"
=>
{
"count"
=>
0
,
"down"
=>
[],
"down_count"
=>
0
,
"point"
=>
0
,
"up"
=>
[],
"up_count"
=>
[]}}
coll
.
insert
(
doc
)
end
binding
.
pry
...
...
api/flags.rb
View file @
a23e6f5f
put
"
#{
APIPREFIX
}
/threads/:thread_id/abuse_flag
s
"
do
|
thread_id
|
put
"
#{
APIPREFIX
}
/threads/:thread_id/abuse_flag"
do
|
thread_id
|
flag_as_abuse
thread
end
put
"
#{
APIPREFIX
}
/threads/:thread_id/abuse_unflag
s
"
do
|
thread_id
|
put
"
#{
APIPREFIX
}
/threads/:thread_id/abuse_unflag"
do
|
thread_id
|
un_flag_as_abuse
thread
end
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_flag
s"
do
|
thread
_id
|
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_flag
"
do
|
comment
_id
|
flag_as_abuse
comment
end
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_unflag
s"
do
|
thread
_id
|
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_unflag
"
do
|
comment
_id
|
un_flag_as_abuse
comment
end
\ No newline at end of file
spec/api/abuse_spec.rb
View file @
a23e6f5f
require
'spec_helper'
def
create_comment_flag
(
comment_id
,
user_id
)
create_flag
(
"/api/v1/comments/"
+
comment_id
+
"/abuse_flag
s
"
,
user_id
)
create_flag
(
"/api/v1/comments/"
+
comment_id
+
"/abuse_flag"
,
user_id
)
end
def
create_thread_flag
(
thread_id
,
user_id
)
create_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_flag
s
"
,
user_id
)
create_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_flag"
,
user_id
)
end
def
remove_thread_flag
(
thread_id
,
user_id
)
remove_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_unflag
s
"
,
user_id
)
remove_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_unflag"
,
user_id
)
end
def
remove_comment_flag
(
comment_id
,
user_id
)
remove_flag
(
"/api/v1/comments/"
+
comment_id
+
"/abuse_unflag
s
"
,
user_id
)
remove_flag
(
"/api/v1/comments/"
+
comment_id
+
"/abuse_unflag"
,
user_id
)
end
def
create_flag
(
put_command
,
user_id
)
if
user_id
.
nil?
if
user_id
.
nil?
put
put_command
else
put
put_command
,
user_id:
user_id
...
...
@@ -25,7 +25,7 @@ def create_flag(put_command, user_id)
end
def
remove_flag
(
put_command
,
user_id
)
if
user_id
.
nil?
if
user_id
.
nil?
put
put_command
else
put
put_command
,
user_id:
user_id
...
...
@@ -103,6 +103,36 @@ describe "app" do
comment
.
abuse_flaggers
.
to_a
.
should_not
include
User
.
first
.
id
end
it
"returns 400 when the thread does not exist"
do
remove_comment_flag
(
"does_not_exist"
,
User
.
first
.
id
)
last_response
.
status
.
should
==
400
end
it
"returns 400 when user_id is not provided"
do
remove_comment_flag
(
"
#{
Comment
.
first
.
comment_thread
.
id
}
"
,
nil
)
last_response
.
status
.
should
==
400
end
#Would like to test the output of to_hash, but not sure how to deal with a Moped::BSON::Document object
#it "has a correct hash" do
# create_thread_flag("#{Comment.first.comment_thread.id}", User.first.id)
# Comment.first.comment_thread.to_hash
#end
end
describe
"unflag a thread as abusive"
do
it
"removes the user from the existing abuse_flaggers"
do
thread
=
CommentThread
.
first
create_thread_flag
(
"
#{
thread
.
id
}
"
,
User
.
first
.
id
)
thread
=
CommentThread
.
first
prev_abuse_flaggers
=
thread
.
abuse_flaggers
prev_abuse_flaggers
.
should
include
User
.
first
.
id
remove_thread_flag
(
"
#{
thread
.
id
}
"
,
User
.
first
.
id
)
thread
=
CommentThread
.
find
(
thread
.
id
)
thread
.
abuse_flaggers
.
length
.
should
==
prev_abuse_flaggers
.
length
-
1
thread
.
abuse_flaggers
.
to_a
.
should_not
include
User
.
first
.
id
end
it
"returns 400 when the thread does not exist"
do
remove_thread_flag
(
"does_not_exist"
,
User
.
first
.
id
)
last_response
.
status
.
should
==
400
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