fixes #2822: Post vote API: returns 200 for both success and failure; fixes bug with x-api-limit header
This commit is contained in:
@@ -109,14 +109,12 @@ class Comment < ActiveRecord::Base
|
||||
module VoteMethods
|
||||
def vote!(val)
|
||||
numerical_score = val == "up" ? 1 : -1
|
||||
vote = votes.create(:score => numerical_score)
|
||||
vote = votes.create!(:score => numerical_score)
|
||||
|
||||
if vote.errors.empty?
|
||||
if vote.is_positive?
|
||||
update_column(:score, score + 1)
|
||||
elsif vote.is_negative?
|
||||
update_column(:score, score - 1)
|
||||
end
|
||||
if vote.is_positive?
|
||||
update_column(:score, score + 1)
|
||||
elsif vote.is_negative?
|
||||
update_column(:score, score - 1)
|
||||
end
|
||||
|
||||
return vote
|
||||
|
||||
@@ -1075,7 +1075,7 @@ class Post < ActiveRecord::Base
|
||||
raise PostVote::Error.new("You have already voted for this post")
|
||||
end
|
||||
|
||||
PostVote.create(:post_id => id, :score => score)
|
||||
PostVote.create!(:post_id => id, :score => score)
|
||||
reload # PostVote.create modifies our score. Reload to get the new score.
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user