Skip to content

Commit

Permalink
Fix Roo::Base#each_with_pagename degraded at #576
Browse files Browse the repository at this point in the history
  • Loading branch information
kakubin committed Sep 12, 2023
1 parent 00850f1 commit 06eff9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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

0 comments on commit 06eff9c

Please sign in to comment.