From 190cd762e70ce95cc06ce0bca7efe379b82edc1e Mon Sep 17 00:00:00 2001 From: Kevin De Pelseneer Date: Tue, 22 Oct 2024 12:05:43 +0200 Subject: [PATCH] Put job in with_current_user block Effect of adding `samples.all?(&:can_edit?)` clause ini editing constraints. --- .../jobs/update_sample_metadata_job_test.rb | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/unit/jobs/update_sample_metadata_job_test.rb b/test/unit/jobs/update_sample_metadata_job_test.rb index e978fd2e22..d465b04e4f 100644 --- a/test/unit/jobs/update_sample_metadata_job_test.rb +++ b/test/unit/jobs/update_sample_metadata_job_test.rb @@ -23,16 +23,17 @@ def teardown end test 'Check sample metadata after updating the attribute title' do - assert_equal @sample_type.sample_attributes.first.title, 'the_title' - @sample_type.sample_attributes.first.update!(title: 'new title') - attribute_change_maps = [{id: @sample_type.sample_attributes.first.id, old_title: 'the_title', new_title: 'new title' }] - assert_equal @sample_type.sample_attributes.first.title, 'new title' - refute_equal @sample_type.sample_attributes.first.title, 'the_title' - UpdateSampleMetadataJob.new.perform(@sample_type, attribute_change_maps, @person.user) - @sample_type.samples.each do |sample| - json_metadata = JSON.parse sample.json_metadata - assert json_metadata.keys.include?('new title') - refute json_metadata.keys.include?('the_title') + User.with_current_user(@person.user) do + @sample_type.sample_attributes.first.update!(title: 'new title') + attribute_change_maps = [{id: @sample_type.sample_attributes.first.id, old_title: 'the_title', new_title: 'new title' }] + assert_equal @sample_type.sample_attributes.first.title, 'new title' + refute_equal @sample_type.sample_attributes.first.title, 'the_title' + UpdateSampleMetadataJob.new.perform(@sample_type, attribute_change_maps, @person.user) + @sample_type.samples.each do |sample| + json_metadata = JSON.parse sample.json_metadata + assert json_metadata.keys.include?('new title') + refute json_metadata.keys.include?('the_title') + end end end end