3 class WorkflowTest < ActiveSupport::TestCase
4 test "create workflow with no definition yaml" do
5 set_user_from_auth :active
11 w = Workflow.create!(wf)
15 test "create workflow with valid definition yaml" do
16 set_user_from_auth :active
20 definition: "k1:\n v1: x\n v2: y"
23 w = Workflow.create!(wf)
27 test "create workflow with simple string as definition" do
28 set_user_from_auth :active
32 definition: "this is valid yaml"
35 w = Workflow.create!(wf)
39 test "create workflow with invalid definition yaml" do
40 set_user_from_auth :active
44 definition: "k1:\n v1: x\n v2: y"
47 assert_raises(ActiveRecord::RecordInvalid) do
52 test "update workflow with invalid definition yaml" do
53 set_user_from_auth :active
55 w = Workflow.find_by_uuid(workflows(:workflow_with_definition_yml).uuid)
56 definition = "k1:\n v1: x\n v2: y"
58 assert_raises(ActiveRecord::RecordInvalid) do
59 w.update_attributes!(definition: definition)
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 definition 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 definition = "name: test name 1\ndescription: test desc 1\nother: some more"
70 w.update_attributes!(definition: definition)
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 definition yaml
76 # when it does not already have custom values for these fields
77 definition = "name: test name 2\ndescription: test desc 2\nother: some more"
78 w.update_attributes!(definition: definition)
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 definition yaml
84 # even if it means emptying them out
85 definition = "more: etc"
86 w.update_attributes!(definition: definition)
88 assert_equal nil, w.name
89 assert_equal nil, w.description
91 # Workflow name and desc set using definition yaml should be cleared
92 # if definition yaml is cleared
93 definition = "name: test name 2\ndescription: test desc 2\nother: some more"
94 w.update_attributes!(definition: definition)
97 w.update_attributes!(definition: definition)
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 definition = "name: test name 3\ndescription: test desc 3\nother: some more"
104 w.update_attributes!(name: "remains", description: "remains", definition: definition)
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 definition = "name: test name 4\ndescription: test desc 4\nother: some more"
112 w.update_attributes!(definition: definition)
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 definition yaml
120 w.update_attributes!(definition: definition)
122 assert_equal "remains", w.name
123 assert_equal "remains", w.description