3153: directly invoke setup method during auto-setup
[arvados.git] / services / api / test / unit / arvados_model_test.rb
index e9e872f04eebd4ab61c0419ff0c22b7056ea450e..85d07a5746afce9e85c4287ed2d487c5d465663f 100644 (file)
@@ -31,4 +31,48 @@ class ArvadosModelTest < ActiveSupport::TestCase
     assert a.uuid.length==27, "Auto assigned uuid length is wrong."
   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]}},
+    {'a' => {['foo', :foo] => ['bar', 'baz']}},
+  ].each do |x|
+    test "refuse symbol keys in serialized attribute: #{x.inspect}" do
+      set_user_from_auth :admin_trustedclient
+      assert_nothing_raised do
+        Link.create!(link_class: 'test',
+                     properties: {})
+      end
+      assert_raises ActiveRecord::RecordInvalid do
+        Link.create!(link_class: 'test',
+                     properties: x)
+      end
+    end
+  end
+
+  test "Stringify symbols coming from serialized attribute in database" do
+    set_user_from_auth :admin_trustedclient
+    fixed = Link.find_by_uuid(links(:has_symbol_keys_in_database_somehow).uuid)
+    assert_equal(["baz", "foo"], fixed.properties.keys.sort,
+                 "Hash symbol keys from DB did not get stringified.")
+    assert_equal(['waz', 'waz', 'waz', 1, nil, false, true],
+                 fixed.properties['baz'],
+                 "Array symbol values from DB did not get stringified.")
+    assert_equal true, fixed.save, "Failed to save fixed model back to db."
+  end
+
+  test "No HashWithIndifferentAccess in database" do
+    set_user_from_auth :admin_trustedclient
+    assert_raises ActiveRecord::RecordInvalid do
+      Link.create!(link_class: 'test',
+                   properties: {'foo' => 'bar'}.with_indifferent_access)
+    end
+  end
 end