9898: test updates
[arvados.git] / services / api / test / unit / workflow_test.rb
index 7bcf2f6b541db22c59204af7c1da0d3ed343ef0c..ac8df472bf9a7a1a5a1677b69f978a08fa3de0d6 100644 (file)
@@ -24,6 +24,18 @@ class WorkflowTest < ActiveSupport::TestCase
     assert_not_nil w.uuid
   end
 
+  test "create workflow with simple string as workflow" do
+    set_user_from_auth :active
+
+    wf = {
+      name: "test name",
+      workflow: "this is valid yaml"
+    }
+
+    w = Workflow.create!(wf)
+    assert_not_nil w.uuid
+  end
+
   test "create workflow with invalid workflow yaml" do
     set_user_from_auth :active
 
@@ -56,6 +68,7 @@ class WorkflowTest < ActiveSupport::TestCase
     w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
     wf = "name: test name 1\ndescription: test desc 1\nother: some more"
     w.update_attributes!(workflow: wf)
+    w.reload
     assert_equal "test name 1", w.name
     assert_equal "test desc 1", w.description
 
@@ -63,6 +76,7 @@ class WorkflowTest < ActiveSupport::TestCase
     # when it does not already have custom values for these fields
     wf = "name: test name 2\ndescription: test desc 2\nother: some more"
     w.update_attributes!(workflow: wf)
+    w.reload
     assert_equal "test name 2", w.name
     assert_equal "test desc 2", w.description
 
@@ -70,12 +84,25 @@ class WorkflowTest < ActiveSupport::TestCase
     # even if it means emptying them out
     wf = "more: etc"
     w.update_attributes!(workflow: wf)
+    w.reload
+    assert_equal nil, w.name
+    assert_equal nil, w.description
+
+    # Workflow name and desc set using workflow yaml should be cleared
+    # if workflow yaml is cleared
+    wf = "name: test name 2\ndescription: test desc 2\nother: some more"
+    w.update_attributes!(workflow: wf)
+    w.reload
+    wf = nil
+    w.update_attributes!(workflow: wf)
+    w.reload
     assert_equal nil, w.name
     assert_equal nil, w.description
 
     # Workflow name and desc should be set to provided custom values
     wf = "name: test name 3\ndescription: test desc 3\nother: some more"
     w.update_attributes!(name: "remains", description: "remains", workflow: wf)
+    w.reload
     assert_equal "remains", w.name
     assert_equal "remains", w.description
 
@@ -83,6 +110,15 @@ class WorkflowTest < ActiveSupport::TestCase
     # and should not be overwritten by values from yaml
     wf = "name: test name 4\ndescription: test desc 4\nother: some more"
     w.update_attributes!(workflow: wf)
+    w.reload
+    assert_equal "remains", w.name
+    assert_equal "remains", w.description
+
+    # Workflow name and desc should retain provided custom values
+    # and not be affected by the clearing of the workflow yaml
+    wf = nil
+    w.update_attributes!(workflow: wf)
+    w.reload
     assert_equal "remains", w.name
     assert_equal "remains", w.description
   end