Skip to content

Commit

Permalink
Change on the signature for the method Tube.find_all() as the previous
Browse files Browse the repository at this point in the history
definition was not valid anymore.
  • Loading branch information
emrojo committed Nov 8, 2023
1 parent e60f8e2 commit 3f42218
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def set_filename

def ancestor_tube_details(ancestor_results)
ancestor_results.each_with_object({}) do |ancestor_result, tube_list|
tube = Sequencescape::Api::V2::Tube.find_by({ uuid: ancestor_result.uuid })
tube = Sequencescape::Api::V2::Tube.find_by(uuid: ancestor_result.uuid)
tube_sample_uuid = tube.aliquots.first.sample.uuid
tube_list[tube_sample_uuid] = tube if tube_sample_uuid.present?
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/labware_creators/multi_stamp_tubes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parent_uuids
end

def parent_tubes
Sequencescape::Api::V2::Tube.find_all({ uuid: parent_uuids }, includes: 'receptacle,aliquots,aliquots.study')
Sequencescape::Api::V2::Tube.find_all(uuid: parent_uuids, includes: 'receptacle,aliquots,aliquots.study')
end

def transfer_material_from_parent!(child_plate)
Expand All @@ -101,7 +101,7 @@ def source_tube_outer_request_uuid(tube)
end

def request_hash(transfer, child_plate)
tube = Sequencescape::Api::V2::Tube.find_by({ uuid: transfer[:source_tube] })
tube = Sequencescape::Api::V2::Tube.find_by(uuid: transfer[:source_tube])

{
'source_asset' => transfer[:source_asset],
Expand Down
4 changes: 2 additions & 2 deletions app/models/labware_creators/plate_split_to_tube_racks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def tube_barcodes_are_unique?
def check_tube_rack_scan_file(tube_rack_file, msg_prefix)
tube_rack_file.position_details.each do |tube_posn, tube_details|
foreign_barcode = tube_details['tube_barcode']
tube_in_db = Sequencescape::Api::V2::Tube.find_by({ barcode: foreign_barcode })
tube_in_db = Sequencescape::Api::V2::Tube.find_by(barcode: foreign_barcode)
next if tube_in_db.blank?

msg = "#{msg_prefix} tube barcode #{foreign_barcode} (at rack position #{tube_posn}) already exists in the LIMS"
Expand Down Expand Up @@ -224,7 +224,7 @@ def locate_ancestor_tubes
return {} if ancestor_results.blank?

ancestor_results.each_with_object({}) do |ancestor_result, tube_list|
tube = Sequencescape::Api::V2::Tube.find_by({ uuid: ancestor_result.uuid })
tube = Sequencescape::Api::V2::Tube.find_by(uuid: ancestor_result.uuid)
tube_sample_uuid = tube.aliquots.first.sample.uuid
tube_list[tube_sample_uuid] = tube if tube_sample_uuid.present?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/labware_creators/pooled_tubes_by_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def locate_ancestor_tubes
return {} if ancestor_results.blank?

ancestor_results.each_with_object({}) do |ancestor_result, tube_list|
tube = Sequencescape::Api::V2::Tube.find_by({ uuid: ancestor_result.uuid })
tube = Sequencescape::Api::V2::Tube.find_by(uuid: ancestor_result.uuid)
tube_sample_uuid = tube.aliquots.first.sample.uuid
tube_list[tube_sample_uuid] = tube if tube_sample_uuid.present?
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/labware_creators/pooled_tubes_from_whole_tubes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ def available_tubes
@search_options = OngoingTube.new(purpose_names: [parent.purpose.name], include_used: false)
@search_results =
Sequencescape::Api::V2::Tube.find_all(
@search_options.v2_search_parameters,
includes: 'purpose',
paginate: @search_options.v2_pagination
**@search_options.v2_search_parameters.merge({ includes: 'purpose', paginate: @search_options.v2_pagination })
)
end

def parents
@parents ||= Sequencescape::Api::V2::Tube.find_all({ barcode: barcodes }, includes: [])
@parents ||= Sequencescape::Api::V2::Tube.find_all(barcode: barcodes, includes: [])
end

def parents_suitable
Expand Down
9 changes: 7 additions & 2 deletions app/sequencescape/sequencescape/api/v2/tube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ class Sequencescape::Api::V2::Tube < Sequencescape::Api::V2::Base
property :created_at, type: :time
property :updated_at, type: :time

def self.find_by(options, includes: DEFAULT_INCLUDES)
def self.find_by(params)
options = params.dup
includes = options.delete(:includes) || DEFAULT_INCLUDES
Sequencescape::Api::V2::Tube.includes(*includes).find(**options).first
end

def self.find_all(options, includes: DEFAULT_INCLUDES, paginate: {})
def self.find_all(params)
options = params.dup
includes = options.delete(:includes) || DEFAULT_INCLUDES
paginate = options.delete(:paginate) || {}
Sequencescape::Api::V2::Tube.includes(*includes).where(**options).paginate(paginate).all
end

Expand Down
24 changes: 22 additions & 2 deletions spec/features/pooling_multiple_tubes_into_one_tube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@
stub_api_post('sub-uuid', 'submit')
end

before do
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(
include_used: false,
purpose_name: ['example-purpose'],
includes: 'purpose',
paginate: {
size: 30,
number: 1
}
)
.and_return([example_v2_tube, example_v2_tube2])

# Parent lookup
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(barcode: [tube_barcode_1, tube_barcode_2], includes: [])
.and_return([example_v2_tube, example_v2_tube2])
end

background do
create :tube_config, name: parent_purpose_name, uuid: 'example-purpose-uuid'
create :pooled_tube_from_tubes_purpose_config,
Expand All @@ -165,7 +184,8 @@
# Available tubes search
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with(
{ include_used: false, purpose_name: ['example-purpose'] },
include_used: false,
purpose_name: ['example-purpose'],
includes: 'purpose',
paginate: {
size: 30,
Expand All @@ -176,7 +196,7 @@

# Parent lookup
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with({ barcode: [tube_barcode_1, tube_barcode_2] }, includes: [])
.with(barcode: [tube_barcode_1, tube_barcode_2], includes: [])
.and_return([example_v2_tube, example_v2_tube2])

# Old API still used when loading parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

before do
allow(Sequencescape::Api::V2::Tube).to receive(:find_all)
.with({ barcode: barcodes }, includes: [])
.with(barcode: barcodes, includes: [])
.and_return([parent, parent2])

tube_creation_request
Expand Down

0 comments on commit 3f42218

Please sign in to comment.