2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe UserField do
|
2024-05-23 07:18:25 -04:00
|
|
|
it do
|
|
|
|
is_expected.to define_enum_for(:requirement).with_values(%w[optional for_all_users on_signup])
|
|
|
|
end
|
|
|
|
|
2019-03-13 13:40:43 -04:00
|
|
|
describe "doesn't validate presence of name if field type is 'confirm'" do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:confirm_field) { described_class.new(field_type: "confirm") }
|
|
|
|
|
2019-03-13 13:40:43 -04:00
|
|
|
it { is_expected.not_to validate_presence_of :name }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validates presence of name for other field types" do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:dropdown_field) { described_class.new(field_type: "dropdown") }
|
|
|
|
|
2019-03-13 13:40:43 -04:00
|
|
|
it { is_expected.to validate_presence_of :name }
|
|
|
|
end
|
2021-10-27 10:33:07 -04:00
|
|
|
|
|
|
|
it "sanitizes the description" do
|
|
|
|
xss = "<b onmouseover=alert('Wufff!')>click me!</b><script>alert('TEST');</script>"
|
|
|
|
user_field = Fabricate(:user_field)
|
|
|
|
|
|
|
|
user_field.update!(description: xss)
|
|
|
|
|
|
|
|
expect(user_field.description).to eq("<b>click me!</b>alert('TEST');")
|
|
|
|
end
|
2023-01-06 08:18:35 -05:00
|
|
|
|
|
|
|
it "allows target attribute in the description" do
|
|
|
|
link = "<a target=\"_blank\" href=\"/elsewhere\">elsewhere</a>"
|
|
|
|
user_field = Fabricate(:user_field)
|
|
|
|
|
|
|
|
user_field.update!(description: link)
|
|
|
|
|
|
|
|
expect(user_field.description).to eq(link)
|
|
|
|
end
|
2024-04-25 08:58:34 -04:00
|
|
|
|
|
|
|
it "enqueues index user fields job on save" do
|
|
|
|
user_field = Fabricate(:user_field)
|
|
|
|
|
|
|
|
user_field.update!(description: "tomtom")
|
|
|
|
|
|
|
|
expect(
|
|
|
|
job_enqueued?(job: Jobs::IndexUserFieldsForSearch, args: { user_field_id: user_field.id }),
|
|
|
|
).to eq(true)
|
|
|
|
end
|
2024-05-23 07:18:25 -04:00
|
|
|
|
|
|
|
describe "#required?" do
|
|
|
|
let(:user_field) { Fabricate(:user_field, requirement:) }
|
|
|
|
|
|
|
|
context "when requirement is optional" do
|
|
|
|
let(:requirement) { "optional" }
|
|
|
|
|
|
|
|
it { expect(user_field).not_to be_required }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when requirement is for all users" do
|
|
|
|
let(:requirement) { "for_all_users" }
|
|
|
|
|
|
|
|
it { expect(user_field).to be_required }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when requirement is on signup" do
|
|
|
|
let(:requirement) { "on_signup" }
|
|
|
|
|
|
|
|
it { expect(user_field).to be_required }
|
|
|
|
end
|
|
|
|
end
|
2019-03-13 13:40:43 -04:00
|
|
|
end
|