Skip to content

Commit

Permalink
validate format for SettingsChange#key
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jul 26, 2023
1 parent 7a18b54 commit af56a21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/settings_change.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SettingsChange < ApplicationRecord
serialize :value

validates :key, :format => %r{\A/[^/]+(/[^/]+)*\z}
belongs_to :resource, :polymorphic => true

def key_path
Expand Down
9 changes: 9 additions & 0 deletions spec/models/settings_change_spec.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit af56a21

Please sign in to comment.