Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 2ff360a

Browse files
committed
Fix import problem when using only one barcode
1 parent 0a83dbb commit 2ff360a

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

lib/importers/concerns/changes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ module Concerns
55
module Changes
66

77
def refresh_assets(assets, opts={})
8+
assets = [assets].flatten
89
FactChanges.new.tap do |updates|
910
if assets.length > 0
1011
remote_assets = SequencescapeClient::find_by_uuid(assets.map(&:uuid))
1112
remote_assets = [] if remote_assets.nil?
13+
remote_assets = [remote_assets].flatten
1214
assets.zip(remote_assets).each do |asset, remote_asset|
1315
annotator = Importers::Concerns::Annotator.new(asset, remote_asset)
1416
annotator.validate!
@@ -22,10 +24,12 @@ def refresh_assets(assets, opts={})
2224
end
2325

2426
def import_barcodes(barcodes)
27+
barcodes = [barcodes].flatten
2528
FactChanges.new.tap do |updates|
2629
if barcodes.length > 0
2730
remote_assets = SequencescapeClient::get_remote_asset(barcodes)
2831
remote_assets = [] if remote_assets.nil?
32+
remote_assets = [remote_assets].flatten
2933
barcodes.zip(remote_assets).each do |barcode, remote_asset|
3034
if remote_asset
3135
# Needed in order to identify the imported elements

spec/lib/importers/concerns/changes_spec.rb

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,47 @@
1111
let(:assets) { [ create(:plate), create(:tube), create(:plate), create(:well)]}
1212
let(:remote_assets) {[build_remote_plate, build_remote_tube, build_remote_plate, build_remote_well('B1')]}
1313

14-
before do
15-
assets.zip(remote_assets) do |a, remote|
16-
allow(remote).to receive(:uuid).and_return(a.uuid)
14+
context 'when refreshing a list of assets' do
15+
before do
16+
assets.zip(remote_assets) do |a, remote|
17+
allow(remote).to receive(:uuid).and_return(a.uuid)
18+
end
19+
allow(SequencescapeClient).to receive(:find_by_uuid).with(assets.map(&:uuid)).and_return(remote_assets)
20+
end
21+
22+
it 'refreshes the contents of the assets' do
23+
updates = instance.refresh_assets(assets)
24+
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
25+
expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(*uuids)
1726
end
18-
allow(SequencescapeClient).to receive(:find_by_uuid).with(assets.map(&:uuid)).and_return(remote_assets)
19-
end
2027

21-
it 'refreshes the contents of the assets' do
22-
updates = instance.refresh_assets(assets)
23-
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
24-
expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(*uuids)
28+
context 'when receiving an empty list' do
29+
it 'does nothing' do
30+
updates = instance.refresh_assets([])
31+
expect(updates.to_h).to eq({})
32+
end
33+
end
2534
end
2635

27-
context 'when receiving an empty list' do
28-
it 'does nothing' do
29-
updates = instance.refresh_assets([])
30-
expect(updates.to_h).to eq({})
36+
context 'when refreshing a single asset' do
37+
before do
38+
assets.zip(remote_assets) do |a, remote|
39+
allow(remote).to receive(:uuid).and_return(a.uuid)
40+
end
41+
allow(SequencescapeClient).to receive(:find_by_uuid).with([assets.map(&:uuid).first]).and_return(remote_assets.first)
3142
end
43+
44+
it 'refreshes the contents of the asset' do
45+
updates = instance.refresh_assets([assets.first])
46+
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
47+
48+
# It includes the asset
49+
expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(uuids.first)
50+
51+
# It does not refreshes other remote assets not passed as argument
52+
expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).not_to include(uuids.last)
53+
end
54+
3255
end
3356
end
3457

@@ -51,22 +74,35 @@
5174
remote_assets.map{|a| a.labware_barcode['human_barcode']}
5275
}
5376

54-
before do
55-
allow(SequencescapeClient).to receive(:get_remote_asset).with(barcodes).and_return(remote_assets)
56-
end
77+
context 'when scanning a list of barcodes' do
78+
before do
79+
allow(SequencescapeClient).to receive(:get_remote_asset).with(barcodes).and_return(remote_assets)
80+
end
5781

58-
it 'imports the assets' do
59-
updates = instance.import_barcodes(barcodes)
60-
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
61-
expect(updates.to_h[:create_assets]).to include(*uuids)
62-
end
82+
it 'imports the assets' do
83+
updates = instance.import_barcodes(barcodes)
84+
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
85+
expect(updates.to_h[:create_assets]).to include(*uuids)
86+
end
6387

64-
context 'when receiving an empty list' do
65-
it 'does nothing' do
66-
updates = instance.import_barcodes([])
67-
expect(updates.to_h).to eq({})
88+
context 'when receiving an empty list' do
89+
it 'does nothing' do
90+
updates = instance.import_barcodes([])
91+
expect(updates.to_h).to eq({})
92+
end
6893
end
6994
end
7095

96+
context 'when scanning a single barcode' do
97+
before do
98+
allow(SequencescapeClient).to receive(:get_remote_asset).with([barcodes.first]).and_return(remote_assets.first)
99+
end
100+
101+
it 'imports the asset' do
102+
updates = instance.import_barcodes([barcodes.first])
103+
expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil
104+
expect(updates.to_h[:create_assets]).to eq([uuids.first])
105+
end
106+
end
71107
end
72108
end

0 commit comments

Comments
 (0)