From b5a6263ec3ec0a729c9b2bec86c22d1ead33eb65 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Thu, 12 Sep 2013 22:13:09 +0900 Subject: repair pivot table data ref populate and bring coverage back up to 100% --- lib/axlsx/workbook/worksheet/pivot_table.rb | 6 ++++-- test/drawing/tc_two_cell_anchor.rb | 6 +++--- test/tc_package.rb | 1 + test/workbook/worksheet/tc_pivot_table.rb | 3 ++- test/workbook/worksheet/tc_worksheet.rb | 15 ++++++++++++++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index 0de22f8f..d27e08ad 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -253,7 +253,7 @@ module Axlsx '' << '' << '' - elsif data.include? cell_ref + elsif data_refs.include? cell_ref '' << '' else @@ -261,7 +261,9 @@ module Axlsx '' end end - + def data_refs + data.map { |hash| hash[:ref] } + end def header_range range.gsub(/^(\w+?)(\d+)\:(\w+?)\d+$/, '\1\2:\3\2') end diff --git a/test/drawing/tc_two_cell_anchor.rb b/test/drawing/tc_two_cell_anchor.rb index 66f8bd58..db84521d 100644 --- a/test/drawing/tc_two_cell_anchor.rb +++ b/test/drawing/tc_two_cell_anchor.rb @@ -10,9 +10,6 @@ class TestTwoCellAnchor < Test::Unit::TestCase @anchor = chart.graphic_frame.anchor end - def teardown - end - def test_initialization assert(@anchor.from.col == 0) assert(@anchor.from.row == 0) @@ -20,6 +17,9 @@ class TestTwoCellAnchor < Test::Unit::TestCase assert(@anchor.to.row == 10) end + def test_index + assert_equal(@anchor.index, @anchor.drawing.anchors.index(@anchor)) + end def test_options assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at=>"1" } diff --git a/test/tc_package.rb b/test/tc_package.rb index 4d77b8bd..4df44ea4 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -59,6 +59,7 @@ class TestPackage < Test::Unit::TestCase image.height=666 image.hyperlink.tooltip = "Labeled Link" image.start_at 5, 5 + image.end_at 10, 10 end ws.add_image :image_src => File.expand_path('../../examples/image1.gif', __FILE__) do |image| image.start_at 0, 20 diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb index 56ac4bd4..3c42d605 100644 --- a/test/workbook/worksheet/tc_pivot_table.rb +++ b/test/workbook/worksheet/tc_pivot_table.rb @@ -47,7 +47,7 @@ class TestPivotTable < Test::Unit::TestCase end def test_add_pivot_table_with_config - pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt| + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt| pt.rows = ['Year', 'Month'] pt.columns = ['Type'] pt.data = ['Sales'] @@ -57,6 +57,7 @@ class TestPivotTable < Test::Unit::TestCase assert_equal(['Type'], pivot_table.columns) assert_equal([{:ref=>"Sales"}], pivot_table.data) assert_equal(['Region'], pivot_table.pages) + shared_test_pivot_table_xml_validity(pivot_table) end def test_add_pivot_table_with_options_on_data_field diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index f6037f57..3782b215 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -167,7 +167,7 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook") end - def test_add_page_break + def test_add_page_break_with_string_cell_ref assert(@ws.row_breaks.empty?) assert(@ws.col_breaks.empty?) @ws.add_page_break("B1") @@ -175,6 +175,19 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(1, @ws.col_breaks.size) end + def test_add_page_break_with_cell + @ws.add_row [1, 2, 3, 4] + @ws.add_row [1, 2, 3, 4] + + + assert(@ws.row_breaks.empty?) + assert(@ws.col_breaks.empty?) + @ws.add_page_break(@ws.rows.last.cells[1]) + assert_equal(1, @ws.row_breaks.size) + assert_equal(1, @ws.col_breaks.size) + end + + def test_drawing assert @ws.drawing == nil @ws.add_chart(Axlsx::Pie3DChart) -- cgit v1.2.3