2024-05-22 22:19:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe Flag, type: :model do
|
2024-05-23 22:55:21 -04:00
|
|
|
after(:each) { Flag.reset_flag_settings! }
|
2024-05-22 22:19:07 -04:00
|
|
|
|
|
|
|
it "has id lower than 1000 for system flags" do
|
|
|
|
flag = Fabricate(:flag, id: 1)
|
|
|
|
expect(flag.system?).to be true
|
2024-05-23 22:55:21 -04:00
|
|
|
flag.destroy!
|
2024-05-22 22:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has id greater than 1000 for non-system flags" do
|
|
|
|
flag = Fabricate(:flag)
|
|
|
|
expect(flag.system?).to be false
|
|
|
|
expect(flag.id).to be > 1000
|
2024-05-23 22:55:21 -04:00
|
|
|
flag.destroy!
|
2024-05-22 22:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has correct name key" do
|
|
|
|
flag = Fabricate(:flag, name: "CuStOm Flag!!!")
|
|
|
|
expect(flag.name_key).to eq("custom_flag")
|
|
|
|
|
|
|
|
flag.update!(name: "It's Illegal")
|
|
|
|
expect(flag.name_key).to eq("its_illegal")
|
|
|
|
|
|
|
|
flag.update!(name: "THIS IS SPaM!+)(*&^%$#@@@!)")
|
|
|
|
expect(flag.name_key).to eq("this_is_spam")
|
2024-05-23 22:55:21 -04:00
|
|
|
|
|
|
|
flag.destroy!
|
2024-05-22 22:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "updates post action types when created, modified or destroyed" do
|
|
|
|
expect(PostActionType.flag_types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
expect(ReviewableScore.types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators needs_approval],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
flag = Fabricate(:flag, name: "custom")
|
|
|
|
expect(PostActionType.flag_types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators custom],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
expect(ReviewableScore.types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators custom needs_approval],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
flag.update!(name: "edited_custom")
|
|
|
|
expect(PostActionType.flag_types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators edited_custom],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
expect(ReviewableScore.types.keys).to eq(
|
|
|
|
%i[
|
|
|
|
notify_user
|
|
|
|
off_topic
|
|
|
|
inappropriate
|
|
|
|
spam
|
|
|
|
illegal
|
2024-06-06 01:45:30 -04:00
|
|
|
notify_moderators
|
2024-05-22 22:19:07 -04:00
|
|
|
edited_custom
|
|
|
|
needs_approval
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
flag.destroy!
|
|
|
|
expect(PostActionType.flag_types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
expect(ReviewableScore.types.keys).to eq(
|
2024-06-06 01:45:30 -04:00
|
|
|
%i[notify_user off_topic inappropriate spam illegal notify_moderators needs_approval],
|
2024-05-22 22:19:07 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|