diff --git a/app/models/settings_change.rb b/app/models/settings_change.rb index 7d1b732d883..61720a1bfd5 100644 --- a/app/models/settings_change.rb +++ b/app/models/settings_change.rb @@ -1,6 +1,7 @@ class SettingsChange < ApplicationRecord serialize :value + validates :key, :format => %r{\A/[^/]+(/[^/]+)*\z} belongs_to :resource, :polymorphic => true def key_path diff --git a/spec/models/settings_change_spec.rb b/spec/models/settings_change_spec.rb index 69c891ffe78..38e8f523fba 100644 --- a/spec/models/settings_change_spec.rb +++ b/spec/models/settings_change_spec.rb @@ -1,4 +1,13 @@ RSpec.describe SettingsChange do + describe "#key" do + it "validates with a good key" do + expect(described_class.new(:key => "/api/token")).to be_valid + end + + it "doesn't validate with a bad key" do + expect(described_class.new(:key => "api/token")).not_to be_valid + end + end describe "#key_path" do it "with multiple parts in the key" do change = described_class.new(:key => "/api/token_ttl")