Merge branch 'master' into 13822-nm-delayed-daemon
[arvados.git] / services / api / test / unit / arvados_model_test.rb
index d83f583bf349ccf13f1330a0a8e2881623281333..d07027721f603565d3d6c66838fdd5ad666b95da 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class ArvadosModelTest < ActiveSupport::TestCase
@@ -95,7 +99,7 @@ class ArvadosModelTest < ActiveSupport::TestCase
                         properties: {'foo' => 'bar'}.with_indifferent_access)
     raw = ActiveRecord::Base.connection.
       select_value("select properties from links where uuid='#{link.uuid}'")
-    assert_equal '{"foo":"bar"}', raw
+    assert_equal '{"foo": "bar"}', raw
   end
 
   test "store long string" do
@@ -135,6 +139,7 @@ class ArvadosModelTest < ActiveSupport::TestCase
   test "search index exists on models that go into projects" do
     all_tables =  ActiveRecord::Base.connection.tables
     all_tables.delete 'schema_migrations'
+    all_tables.delete 'permission_refresh_lock'
 
     all_tables.each do |table|
       table_class = table.classify.constantize
@@ -253,4 +258,24 @@ class ArvadosModelTest < ActiveSupport::TestCase
 
     assert_equal true, (updated_at_2 > updated_at_1), "Expected updated time 2 to be newer than 1"
   end
+
+  test 'jsonb column' do
+    set_user_from_auth :active
+
+    c = Collection.create!(properties: {})
+    assert_equal({}, c.properties)
+
+    c.update_attributes(properties: {'foo' => 'foo'})
+    c.reload
+    assert_equal({'foo' => 'foo'}, c.properties)
+
+    c.update_attributes(properties: nil)
+    c.reload
+    assert_equal({}, c.properties)
+
+    c.update_attributes(properties: {foo: 'bar'})
+    assert_equal({'foo' => 'bar'}, c.properties)
+    c.reload
+    assert_equal({'foo' => 'bar'}, c.properties)
+  end
 end