diff --git a/app/models/workflow.rb b/app/models/workflow.rb index 6ee0b1cda1..0af04aab04 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -44,6 +44,7 @@ def initialize(*args) acts_as_doi_mintable(proxy: :parent, general_type: 'Workflow') + before_validation :remove_redundant_abstract_cwl_annotation before_save :refresh_internals, if: -> { main_workflow_path_changed? && main_workflow_blob && !main_workflow_blob.empty? } after_save :clear_cached_diagram, if: -> { diagram_path_changed? } after_commit :submit_to_life_monitor, on: [:create, :update], if: :should_submit_to_life_monitor? @@ -97,6 +98,10 @@ def should_submit_to_life_monitor? def sync_test_status parent.update_column(:test_status, Workflow::TEST_STATUS_INV[test_status]) if latest_git_version? end + + def remove_redundant_abstract_cwl_annotation + abstract_cwl_annotation.mark_for_destruction if abstract_cwl_path && abstract_cwl_path == main_workflow_path + end end explicit_versioning(version_column: 'version', sync_ignore_columns: ['doi', 'test_status']) do diff --git a/test/integration/git_workflow_creation_test.rb b/test/integration/git_workflow_creation_test.rb index 4464baa93d..b40e7f5e2b 100644 --- a/test/integration/git_workflow_creation_test.rb +++ b/test/integration/git_workflow_creation_test.rb @@ -394,6 +394,41 @@ class GitWorkflowCreationTest < ActionDispatch::IntegrationTest assert_equal annotation_count + 2, Git::Annotation.count end + test 'cannot set abstract cwl path to same as main workflow path' do + person = FactoryBot.create(:person) + cwl = WorkflowClass.find_by_key('cwl') || FactoryBot.create(:cwl_workflow_class) + login_as(person.user) + + repo = FactoryBot.create(:unlinked_local_repository) + + assert_difference('Workflow.count', 1) do + assert_difference('Git::Version.count', 1) do + # 2 annotations = Main WF path, diagram path + assert_difference('Git::Annotation.count', 2) do + post create_metadata_workflows_path, params: { + workflow: { + workflow_class_id: cwl.id, + title: 'blabla', + project_ids: [person.projects.first.id], + git_version_attributes: { + root_path: '/', + git_repository_id: repo.id, + ref: 'refs/heads/master', + main_workflow_path: 'Concat_two_files.cwl', + diagram_path: 'diagram.png', + abstract_cwl_path: 'Concat_two_files.cwl' + } + } + } + end + end + end + + assert_redirected_to workflow_path(assigns(:workflow)) + assert_equal 'Concat_two_files.cwl', assigns(:workflow).main_workflow_path + assert_nil assigns(:workflow).abstract_cwl_path + end + private def login_as(user)