raise if non writable setting is attempted to be written

pull/10296/head
ulferts 3 years ago
parent 098fcfe59d
commit 07801a8cf8
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 6
      app/models/setting.rb
  2. 2
      app/seeders/basic_data/setting_seeder.rb
  3. 13
      spec/models/setting_spec.rb

@ -156,8 +156,10 @@ class Setting < ApplicationRecord
self.class.deserialize(name, read_attribute(:value))
end
def value=(v)
write_attribute(:value, formatted_value(v))
def value=(val)
raise NoMethodError unless Settings::Definition[name].writable?
write_attribute(:value, formatted_value(val))
end
def formatted_value(value)

@ -47,7 +47,7 @@ module BasicData
def data
@settings ||= begin
settings = Setting.definitions.each_with_object({}) do |definition, hash|
settings = Setting.definitions.select(&:writable?).each_with_object({}) do |definition, hash|
hash[definition.name] = definition.value || ''
end

@ -29,6 +29,10 @@
require 'spec_helper'
describe Setting, type: :model do
before do
described_class.clear_cache
end
after do
described_class.destroy_all
end
@ -128,6 +132,11 @@ describe Setting, type: :model do
expect(described_class.app_title)
.to eql('New title')
end
it 'raises an error for a non writable setting' do
expect { described_class.smtp_openssl_verify_mode = 'none' }
.to raise_error NoMethodError
end
end
describe '.[setting]_writable?' do
@ -205,10 +214,6 @@ describe Setting, type: :model do
# Check that when reading certain setting values that they get overwritten if needed.
describe "filter saved settings" do
before do
described_class.work_package_list_default_highlighting_mode = "inline"
end
describe "with EE token", with_ee: [:conditional_highlighting] do
it "returns the value for 'work_package_list_default_highlighting_mode' without changing it" do
expect(described_class.work_package_list_default_highlighting_mode).to eq("inline")

Loading…
Cancel
Save