diff --git a/app/controllers/isa_assays_controller.rb b/app/controllers/isa_assays_controller.rb index 1c4b92d96d..a53c751b06 100644 --- a/app/controllers/isa_assays_controller.rb +++ b/app/controllers/isa_assays_controller.rb @@ -9,7 +9,7 @@ class ISAAssaysController < ApplicationController after_action :fix_assay_linkage_for_new_assays, only: :create # Update sample metadata when updating an assay - before_action :old_attributes, only: %i[update] + before_action :old_attributes, only: :update after_action :update_sample_json_metadata, only: :update def new @@ -222,12 +222,16 @@ def set_up_instance_variable end def old_attributes + return if @isa_assay.assay.is_assay_stream? + @old_attributes = @isa_assay.sample_type.sample_attributes.map do |attr| { id: attr.id, title: attr.title } end end def update_sample_json_metadata + return if @isa_assay.assay.is_assay_stream? + attribute_changes = @isa_assay.sample_type.sample_attributes.map do |attr| old_attr = @old_attributes.detect { |oa| oa[:id] == attr.id } next if old_attr.nil? diff --git a/test/functional/isa_assays_controller_test.rb b/test/functional/isa_assays_controller_test.rb index a633c676e8..9dec2be2e4 100644 --- a/test/functional/isa_assays_controller_test.rb +++ b/test/functional/isa_assays_controller_test.rb @@ -826,6 +826,34 @@ def setup end + test 'Should not run sample metadata updating callbacks and tasks when updating assay streams' do + person = FactoryBot.create(:person) + login_as(person) + project = person.projects.first + + investigation = FactoryBot.create(:investigation, projects: [project], contributor: person) + study = FactoryBot.create(:study, contributor: person, investigation: investigation) + assay_stream = FactoryBot.create(:assay_stream, contributor: person, study: study, title: 'my asay stream', description: 'Original assay stream') + + assert assay_stream.can_edit? + + parameters = { + assay: { + title: 'my assay stream', + description: 'Updated assay stream' + } + } + + assert_no_enqueued_jobs(only: UpdateSampleMetadataJob) do + patch :update, params: { id: assay_stream.id, isa_assay: parameters } + end + + assert_response :redirect + assay_stream.reload + assert_equal assay_stream.title, 'my assay stream' + assert_equal assay_stream.description, 'Updated assay stream' + end + private def create_material_assay_sample_type_attributes(project, linked_sample_type_id='self', parent_template_id=nil, counter=1)