-
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 #1365 from sanger/y24-096-add-uuid-to-aliquot
refactor: add uuid field to aliquot
- Loading branch information
Showing
8 changed files
with
77 additions
and
8 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
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
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :aliquots do | ||
# A rake task to be run to add UUIDs to all aliquots that do not have one | ||
desc 'Update aliquots with UUID' | ||
|
||
task add_missing_uuids: :environment do | ||
puts '-> Updating aliquots with UUID' | ||
|
||
ActiveRecord::Base.transaction do | ||
# If an aliquot does not have a UUID set it | ||
Aliquot.where(uuid: nil).find_each do |aliquot| | ||
aliquot.update!(uuid: SecureRandom.uuid) | ||
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
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,45 @@ | ||
# 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 | ||
# Create a default SMRTLink version to be used by factories | ||
before do | ||
Pacbio::SmrtLinkVersion.find_by(name: 'v13_sequel_iie') || create(:pacbio_smrt_link_version, name: 'v13_sequel_iie', default: true) | ||
end | ||
|
||
describe 'aliquots:add_missing_uuids' do | ||
define_negated_matcher :not_change, :change | ||
|
||
it 'assigns a random UUID to all aliquots that currently lack one.' do | ||
aliquots_with_empty_uuid = create_list(:aliquot, 5, used_by: create(:pacbio_pool), uuid: nil) | ||
aliquots_with_uuid = create_list(:aliquot, 5, used_by: create(:pacbio_pool)) | ||
|
||
# Get uuids to check they are not affected | ||
uuids = aliquots_with_uuid.map(&:uuid) | ||
|
||
# We shouldnt change the amount of aliquots | ||
expect { Rake::Task['aliquots:add_missing_uuids'].invoke }.to not_change(Aliquot, :count).and output( | ||
<<~HEREDOC | ||
-> Updating aliquots with UUID | ||
HEREDOC | ||
).to_stdout | ||
|
||
# Aliquots without uuids should have a uuid set | ||
aliquots_with_empty_uuid.each do |aliquot| | ||
aliquot.reload | ||
expect(aliquot.uuid).not_to be_nil | ||
end | ||
|
||
# Other aliquots should not be affected | ||
aliquots_with_uuid.each do |aliquot| | ||
aliquot.reload | ||
expect(uuids).to include aliquot.uuid | ||
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