Commit a23e6f5f by Kevin Chugh

Merge pull request #27 from rll/feature/kevin/flagging

update object identifier in API cal
parents fb968957 b9a8f441
......@@ -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
......
put "#{APIPREFIX}/threads/:thread_id/abuse_flags" do |thread_id|
put "#{APIPREFIX}/threads/:thread_id/abuse_flag" do |thread_id|
flag_as_abuse thread
end
put "#{APIPREFIX}/threads/:thread_id/abuse_unflags" 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_flags" do |thread_id|
put "#{APIPREFIX}/comments/:comment_id/abuse_flag" do |comment_id|
flag_as_abuse comment
end
put "#{APIPREFIX}/comments/:comment_id/abuse_unflags" 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
require 'spec_helper'
def create_comment_flag(comment_id, user_id)
create_flag("/api/v1/comments/" + comment_id + "/abuse_flags", 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_flags", 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_unflags", 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_unflags", 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment