mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-08 05:58:27 +08:00
Implement a `datetime` type for site settings and object site settings
You can implement this type as so:
```
test_setting:
default: ""
client: true
type: "datetime"
```
- Add necessary validations
- Add tests
### Preview
<img width="670" height="264" alt="Screenshot 2025-12-29 at 11 59 13 AM"
src="https://github.com/user-attachments/assets/48d330e3-a38c-4d6a-9ea7-c4271b3e360e"
/>
24 lines
762 B
Ruby
24 lines
762 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DatetimeSettingValidator do
|
|
describe "#valid_value?" do
|
|
subject(:validator) { described_class.new }
|
|
|
|
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 for valid ISO 8601 datetime with Z suffix" do
|
|
expect(validator.valid_value?("2024-12-29T15:30:00Z")).to eq(true)
|
|
end
|
|
|
|
it "returns true for valid ISO 8601 datetime with timezone offset" do
|
|
expect(validator.valid_value?("2024-12-29T15:30:00+05:30")).to eq(true)
|
|
end
|
|
|
|
it "returns false for invalid datetime strings" do
|
|
expect(validator.valid_value?("not a datetime")).to eq(false)
|
|
end
|
|
end
|
|
end
|