FEATURE: allow for a localized error when a regex fails in site settings

FEATURE: apply string validation to list site settings (so we get regex)
This commit is contained in:
Sam
2015-02-27 11:45:56 +11:00
parent ea40dd08e6
commit 0742f340f9
7 changed files with 26 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ describe SiteSettingExtension do
describe "refresh!" do
it "will reset to default if provider vanishes" do
settings.setting(:hello, 1)
settings.hello = 100
@@ -167,6 +168,22 @@ describe SiteSettingExtension do
end
end
describe "string setting with regex" do
it "Supports custom validation errors" do
settings.setting(:test_str, "bob", regex: "hi", regex_error: "oops")
settings.refresh!
begin
settings.test_str = "a"
rescue Discourse::InvalidParameters => e
message = e.message
end
message.should =~ /oops/
end
end
describe "bool setting" do
before do
settings.setting(:test_hello?, false)