[ARVADOS] updated: 15cc0bc32eb57c02b566826598c6de2a8587ef9f

git at public.curoverse.com git at public.curoverse.com
Fri May 30 13:29:16 EDT 2014


Summary of changes:
 services/api/app/models/arvados_model.rb     | 29 ++++++++++++++++------------
 services/api/test/unit/arvados_model_test.rb |  7 +++++++
 2 files changed, 24 insertions(+), 12 deletions(-)

       via  15cc0bc32eb57c02b566826598c6de2a8587ef9f (commit)
      from  83304d43227dce877cc86d87f8f25463a4fac096 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 15cc0bc32eb57c02b566826598c6de2a8587ef9f
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri May 30 13:26:45 2014 -0400

    2893: Add test cases. Stringify all serialized attrs coming from DB,
    not just Hash. Rename has_any_symbols? to has_symbols?.

diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 2817d69..f63f9fb 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -262,19 +262,20 @@ class ArvadosModel < ActiveRecord::Base
     true
   end
 
-  def self.has_any_symbols? x
+  def self.has_symbols? x
     if x.is_a? Hash
       x.each do |k,v|
-        return true if has_any_symbols?(k) or has_any_symbols?(v)
+        return true if has_symbols?(k) or has_symbols?(v)
       end
+      false
     elsif x.is_a? Array
       x.each do |k|
-        return true if has_any_symbols?(k)
+        return true if has_symbols?(k)
       end
+      false
     else
-      return (x.class == Symbol)
+      (x.class == Symbol)
     end
-    false
   end
 
   def self.recursive_stringify x
@@ -304,7 +305,7 @@ class ArvadosModel < ActiveRecord::Base
       if attr.object_class
         if self.attributes[colname].class != attr.object_class
           self.errors.add colname.to_sym, "must be a #{attr.object_class.to_s}, not a #{self.attributes[colname].class.to_s}"
-        elsif self.class.has_any_symbols? attributes[colname]
+        elsif self.class.has_symbols? attributes[colname]
           self.errors.add colname.to_sym, "must not contain symbols: #{attributes[colname].inspect}"
         end
       end
@@ -312,13 +313,17 @@ class ArvadosModel < ActiveRecord::Base
   end
 
   def convert_serialized_symbols_to_strings
+    # ensure_serialized_attribute_type should prevent symbols from
+    # getting into the database in the first place. If someone managed
+    # to get them into the database (perhaps using an older version)
+    # we'll convert symbols to strings when loading from the
+    # database. (Otherwise, loading and saving an object with existing
+    # symbols in a serialized field will crash.)
     self.class.serialized_attributes.each do |colname, attr|
-      if attr.object_class == Hash
-        if self.class.has_any_symbols? attributes[colname]
-          attributes[colname] = self.class.recursive_stringify attributes[colname]
-          self.send(colname + '=',
-                    self.class.recursive_stringify(attributes[colname]))
-        end
+      if self.class.has_symbols? attributes[colname]
+        attributes[colname] = self.class.recursive_stringify attributes[colname]
+        self.send(colname + '=',
+                  self.class.recursive_stringify(attributes[colname]))
       end
     end
   end
diff --git a/services/api/test/unit/arvados_model_test.rb b/services/api/test/unit/arvados_model_test.rb
index f7db88c..85d07a5 100644
--- a/services/api/test/unit/arvados_model_test.rb
+++ b/services/api/test/unit/arvados_model_test.rb
@@ -32,6 +32,13 @@ class ArvadosModelTest < ActiveSupport::TestCase
   end
 
   [ {:a => 'foo'},
+    {'a' => :foo},
+    {:a => ['foo', 'bar']},
+    {'a' => [:foo, 'bar']},
+    {'a' => ['foo', :bar]},
+    {:a => [:foo, :bar]},
+    {:a => {'foo' => {'bar' => 'baz'}}},
+    {'a' => {:foo => {'bar' => 'baz'}}},
     {'a' => {'foo' => {:bar => 'baz'}}},
     {'a' => {'foo' => {'bar' => :baz}}},
     {'a' => {'foo' => ['bar', :baz]}},

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list