Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/isa_assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
28 changes: 28 additions & 0 deletions test/functional/isa_assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down