2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-07-23 17:58:26 -04:00
|
|
|
|
2013-09-10 21:21:16 -04:00
|
|
|
describe UserHistory do
|
2014-02-28 16:30:45 -05:00
|
|
|
|
2016-01-08 05:53:52 -05:00
|
|
|
describe '#actions' do
|
|
|
|
context "verify enum sequence" do
|
|
|
|
before do
|
|
|
|
@actions = UserHistory.actions
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-02-28 16:30:45 -05:00
|
|
|
describe '#staff_action_records' do
|
|
|
|
context "with some records" do
|
|
|
|
before do
|
2017-07-27 21:20:09 -04: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")
|
2014-02-28 16:30:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns all records for admins" do
|
|
|
|
records = described_class.staff_action_records(Fabricate(:admin)).to_a
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(records.size).to eq(2)
|
2014-02-28 16:30:45 -05: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
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(records).to eq([@change_trust_level])
|
2014-02-28 16:30:45 -05:00
|
|
|
end
|
2019-03-27 16:29:15 -04:00
|
|
|
|
|
|
|
it 'filters by action' do
|
|
|
|
records = described_class.staff_action_records(Fabricate(:admin), action_id: @change_site_setting.action_before_type_cast).to_a
|
|
|
|
expect(records.size).to eq(1)
|
|
|
|
expect(records.first).to eq(@change_site_setting)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by action_name' do
|
|
|
|
records = described_class.staff_action_records(Fabricate(:admin), action_name: "change_site_setting").to_a
|
|
|
|
expect(records.size).to eq(1)
|
|
|
|
expect(records.first).to eq(@change_site_setting)
|
|
|
|
end
|
2014-02-28 16:30:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-23 17:58:26 -04:00
|
|
|
end
|