Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Roo::Base#each_with_pagename degraded at #576 #584

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Changed/Added
- Prevent warnings on Ruby 3.1 if finalizer is called twice [586](https://github.com/roo-rb/roo/pull/586)
- Fix Roo::Base#each_with_pagename degraded at [576](https://github.com/roo-rb/roo/pull/576) [583](https://github.com/roo-rb/roo/pull/583)

## [2.10.0] 2023-02-07

Expand Down
8 changes: 4 additions & 4 deletions lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ def sheet(index, name = false)

# iterate through all worksheets of a document
def each_with_pagename
Enumerator.new do |yielder|
sheets.each do |s|
yielder << sheet(s, true)
end
return to_enum(:each_with_pagename) { sheets.size } unless block_given?

sheets.each do |s|
yield sheet(s, true)
end
end

Expand Down
20 changes: 16 additions & 4 deletions spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,22 @@ def sheets
end

describe '#each_with_pagename' do
it 'should return an enumerator with all the rows' do
each_with_pagename = spreadsheet.each_with_pagename
expect(each_with_pagename).to be_a(Enumerator)
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
context 'when block given' do
it 'iterate with sheet and sheet_name' do
sheet_names = []
spreadsheet.each_with_pagename do |sheet_name, sheet|
sheet_names << sheet_name
end
expect(sheet_names).to eq ['my_sheet', 'blank sheet']
end
end

context 'when called without block' do
it 'should return an enumerator with all the rows' do
each_with_pagename = spreadsheet.each_with_pagename
expect(each_with_pagename).to be_a(Enumerator)
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
end
end
end

Expand Down
Loading