Skip to content

lazy worksheet initialization is harmful? #9

Description

@timon

While writing tests for worksheet protection timon/spreadsheet@c2351bd3e2 I've found strange issue:

The following code fails:

  def test_read_protected
      path = File.join @data, "test_merged_and_protected.xls"
      book = Spreadsheet.open path
      sheet = book.worksheet(0)
      assert(sheet.protected?, "Expected sheet to be protected")
      assert_equal(Spreadsheet::Excel::Password.password_hash('testing'), sheet.password_hash)
    end
# => Expected sheet to be protected.

The following code runs fine due to side effects:

   def test_read_protected
      path = File.join @data, "test_merged_and_protected.xls"
      book = Spreadsheet.open path
      sheet = book.worksheet(0)
      sheet.inspect # Hello, magic! 
      assert(sheet.protected?, "Expected sheet to be protected")
      assert_equal(Spreadsheet::Excel::Password.password_hash('testing'), sheet.password_hash)
    end

I'm not sure what's correct way to handle this issue — either load all worksheets greedily after workbook is read, or guard all methods with ensure_rows_read — both approaches seems to have their positive and negative sides

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions