Skip to content

Commit 751c52f

Browse files
committed
Merge branch 'develop' into y26-106-ug200-sample-sheet-generator
2 parents 2734596 + 0636411 commit 751c52f

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ GEM
247247
ffi (1.17.3-arm64-darwin)
248248
ffi (1.17.3-x86_64-darwin)
249249
ffi (1.17.3-x86_64-linux-gnu)
250-
flipper (1.4.0)
250+
flipper (1.4.1)
251251
concurrent-ruby (< 2)
252252
flipper-active_record (1.4.0)
253253
activerecord (>= 4.2, < 9)

app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ def rows_with_warnings
4040
end
4141
end
4242

43-
def apply_warning_flash(rows)
44-
flash[:warning] = {
45-
'Sample manifest uploaded with warnings!':
46-
rows.flat_map { |row| row.warnings.full_messages }.uniq
47-
}
43+
def apply_warning_flash(rows) # rubocop:disable Metrics/AbcSize
44+
# There are more than 10 messages, truncate the list and add a note about it.
45+
# This is to prevent the flash from becoming too large and causing issues with cookies.
46+
row_messages = rows.flat_map { |row| row.warnings.full_messages }.uniq
47+
if row_messages.size > 10
48+
# IfUnlessModifier doesn't improve readability
49+
row_messages = row_messages.first(10) + ["and #{row_messages.size - 10} more..."]
50+
end
51+
52+
flash[:warning] = { 'Sample manifest uploaded with warnings!': row_messages }
4853

4954
redirect_target = (@uploader.study.present? ? sample_manifests_study_path(@uploader.study) : sample_manifests_path)
5055
redirect_to redirect_target

spec/controllers/sample_manifest_upload_with_tag_sequences_controller_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,47 @@
6868
end
6969
end
7070

71+
context 'when the upload succeeds with more than 10 warnings' do
72+
let(:warning_rows) do
73+
(1..12).map do |i|
74+
double(warnings: double(full_messages: ["Row #{i} warning"]))
75+
end
76+
end
77+
78+
before do
79+
allow(controller).to receive(:upload_manifest) do
80+
controller.instance_variable_set(:@uploader, uploader)
81+
true
82+
end
83+
allow(controller).to receive(:rows_with_warnings).and_return(warning_rows)
84+
post :create, params: { upload: upload_file }
85+
end
86+
87+
it 'sets warning flash message' do
88+
expect(flash[:warning]).to eq(
89+
{
90+
'Sample manifest uploaded with warnings!': [
91+
'Row 1 warning',
92+
'Row 2 warning',
93+
'Row 3 warning',
94+
'Row 4 warning',
95+
'Row 5 warning',
96+
'Row 6 warning',
97+
'Row 7 warning',
98+
'Row 8 warning',
99+
'Row 9 warning',
100+
'Row 10 warning',
101+
'and 2 more...'
102+
]
103+
}
104+
)
105+
end
106+
107+
it 'redirects correctly' do
108+
expect(response).to redirect_to(sample_manifests_path)
109+
end
110+
end
111+
71112
context 'when the upload fails due to invalid data' do
72113
before do
73114
allow(uploader).to receive(:run!).and_raise(AccessionService::AccessionValidationFailed, 'Invalid data')

0 commit comments

Comments
 (0)