summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2018-12-14 22:42:07 +0800
committerRémy Coutable <remy@rymai.me>2018-12-19 11:24:54 +0100
commitcc5099c5ce79a7c062e2197b47f5f8a81bb48292 (patch)
tree379058dc0f48c627767e02c8787e42dd19808880
parent1ae28e0e7b5996536e4c8005c362d3f82088c77c (diff)
downloadgitlab-ce-cc5099c5ce79a7c062e2197b47f5f8a81bb48292.tar.gz
Move schema aware defaults to build_from_defaults
This way we can reuse the safe setting
-rw-r--r--app/models/concerns/cacheable_attributes.rb7
-rw-r--r--lib/gitlab/current_settings.rb9
2 files changed, 7 insertions, 9 deletions
diff --git a/app/models/concerns/cacheable_attributes.rb b/app/models/concerns/cacheable_attributes.rb
index 75592bb63e2..3d60f6924c1 100644
--- a/app/models/concerns/cacheable_attributes.rb
+++ b/app/models/concerns/cacheable_attributes.rb
@@ -23,7 +23,12 @@ module CacheableAttributes
end
def build_from_defaults(attributes = {})
- new(defaults.merge(attributes))
+ final_attributes = defaults
+ .merge(attributes)
+ .stringify_keys
+ .slice(*column_names)
+
+ new(final_attributes)
end
def cached
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb
index 168542f77e6..570bfb80fba 100644
--- a/lib/gitlab/current_settings.rb
+++ b/lib/gitlab/current_settings.rb
@@ -47,14 +47,7 @@ module Gitlab
# defaults for missing columns.
if ActiveRecord::Migrator.needs_migration?
db_attributes = current_settings&.attributes || {}
- column_names = ::ApplicationSetting.column_names
- final_attributes = ::ApplicationSetting
- .defaults
- .merge(db_attributes)
- .stringify_keys
- .slice(*column_names)
-
- ::ApplicationSetting.new(final_attributes)
+ ::ApplicationSetting.build_from_defaults(db_attributes)
elsif current_settings.present?
current_settings
else