mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Added spec tests
This commit is contained in:
parent
b4f4cf794b
commit
95fa340601
3 changed files with 15 additions and 0 deletions
|
@ -8,6 +8,7 @@ class PostActionsController < ApplicationController
|
|||
def create
|
||||
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], is_warning: params[:is_warning])
|
||||
|
||||
args = {}
|
||||
args[:message] = params[:message] if params[:message].present?
|
||||
|
|
|
@ -32,6 +32,9 @@ module PostGuardian
|
|||
# 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)) &&
|
||||
|
||||
# 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
|
||||
not(action_key == :notify_user && !SiteSetting.enable_private_messages) &&
|
||||
|
||||
|
|
|
@ -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'
|
||||
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
|
||||
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'
|
||||
|
|
Loading…
Reference in a new issue