mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 07:33:37 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe TimezoneValidator do
|
|
describe "#valid?" do
|
|
context "when timezone is ok" do
|
|
it "returns true" do
|
|
expect(described_class.valid?("Australia/Brisbane")).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "when timezone is not ok" do
|
|
it "returns false" do
|
|
expect(described_class.valid?("Mars")).to eq(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#validate_each" do
|
|
let(:record) { Fabricate(:active_user).user_option }
|
|
|
|
context "when timezone is ok" do
|
|
it "adds no errors to the record" do
|
|
record.timezone = "Australia/Melbourne"
|
|
record.save
|
|
expect(record.errors.full_messages.empty?).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "when timezone is blank" do
|
|
it "adds no errors to the record" do
|
|
record.timezone = nil
|
|
record.save
|
|
expect(record.errors.full_messages.empty?).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "when timezone is not ok" do
|
|
it "adds errors to the record" do
|
|
record.timezone = "Mars"
|
|
record.save
|
|
expect(record.errors.full_messages).to include(
|
|
"Timezone 'Mars' is not a valid timezone"
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|