-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1363 from sanger/1354-y24-180---bug-pacbio-librar…
…ies-not-updating-their-used_aliquots-when-they-are-edited feat: Update used aliquots data when primary aliquot is updated for a library
- Loading branch information
Showing
5 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/tasks/update_used_aliquots_with_primary_aliquot_tags.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :used_aliquots do | ||
task update_tags: :environment do | ||
libraries = Pacbio::Library.all.reject { |library| library.used_aliquots.first.tag == library.tag } | ||
libraries.each do |library| | ||
library.used_aliquots.each do |used_aliquot| | ||
used_aliquot.update!(tag: library.tag) | ||
end | ||
end | ||
puts "-> #{libraries.count} instances of libraries updated." | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
spec/lib/tasks/update_used_aliquots_with_primary_aliquot_tag.rake_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'rake' | ||
|
||
# only load Rake tasks if they haven't been loaded already | ||
Rails.application.load_tasks if Rake::Task.tasks.empty? | ||
|
||
RSpec.describe 'RakeTasks' do | ||
describe 'used_aliquots:update_tags' do | ||
it 'updates used aliquots with primary aliquot tag' do | ||
libraries = create_list(:pacbio_library, 5) | ||
tag = create(:tag) | ||
libraries.each do |library| | ||
library.used_aliquots.first.update!(tag:) | ||
end | ||
|
||
expect { Rake::Task['used_aliquots:update_tags'].invoke }.to output( | ||
"-> #{libraries.count} instances of libraries updated.\n" | ||
).to_stdout | ||
|
||
libraries.each do |library| | ||
library.reload | ||
expect(library.used_aliquots.first.tag).to eq(library.tag) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters