mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
FIX Read-Modify-Write issue with dynamic fields (#290)
* FIX Read-Modify-Write issue with dynamic fields Ruby caching + queueing updates might cause some dynamic fields to not be updated. * Small fix for true dynamic fields * Add suite of tests for new settings page * Treat nil values as deletions to keep the hash clean * Test fix
This commit is contained in:
@@ -70,10 +70,14 @@ class Setting < RailsSettings::Base
|
||||
if respond_to?("#{key_str}=")
|
||||
public_send("#{key_str}=", value)
|
||||
else
|
||||
# Otherwise, store in dynamic_fields hash
|
||||
# Otherwise, manage in dynamic_fields hash
|
||||
current_dynamic = dynamic_fields.dup
|
||||
current_dynamic[key_str] = value
|
||||
self.dynamic_fields = current_dynamic
|
||||
if value.nil?
|
||||
current_dynamic.delete(key_str) # treat nil as delete
|
||||
else
|
||||
current_dynamic[key_str] = value
|
||||
end
|
||||
self.dynamic_fields = current_dynamic # persists & busts cache
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user