fixes #1792
This commit is contained in:
5
app/views/comment_votes/create.json.erb
Normal file
5
app/views/comment_votes/create.json.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<% if @comment_vote.errors.any? %>
|
||||||
|
{"success": false, "errors": <%= @comment_vote.errors.full_messages.to_json.html_safe %>}
|
||||||
|
<% else %>
|
||||||
|
{"success": true}
|
||||||
|
<% end %>
|
||||||
@@ -14,18 +14,39 @@ class CommentVotesControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create a vote" do
|
context "#create.json" do
|
||||||
assert_difference("CommentVote.count", 1) do
|
should "create a vote" do
|
||||||
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
assert_difference("CommentVote.count", 1) do
|
||||||
assert_response :success
|
post :create, {:format => "json", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
assert_equal("{\"success\": true}", @response.body.strip)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "fail silently on errors" do
|
||||||
|
FactoryGirl.create(:comment_vote, :comment => @comment)
|
||||||
|
assert_difference("CommentVote.count", 0) do
|
||||||
|
post :create, {:format => "json", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
||||||
|
assert_response 422
|
||||||
|
assert_equal("{\"errors\":{\"user_id\":[\"have already voted for this comment\"]}}", @response.body.strip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fail silently on errors" do
|
context "#create.js" do
|
||||||
FactoryGirl.create(:comment_vote, :comment => @comment)
|
should "create a vote" do
|
||||||
assert_difference("CommentVote.count", 0) do
|
assert_difference("CommentVote.count", 1) do
|
||||||
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "fail silently on errors" do
|
||||||
|
FactoryGirl.create(:comment_vote, :comment => @comment)
|
||||||
|
assert_difference("CommentVote.count", 0) do
|
||||||
|
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user