2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe UserHistory do
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#actions" do
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when verifying enum sequence" do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { @actions = UserHistory.actions }
|
2016-01-08 04:53:52 -06:00
|
|
|
|
|
|
|
it "'delete_user' should be at 1st position" do
|
|
|
|
expect(@actions[:delete_user]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'change_site_text' should be at 29th position" do
|
|
|
|
expect(@actions[:change_site_text]).to eq(29)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#staff_action_records" do
|
2014-02-28 15:30:45 -06:00
|
|
|
context "with some records" do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:custom_type) { "confirmed_ham" }
|
2019-04-10 07:53:17 -05:00
|
|
|
|
2014-02-28 15:30:45 -06:00
|
|
|
before do
|
2023-01-09 05:18:21 -06:00
|
|
|
@change_site_setting =
|
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:change_site_setting],
|
|
|
|
subject: "title",
|
|
|
|
previous_value: "Old",
|
|
|
|
new_value: "New",
|
|
|
|
)
|
|
|
|
@change_trust_level =
|
|
|
|
UserHistory.create!(
|
|
|
|
action: UserHistory.actions[:change_trust_level],
|
|
|
|
target_user_id: Fabricate(:user).id,
|
|
|
|
details: "stuff happened",
|
|
|
|
)
|
|
|
|
@custom_history = StaffActionLogger.new(admin).log_custom("confirmed_ham", admin_only: true)
|
2014-02-28 15:30:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns all records for admins" do
|
2019-04-10 07:53:17 -05:00
|
|
|
records = described_class.staff_action_records(admin).to_a
|
|
|
|
expect(records.size).to eq(3)
|
2014-02-28 15:30:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't return records to moderators that only admins should see" do
|
|
|
|
records = described_class.staff_action_records(Fabricate(:moderator)).to_a
|
2019-04-10 07:53:17 -05:00
|
|
|
expect(records).not_to include([@change_site_setting])
|
2014-02-28 15:30:45 -06:00
|
|
|
end
|
2019-03-27 15:29:15 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "filters by action" do
|
|
|
|
records =
|
|
|
|
described_class.staff_action_records(
|
|
|
|
admin,
|
|
|
|
action_id: @change_site_setting.action_before_type_cast,
|
|
|
|
).to_a
|
2019-03-27 15:29:15 -05:00
|
|
|
expect(records.size).to eq(1)
|
|
|
|
expect(records.first).to eq(@change_site_setting)
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "filters by action_name" do
|
|
|
|
records =
|
|
|
|
described_class.staff_action_records(admin, action_name: "change_site_setting").to_a
|
2019-03-27 15:29:15 -05:00
|
|
|
expect(records.size).to eq(1)
|
|
|
|
expect(records.first).to eq(@change_site_setting)
|
|
|
|
end
|
2019-04-10 07:53:17 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "Uses action_name as custom_type when searching for custom_staff logs" do
|
|
|
|
records =
|
|
|
|
described_class.staff_action_records(
|
|
|
|
admin,
|
|
|
|
action_name: custom_type,
|
|
|
|
action_id: described_class.actions[:custom_staff],
|
|
|
|
).to_a
|
2019-04-10 07:53:17 -05:00
|
|
|
|
|
|
|
expect(records.size).to eq(1)
|
|
|
|
expect(records.first).to eq(@custom_history)
|
|
|
|
end
|
2014-02-28 15:30:45 -06:00
|
|
|
end
|
|
|
|
end
|
2013-07-23 16:58:26 -05:00
|
|
|
end
|