2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe UserField do
|
2019-03-14 01:40:43 +08:00
|
|
|
describe "doesn't validate presence of name if field type is 'confirm'" do
|
2023-01-09 19:18:21 +08:00
|
|
|
subject { described_class.new(field_type: "confirm") }
|
2019-03-14 01:40:43 +08:00
|
|
|
it { is_expected.not_to validate_presence_of :name }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validates presence of name for other field types" do
|
2023-01-09 19:18:21 +08:00
|
|
|
subject { described_class.new(field_type: "dropdown") }
|
2019-03-14 01:40:43 +08:00
|
|
|
it { is_expected.to validate_presence_of :name }
|
|
|
|
end
|
2021-10-27 22:33:07 +08:00
|
|
|
|
2023-01-09 19:18:21 +08:00
|
|
|
it "sanitizes the description" do
|
2021-10-27 22:33:07 +08:00
|
|
|
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 21:18:35 +08:00
|
|
|
|
2023-01-09 19:18:21 +08:00
|
|
|
it "allows target attribute in the description" do
|
2023-01-06 21:18:35 +08:00
|
|
|
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
|
2019-03-14 01:40:43 +08:00
|
|
|
end
|