Update tests for unbanning users
This commit is contained in:
parent
a9392dad53
commit
7677ed21a4
|
@ -118,7 +118,7 @@ class Ajax::ModerationController < AjaxController
|
||||||
reason = params[:reason].to_s
|
reason = params[:reason].to_s
|
||||||
target_user = User.find_by_screen_name!(params[:user])
|
target_user = User.find_by_screen_name!(params[:user])
|
||||||
unban = params[:ban] == '0'
|
unban = params[:ban] == '0'
|
||||||
perma = params[:duration].nil?
|
perma = params[:duration].blank?
|
||||||
|
|
||||||
if !unban && target_user.has_role?(:administrator)
|
if !unban && target_user.has_role?(:administrator)
|
||||||
@response[:status] = :nopriv
|
@response[:status] = :nopriv
|
||||||
|
|
|
@ -224,7 +224,7 @@ class User < ApplicationRecord
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
def banned?
|
def banned?
|
||||||
self.bans.current.any?
|
self.bans.current.count > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def unban
|
def unban
|
||||||
|
|
|
@ -9,7 +9,8 @@ module UseCase
|
||||||
|
|
||||||
def call
|
def call
|
||||||
UserBan.current.where(user_id: target_user_id).update_all(
|
UserBan.current.where(user_id: target_user_id).update_all(
|
||||||
expires_at: DateTime.now
|
# -1s to account for flakyness with timings in tests
|
||||||
|
expires_at: DateTime.now - 1.second
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -443,15 +443,14 @@ describe Ajax::ModerationController, :ajax_controller, type: :controller do
|
||||||
|
|
||||||
context "when ban = 1" do
|
context "when ban = 1" do
|
||||||
let(:ban) { "1" }
|
let(:ban) { "1" }
|
||||||
|
|
||||||
|
context "when permaban = 0" do
|
||||||
let(:duration) { 3 }
|
let(:duration) { 3 }
|
||||||
let(:duration_unit) { 'hours' }
|
let(:duration_unit) { 'hours' }
|
||||||
|
|
||||||
context "when permaban = 0" do
|
|
||||||
let(:permaban) { "0" }
|
|
||||||
|
|
||||||
it "bans the user for 3 hours" do
|
it "bans the user for 3 hours" do
|
||||||
Timecop.freeze do
|
Timecop.freeze do
|
||||||
expect { subject }.to(change { target_user.reload.banned? }.from(false).to(true))
|
expect { subject }.to change { target_user.reload.banned? }.from(false).to(true)
|
||||||
expect(target_user.bans.current.first.reason).to eq("just a prank, bro")
|
expect(target_user.bans.current.first.reason).to eq("just a prank, bro")
|
||||||
expect(target_user.bans.current.first.expires_at.to_i).to eq((Time.now.utc + 3.hours).to_i)
|
expect(target_user.bans.current.first.expires_at.to_i).to eq((Time.now.utc + 3.hours).to_i)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue