2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-11 09:36:15 -06:00
|
|
|
RSpec.describe GroupActionLogger do
|
2023-06-21 09:00:19 -05:00
|
|
|
subject(:logger) { described_class.new(group_owner, group) }
|
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:group_owner) { Fabricate(:user) }
|
|
|
|
fab!(:group) { Fabricate(:group) }
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { group.add_owner(group_owner) }
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#log_make_user_group_owner" do
|
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_make_user_group_owner(user)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
|
|
|
group_history = GroupHistory.last
|
|
|
|
|
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:make_user_group_owner])
|
|
|
|
expect(group_history.acting_user).to eq(group_owner)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#log_remove_user_as_group_owner" do
|
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_remove_user_as_group_owner(user)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
|
|
|
group_history = GroupHistory.last
|
|
|
|
|
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:remove_user_as_group_owner])
|
|
|
|
expect(group_history.acting_user).to eq(group_owner)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#log_add_user_to_group" do
|
|
|
|
context "as a group owner" do
|
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_add_user_to_group(user)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2017-07-27 21:37:10 -05:00
|
|
|
group_history = GroupHistory.last
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2017-07-27 21:37:10 -05:00
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:add_user_to_group])
|
|
|
|
expect(group_history.acting_user).to eq(group_owner)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "as a normal user" do
|
2023-06-21 09:00:19 -05:00
|
|
|
subject(:logger) { described_class.new(user, group) }
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { group.update!(public_admission: true) }
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_add_user_to_group(user)
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2021-07-28 06:04:04 -05:00
|
|
|
group_history = GroupHistory.last
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2021-07-28 06:04:04 -05:00
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:add_user_to_group])
|
|
|
|
expect(group_history.acting_user).to eq(user)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
2017-07-27 21:37:10 -05:00
|
|
|
end
|
2016-12-11 09:36:15 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#log_remove_user_from_group" do
|
|
|
|
context "as group owner" do
|
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_remove_user_from_group(user)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2017-07-27 21:37:10 -05:00
|
|
|
group_history = GroupHistory.last
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2017-07-27 21:37:10 -05:00
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:remove_user_from_group])
|
|
|
|
expect(group_history.acting_user).to eq(group_owner)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
context "as a normal user" do
|
2023-06-21 09:00:19 -05:00
|
|
|
subject(:logger) { described_class.new(user, group) }
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { group.update!(public_exit: true) }
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "should create the right record" do
|
2023-06-21 09:00:19 -05:00
|
|
|
logger.log_remove_user_from_group(user)
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2021-07-28 06:04:04 -05:00
|
|
|
group_history = GroupHistory.last
|
2017-07-27 21:37:10 -05:00
|
|
|
|
2021-07-28 06:04:04 -05:00
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:remove_user_from_group])
|
|
|
|
expect(group_history.acting_user).to eq(user)
|
|
|
|
expect(group_history.target_user).to eq(user)
|
2017-07-27 21:37:10 -05:00
|
|
|
end
|
2016-12-11 09:36:15 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#log_change_group_settings" do
|
|
|
|
it "should create the right record" do
|
2019-04-29 02:32:25 -05:00
|
|
|
group.update!(public_admission: true, created_at: Time.zone.now)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
2023-06-21 09:00:19 -05:00
|
|
|
expect { logger.log_change_group_settings }.to change { GroupHistory.count }.by(1)
|
2016-12-11 09:36:15 -06:00
|
|
|
|
|
|
|
group_history = GroupHistory.last
|
|
|
|
|
|
|
|
expect(group_history.action).to eq(GroupHistory.actions[:change_group_setting])
|
|
|
|
expect(group_history.acting_user).to eq(group_owner)
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(group_history.subject).to eq("public_admission")
|
|
|
|
expect(group_history.prev_value).to eq("f")
|
|
|
|
expect(group_history.new_value).to eq("t")
|
2016-12-11 09:36:15 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|