0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-12 05:37:26 +08:00
discourse/spec/lib/validators/group_setting_validator_spec.rb
chapoi 604f14237e
DEV: add type:group (#40981)
Allows the use of `type:group` in plugins to select only 1 group in the
UI:
```
  some_group:
    default: ""
    type: "group"
```

<img width="712" height="108" alt="CleanShot 2026-06-17 at 12 59 40"
src="https://github.com/user-attachments/assets/36d328e9-3a3b-4e01-b6f1-a754b8657114"
/>
2026-06-17 15:07:37 +02:00

30 lines
927 B
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe GroupSettingValidator do
describe "#valid_value?" do
subject(:validator) { described_class.new }
fab!(:group) { Fabricate(:group, name: "hello") }
it "returns true for blank values" do
expect(validator.valid_value?("")).to eq(true)
expect(validator.valid_value?(nil)).to eq(true)
end
it "returns true if value matches an existing group id" do
expect(validator.valid_value?(group.id.to_s)).to eq(true)
end
it "returns true if value matches an existing group name" do
expect(validator.valid_value?(group.name)).to eq(true)
end
it "returns false if value does not match a group id" do
expect(validator.valid_value?("-9999")).to eq(false)
end
it "returns false for a non-numeric value that does not match a group name" do
expect(validator.valid_value?("notagroup")).to eq(false)
end
end
end