Permalink
Browse files

spreadsheet-0.6.8.gem released

  • Loading branch information...
2 parents 9d486bd + e318958 commit 3748121dcb2f4873499d1c3bcac4906af7424e92 @zdavatz committed Jan 20, 2012
Showing with 53 additions and 32 deletions.
  1. +2 −0 .gitignore
  2. +8 −4 lib/spreadsheet/excel/writer/worksheet.rb
  3. +43 −28 test/excel/writer/worksheet.rb
View
2 .gitignore
@@ -0,0 +1,2 @@
+tags
+*.swp
View
12 lib/spreadsheet/excel/writer/worksheet.rb
@@ -756,14 +756,18 @@ def write_row row
else
height * TWIPS
end
- # TODO: Row spacing
- data = [
+
+ attrs = [
row.idx,
row.first_used,
row.first_unused,
height,
- opts,
- ].pack binfmt(:row)
+ opts]
+
+ return if attrs.any?(&:nil?)
+
+ # TODO: Row spacing
+ data = attrs.pack binfmt(:row)
write_op opcode(:row), data
end
def write_rowblock block
View
71 test/excel/writer/worksheet.rb
@@ -7,34 +7,49 @@
module Spreadsheet
module Excel
module Writer
-class TestWorksheet < Test::Unit::TestCase
- def test_need_number
- sheet = Worksheet.new nil, nil
- assert_equal false, sheet.need_number?(10)
- assert_equal false, sheet.need_number?(114.55)
- assert_equal false, sheet.need_number?(0.1)
- assert_equal false, sheet.need_number?(0.01)
- assert_equal false, sheet.need_number?(0 / 0.0) # NaN
- assert_equal true, sheet.need_number?(0.001)
- assert_equal true, sheet.need_number?(10000000.0)
- end
- def test_write_merged_cells
- # top/bottom/left/right cell of test range 1/2
- r1t, r1b, r1l, r1r = 0, 0, 0, 1
- r2t, r2b, r2l, r2r = 1, 2, 0, 0
- book = Spreadsheet::Workbook.new
- sheet = book.create_worksheet
- sheet.merge_cells(r1t, r1l, r1b, r1r)
- sheet.merge_cells(r2t, r2l, r2b, r2r)
- assert_equal [[r1t, r1b, r1l, r1r], [r2t, r2b, r2l, r2r]], sheet.merged_cells
- io = StringIO.new
- book.write(io)
- book2 = Spreadsheet.open(io)
- sheet2 = book2.worksheet(0)
- sheet2[0,0] # trigger read_worksheet
- assert_equal [[r1t, r1b, r1l, r1r], [r2t, r2b, r2l, r2r]], sheet2.merged_cells
- end
-end
+ class TestWorksheet < Test::Unit::TestCase
+ def test_need_number
+ sheet = Worksheet.new nil, nil
+ assert_equal false, sheet.need_number?(10)
+ assert_equal false, sheet.need_number?(114.55)
+ assert_equal false, sheet.need_number?(0.1)
+ assert_equal false, sheet.need_number?(0.01)
+ assert_equal false, sheet.need_number?(0 / 0.0) # NaN
+ assert_equal true, sheet.need_number?(0.001)
+ assert_equal true, sheet.need_number?(10000000.0)
+ end
+
+ class RowMock
+ attr_accessor :idx, :first_used, :first_unused, :height, :outline_level
+
+ def initialize
+ @idx, @first_used, @first_unused, @height, @outline_level = 0,0,0,0,1
+ end
+
+ def method_missing name, *args
+ nil
+ end
+ end
+
+ def test_write_row_should_not_write_if_the_row_has_no_used_columns
+ sheet = Worksheet.new nil, nil
+ row = RowMock.new
+ row.first_used = nil
+
+ sheet.write_row row
+
+ assert_equal '', sheet.data
+ end
+
+ def test_write_row_should_write_if_any_column_is_used
+ sheet = Worksheet.new nil, nil
+ row = RowMock.new
+
+ sheet.write_row row
+
+ assert_equal false, sheet.data.empty?
+ end
+ end
end
end
end

0 comments on commit 3748121

Please sign in to comment.