diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index c9b1c988f..b3c87fbc5 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -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 diff --git a/app/models/labware_creators/multi_stamp_tubes.rb b/app/models/labware_creators/multi_stamp_tubes.rb index 8d499fae7..55e0156b5 100644 --- a/app/models/labware_creators/multi_stamp_tubes.rb +++ b/app/models/labware_creators/multi_stamp_tubes.rb @@ -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) @@ -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], diff --git a/app/models/labware_creators/plate_split_to_tube_racks.rb b/app/models/labware_creators/plate_split_to_tube_racks.rb index b53dc35e0..f10433435 100644 --- a/app/models/labware_creators/plate_split_to_tube_racks.rb +++ b/app/models/labware_creators/plate_split_to_tube_racks.rb @@ -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" @@ -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 diff --git a/app/models/labware_creators/pooled_tubes_by_sample.rb b/app/models/labware_creators/pooled_tubes_by_sample.rb index bb75969fa..b4da80aa4 100644 --- a/app/models/labware_creators/pooled_tubes_by_sample.rb +++ b/app/models/labware_creators/pooled_tubes_by_sample.rb @@ -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 diff --git a/app/models/labware_creators/pooled_tubes_from_whole_tubes.rb b/app/models/labware_creators/pooled_tubes_from_whole_tubes.rb index 7f33dd73b..87e5fd244 100644 --- a/app/models/labware_creators/pooled_tubes_from_whole_tubes.rb +++ b/app/models/labware_creators/pooled_tubes_from_whole_tubes.rb @@ -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 diff --git a/app/sequencescape/sequencescape/api/v2/tube.rb b/app/sequencescape/sequencescape/api/v2/tube.rb index 5c641a014..0d7051d77 100644 --- a/app/sequencescape/sequencescape/api/v2/tube.rb +++ b/app/sequencescape/sequencescape/api/v2/tube.rb @@ -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 diff --git a/spec/features/pooling_multiple_tubes_into_one_tube_spec.rb b/spec/features/pooling_multiple_tubes_into_one_tube_spec.rb index a700de2af..8e755fad2 100644 --- a/spec/features/pooling_multiple_tubes_into_one_tube_spec.rb +++ b/spec/features/pooling_multiple_tubes_into_one_tube_spec.rb @@ -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, @@ -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, @@ -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 diff --git a/spec/models/labware_creators/pooled_tubes_from_whole_tubes_spec.rb b/spec/models/labware_creators/pooled_tubes_from_whole_tubes_spec.rb index b76188fe9..2530a67af 100644 --- a/spec/models/labware_creators/pooled_tubes_from_whole_tubes_spec.rb +++ b/spec/models/labware_creators/pooled_tubes_from_whole_tubes_spec.rb @@ -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