diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /gems/csv_builder | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'gems/csv_builder')
-rw-r--r-- | gems/csv_builder/lib/csv_builder/gzip.rb | 8 | ||||
-rw-r--r-- | gems/csv_builder/spec/csv_builder/gzip_spec.rb | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/gems/csv_builder/lib/csv_builder/gzip.rb b/gems/csv_builder/lib/csv_builder/gzip.rb index 60875006a35..f97c066705a 100644 --- a/gems/csv_builder/lib/csv_builder/gzip.rb +++ b/gems/csv_builder/lib/csv_builder/gzip.rb @@ -2,12 +2,14 @@ module CsvBuilder class Gzip < CsvBuilder::Builder - # Writes the CSV file compressed and yields the written tempfile. + # Writes the CSV file compressed and yields the written tempfile and rows written. + # # # Example: - # > CsvBuilder::Gzip.new(Issue, { title: -> (row) { row.title.upcase }, id: :id }).render do |tempfile| + # > CsvBuilder::Gzip.new(Issue, { title: -> (row) { row.title.upcase }, id: :id }).render do |tempfile, rows| # > puts tempfile.path # > puts `zcat #{tempfile.path}` + # > puts rows # > end def render Tempfile.open(['csv_builder_gzip', '.csv.gz']) do |tempfile| @@ -16,7 +18,7 @@ module CsvBuilder write_csv csv, until_condition: -> {} # truncation must be handled outside of the CsvBuilder csv.close - yield tempfile + yield tempfile, @rows_written end end end diff --git a/gems/csv_builder/spec/csv_builder/gzip_spec.rb b/gems/csv_builder/spec/csv_builder/gzip_spec.rb index 9d24d351247..22462d8dd0a 100644 --- a/gems/csv_builder/spec/csv_builder/gzip_spec.rb +++ b/gems/csv_builder/spec/csv_builder/gzip_spec.rb @@ -26,6 +26,13 @@ RSpec.describe CsvBuilder::Gzip do ]) end + it 'yields the number of written rows as the second argument' do + row_count = 0 + builder.render { |_, rows| row_count = rows } + + expect(row_count).to eq(2) + end + it 'requires a block' do expect { builder.render }.to raise_error(LocalJumpError) end |