Commit 8e94bfd8 by Rocky Duan

spec for votes; cover more errors

parent 3e1eb13a
......@@ -151,6 +151,10 @@ error BSON::InvalidObjectId do
error 400, "requested object not found"
end
error Mongoid::Errors::DocumentNotFound do
error 400, "requested object not found"
end
error ValueError do
error 400, env['sinatra.error'].message
end
......@@ -60,6 +60,20 @@ describe "app" do
thread.up_votes_count.should == prev_up_votes - 1
thread.down_votes_count.should == prev_down_votes + 1
end
it "returns 400 when the thread does not exist" do
put "/api/v1/threads/does_not_exist/votes", user_id: User.first.id, value: "down"
last_response.status.should == 400
end
it "returns 400 when user_id is not provided" do
put "/api/v1/threads/#{CommentThread.first.id}/votes", value: "down"
last_response.status.should == 400
end
it "returns 400 when value is not provided or invalid" do
put "/api/v1/threads/#{CommentThread.first.id}/votes", user_id: User.first.id
last_response.status.should == 400
put "/api/v1/threads/#{CommentThread.first.id}/votes", user_id: User.first.id, value: "superdown"
last_response.status.should == 400
end
end
describe "DELETE /api/v1/threads/:thread_id/votes" do
it "unvote on the thread" do
......@@ -72,6 +86,14 @@ describe "app" do
thread.up_votes_count.should == prev_up_votes - 1
thread.down_votes_count.should == prev_down_votes
end
it "returns 400 when the comment does not exist" do
delete "/api/v1/threads/does_not_exist/votes", user_id: User.first.id
last_response.status.should == 400
end
it "returns 400 when user_id is not provided" do
delete "/api/v1/threads/#{CommentThread.first.id}/votes"
last_response.status.should == 400
end
end
end
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