FIX: Prevent duplicate flags after undoing on the server side too.

This commit is contained in:
Robin Ward 2014-09-03 14:43:07 -04:00
parent a71640c15f
commit 1e281a909e
2 changed files with 9 additions and 2 deletions

View File

@ -7,7 +7,8 @@ class PostActionsController < ApplicationController
before_filter :fetch_post_action_type_id_from_params
def create
guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id])
taken = PostAction.counts_for([@post], current_user)[@post.id]
guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id], taken_actions: taken)
args = {}
args[:message] = params[:message] if params[:message].present?

View File

@ -28,7 +28,7 @@ describe PostActionsController do
end
it "fails when the user doesn't have permission to perform that action" do
Guardian.any_instance.expects(:post_can_act?).with(@post, :like).returns(false)
Guardian.any_instance.expects(:post_can_act?).with(@post, :like, taken_actions: nil).returns(false)
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
response.should be_forbidden
end
@ -38,6 +38,12 @@ describe PostActionsController do
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like]
end
it "passes a list of taken actions through" do
PostAction.create(post_id: @post.id, user_id: @user.id, post_action_type_id: PostActionType.types[:inappropriate])
Guardian.any_instance.expects(:post_can_act?).with(@post, :off_topic, has_entry({:taken_actions => has_key(PostActionType.types[:inappropriate])}))
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:off_topic]
end
it 'passes the message through' do
PostAction.expects(:act).once.with(@user, @post, PostActionType.types[:like], {message: 'action message goes here'})
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like], message: 'action message goes here'