DEV: introduce new API to look up dynamic site setting

This removes all uses of both `send` and `public_send` from consumers of
SiteSetting and instead introduces a `get` helper for dynamic lookup

This leads to much cleaner and safer code long term as we are always explicit
to test that a site setting is really there before sending an arbitrary
string to the class

It also removes a couple of risky stubs from the auth provider test
This commit is contained in:
Sam Saffron
2019-05-07 11:00:30 +10:00
parent 47995d2d89
commit 9be70a22cd
33 changed files with 99 additions and 73 deletions
+3 -3
View File
@@ -95,7 +95,7 @@ module SeedData
def create_category(site_setting_name:, name:, description:, position:, color:, text_color:,
permissions:, force_permissions:, force_existence: false)
category_id = SiteSetting.send(site_setting_name)
category_id = SiteSetting.get(site_setting_name)
if should_create_category?(category_id, force_existence)
category = Category.new(
@@ -111,7 +111,7 @@ module SeedData
category.set_permissions(permissions)
category.save!
SiteSetting.send("#{site_setting_name}=", category.id)
SiteSetting.set(site_setting_name, category.id)
elsif category = Category.find_by(id: category_id)
if description.present? && (category.topic_id.blank? || !Topic.exists?(category.topic_id))
category.description = description
@@ -159,7 +159,7 @@ module SeedData
end
def find_category(site_setting_name)
category_id = SiteSetting.send(site_setting_name)
category_id = SiteSetting.get(site_setting_name)
Category.find_by(id: category_id) if category_id > 0
end