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 simple string as workflow" do
28 set_user_from_auth :active
32 workflow: "this is valid yaml"
35 w = Workflow.create!(wf)
39 test "create workflow with invalid workflow yaml" do
40 set_user_from_auth :active
44 workflow: "k1:\n v1: x\n v2: y"
47 assert_raises(ActiveRecord::RecordInvalid) do
52 test "update workflow with invalid workflow yaml" do
53 set_user_from_auth :active
55 w = Workflow.find_by_uuid(workflows(:workflow_with_workflow_yml).uuid)
56 wf = "k1:\n v1: x\n v2: y"
58 assert_raises(ActiveRecord::RecordInvalid) do
59 w.update_attributes!(workflow: wf)
63 test "update workflow and verify name and description" do
64 set_user_from_auth :active
66 # Workflow name and desc should be set with values from workflow yaml
67 # when it does not already have custom values for these fields
68 w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
69 wf = "name: test name 1\ndescription: test desc 1\nother: some more"
70 w.update_attributes!(workflow: wf)
72 assert_equal "test name 1", w.name
73 assert_equal "test desc 1", w.description
75 # Workflow name and desc should be set with values from workflow yaml
76 # when it does not already have custom values for these fields
77 wf = "name: test name 2\ndescription: test desc 2\nother: some more"
78 w.update_attributes!(workflow: wf)
80 assert_equal "test name 2", w.name
81 assert_equal "test desc 2", w.description
83 # Workflow name and desc should be set with values from workflow yaml
84 # even if it means emptying them out
86 w.update_attributes!(workflow: wf)
88 assert_equal nil, w.name
89 assert_equal nil, w.description
91 # Workflow name and desc set using workflow yaml should be cleared
92 # if workflow yaml is cleared
93 wf = "name: test name 2\ndescription: test desc 2\nother: some more"
94 w.update_attributes!(workflow: wf)
97 w.update_attributes!(workflow: wf)
99 assert_equal nil, w.name
100 assert_equal nil, w.description
102 # Workflow name and desc should be set to provided custom values
103 wf = "name: test name 3\ndescription: test desc 3\nother: some more"
104 w.update_attributes!(name: "remains", description: "remains", workflow: wf)
106 assert_equal "remains", w.name
107 assert_equal "remains", w.description
109 # Workflow name and desc should retain provided custom values
110 # and should not be overwritten by values from yaml
111 wf = "name: test name 4\ndescription: test desc 4\nother: some more"
112 w.update_attributes!(workflow: wf)
114 assert_equal "remains", w.name
115 assert_equal "remains", w.description
117 # Workflow name and desc should retain provided custom values
118 # and not be affected by the clearing of the workflow yaml
120 w.update_attributes!(workflow: wf)
122 assert_equal "remains", w.name
123 assert_equal "remains", w.description