From 96ddc47b77f3d52483e2df28353ea930cf7ad6c6 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 26 May 2020 16:36:26 -0300 Subject: [PATCH] no cambiar el valor a true de los checkboxes closes #153 --- app/models/metadata_boolean.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/models/metadata_boolean.rb b/app/models/metadata_boolean.rb index 113b9d5f..a06ab7da 100644 --- a/app/models/metadata_boolean.rb +++ b/app/models/metadata_boolean.rb @@ -14,15 +14,18 @@ class MetadataBoolean < MetadataTemplate # # En este caso, queremos priorizar el dato enviado por le usuarie # antes que el generado internamente. + # + # Tenemos varios casos: + # + # * nil => false + # * '0' => false + # * '1' => true + # * false + # * true def value - return false if self[:value] == '0' - return self[:value] unless self[:value].nil? + return document.data.fetch(name.to_s, default_value) if self[:value].nil? + return self[:value] unless self[:value].is_a? String - document.data.fetch(name.to_s, default_value) - end - - def save - self[:value] = !%w[0 false].include?(self[:value]) - true + self[:value] = self[:value] == '1' end end