Added spec tests

This commit is contained in:
cpradio 2016-04-03 19:44:14 -04:00
parent b4f4cf794b
commit 95fa340601
3 changed files with 15 additions and 0 deletions

View file

@ -8,6 +8,7 @@ class PostActionsController < ApplicationController
def create def create
taken = PostAction.counts_for([@post], current_user)[@post.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) guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id], taken_actions: taken)
guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id], is_warning: params[:is_warning])
args = {} args = {}
args[:message] = params[:message] if params[:message].present? args[:message] = params[:message] if params[:message].present?

View file

@ -32,6 +32,9 @@ module PostGuardian
# new users can't notify_user because they are not allowed to send private messages # new users can't notify_user because they are not allowed to send private messages
not(action_key == :notify_user && !@user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) && not(action_key == :notify_user && !@user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) &&
# non-staff can't send an official warning
not(action_key == :notify_user && !is_staff? && opts[:is_warning].present? && opts[:is_warning] == 'true') &&
# can't send private messages if they're disabled globally # can't send private messages if they're disabled globally
not(action_key == :notify_user && !SiteSetting.enable_private_messages) && not(action_key == :notify_user && !SiteSetting.enable_private_messages) &&

View file

@ -49,6 +49,17 @@ describe PostActionsController do
xhr :post, :create, id: @post.id, post_action_type_id: 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'
end end
it 'passes the message through as warning' do
PostAction.expects(:act).once.with(@user, @post, PostActionType.types[:like], {message: 'action message goes here', is_warning: true})
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like], message: 'action message goes here', is_warning: true
end
it "doesn't create message as a warning if the user isn't staff" do
Guardian.any_instance.stubs(:is_staff?).returns(false)
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', is_warning: true
end
it 'passes take_action through' do it 'passes take_action through' do
PostAction.expects(:act).once.with(@user, @post, PostActionType.types[:like], {take_action: true}) PostAction.expects(:act).once.with(@user, @post, PostActionType.types[:like], {take_action: true})
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like], take_action: 'true' xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like], take_action: 'true'