add specs
This commit is contained in:
parent
d718ec31f7
commit
970b026e21
|
@ -5,4 +5,4 @@ en:
|
||||||
|
|
||||||
staff_notes:
|
staff_notes:
|
||||||
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
|
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
|
||||||
user_suspended: "@%{username} suspended this account till %{suspended_till}. Reason: %{reason}"
|
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
|
||||||
|
|
|
@ -152,7 +152,7 @@ after_initialize do
|
||||||
mount ::DiscourseStaffNotes::Engine, at: "/staff_notes"
|
mount ::DiscourseStaffNotes::Engine, at: "/staff_notes"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_model_callback :user_warning, :after_create do
|
add_model_callback(UserWarning, :after_commit, on: :create) do
|
||||||
user = User.find_by_id(self.user_id)
|
user = User.find_by_id(self.user_id)
|
||||||
created_by_user = User.find_by_id(self.created_by_id)
|
created_by_user = User.find_by_id(self.created_by_id)
|
||||||
warning_topic = Topic.find_by_id(self.topic_id)
|
warning_topic = Topic.find_by_id(self.topic_id)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe UserHistory do
|
||||||
|
let(:user) { Fabricate(:user, suspended_till: 7.days.from_now) }
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
|
describe 'when a user suspension log is created' do
|
||||||
|
context "staff notes plugin is enabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.staff_notes_enabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create staff note for suspension" do
|
||||||
|
UserHistory.create!({action: UserHistory.actions[:suspend_user], target_user_id: user.id, acting_user_id: admin.id})
|
||||||
|
|
||||||
|
expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,21 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe UserWarning do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
let(:topic) { Fabricate(:topic) }
|
||||||
|
|
||||||
|
describe 'when a user warning is created' do
|
||||||
|
context "staff notes plugin is enabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.staff_notes_enabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create staff note for warning" do
|
||||||
|
UserWarning.create({topic_id: topic.id, user_id: user.id, created_by_id: admin.id})
|
||||||
|
|
||||||
|
expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue