mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
0f4beab0fb
This enables cops related to RSpec `subject`. See https://github.com/discourse/rubocop-discourse/pull/32
34 lines
1.0 KiB
Ruby
34 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserField do
|
|
describe "doesn't validate presence of name if field type is 'confirm'" do
|
|
subject(:confirm_field) { described_class.new(field_type: "confirm") }
|
|
|
|
it { is_expected.not_to validate_presence_of :name }
|
|
end
|
|
|
|
describe "validates presence of name for other field types" do
|
|
subject(:dropdown_field) { described_class.new(field_type: "dropdown") }
|
|
|
|
it { is_expected.to validate_presence_of :name }
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
end
|