3 class WorkflowTest < ActiveSupport::TestCase
4 test "create workflow with no workflow yaml" do
5 set_user_from_auth :active
11 w = Workflow.create!(wf)
15 test "create workflow with valid workflow yaml" do
16 set_user_from_auth :active
20 workflow: "k1:\n v1: x\n v2: y"
23 w = Workflow.create!(wf)
27 test "create workflow with invalid workflow yaml" do
28 set_user_from_auth :active
32 workflow: "k1:\n v1: x\n v2: y"
35 assert_raises(ActiveRecord::RecordInvalid) do
40 test "update workflow with invalid workflow yaml" do
41 set_user_from_auth :active
43 w = Workflow.find_by_uuid(workflows(:workflow_with_workflow_yml).uuid)
44 wf = "k1:\n v1: x\n v2: y"
46 assert_raises(ActiveRecord::RecordInvalid) do
47 w.update_attributes!(workflow: wf)
51 test "update workflow and verify name and description" do
52 set_user_from_auth :active
54 # Workflow name and desc should be set with values from workflow yaml
55 # when it does not already have custom values for these fields
56 w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
57 wf = "name: test name 1\ndescription: test desc 1\nother: some more"
58 w.update_attributes!(workflow: wf)
59 assert_equal "test name 1", w.name
60 assert_equal "test desc 1", w.description
62 # Workflow name and desc should be set with values from workflow yaml
63 # when it does not already have custom values for these fields
64 wf = "name: test name 2\ndescription: test desc 2\nother: some more"
65 w.update_attributes!(workflow: wf)
66 assert_equal "test name 2", w.name
67 assert_equal "test desc 2", w.description
69 # Workflow name and desc should be set with values from workflow yaml
70 # even if it means emptying them out
72 w.update_attributes!(workflow: wf)
73 assert_equal nil, w.name
74 assert_equal nil, w.description
76 # Workflow name and desc should be set to provided custom values
77 wf = "name: test name 3\ndescription: test desc 3\nother: some more"
78 w.update_attributes!(name: "remains", description: "remains", workflow: wf)
79 assert_equal "remains", w.name
80 assert_equal "remains", w.description
82 # Workflow name and desc should retain provided custom values
83 # and should not be overwritten by values from yaml
84 wf = "name: test name 4\ndescription: test desc 4\nother: some more"
85 w.update_attributes!(workflow: wf)
86 assert_equal "remains", w.name
87 assert_equal "remains", w.description