discourse/spec/lib/validators/timezone_validator_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
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