axlsx 1.3.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts_guide +19 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +52 -79
  5. data/Rakefile +0 -5
  6. data/examples/2010_comments.rb +17 -0
  7. data/examples/anchor_swapping.rb +28 -0
  8. data/examples/example.rb +16 -1
  9. data/examples/pivot_table.rb +2 -0
  10. data/examples/underline.rb +13 -0
  11. data/lib/axlsx.rb +8 -0
  12. data/lib/axlsx/doc_props/core.rb +6 -1
  13. data/lib/axlsx/drawing/axes.rb +7 -3
  14. data/lib/axlsx/drawing/bar_3D_chart.rb +2 -2
  15. data/lib/axlsx/drawing/chart.rb +20 -4
  16. data/lib/axlsx/drawing/drawing.rb +2 -17
  17. data/lib/axlsx/drawing/graphic_frame.rb +3 -8
  18. data/lib/axlsx/drawing/hyperlink.rb +5 -12
  19. data/lib/axlsx/drawing/marker.rb +25 -5
  20. data/lib/axlsx/drawing/one_cell_anchor.rb +9 -0
  21. data/lib/axlsx/drawing/pic.rb +17 -23
  22. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  23. data/lib/axlsx/package.rb +31 -11
  24. data/lib/axlsx/rels/relationship.rb +73 -8
  25. data/lib/axlsx/rels/relationships.rb +8 -1
  26. data/lib/axlsx/stylesheet/color.rb +1 -1
  27. data/lib/axlsx/stylesheet/num_fmt.rb +2 -2
  28. data/lib/axlsx/stylesheet/styles.rb +5 -3
  29. data/lib/axlsx/util/serialized_attributes.rb +11 -8
  30. data/lib/axlsx/util/simple_typed_list.rb +34 -13
  31. data/lib/axlsx/util/validators.rb +7 -0
  32. data/lib/axlsx/version.rb +1 -1
  33. data/lib/axlsx/workbook/defined_name.rb +1 -1
  34. data/lib/axlsx/workbook/shared_strings_table.rb +12 -3
  35. data/lib/axlsx/workbook/workbook.rb +31 -8
  36. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  37. data/lib/axlsx/workbook/worksheet/cell.rb +5 -5
  38. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  39. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  40. data/lib/axlsx/workbook/worksheet/comment.rb +6 -5
  41. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  42. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  43. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  44. data/lib/axlsx/workbook/worksheet/pivot_table.rb +32 -18
  45. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -3
  46. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  47. data/lib/axlsx/workbook/worksheet/row.rb +1 -1
  48. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  49. data/lib/axlsx/workbook/worksheet/table.rb +3 -2
  50. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  51. data/lib/axlsx/workbook/worksheet/worksheet.rb +61 -26
  52. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  53. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -9
  54. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -10
  55. data/lib/schema/sml.xsd +4 -0
  56. data/test/axlsx.qcachegrind +2226 -0
  57. data/test/doc_props/tc_core.rb +7 -0
  58. data/test/drawing/tc_axes.rb +8 -0
  59. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  60. data/test/drawing/tc_chart.rb +13 -0
  61. data/test/drawing/tc_drawing.rb +0 -5
  62. data/test/drawing/tc_graphic_frame.rb +4 -7
  63. data/test/drawing/tc_hyperlink.rb +0 -4
  64. data/test/drawing/tc_pic.rb +14 -3
  65. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  66. data/test/profile.rb +7 -3
  67. data/test/rels/tc_relationship.rb +29 -11
  68. data/test/rels/tc_relationships.rb +12 -1
  69. data/test/stylesheet/tc_color.rb +6 -0
  70. data/test/stylesheet/tc_styles.rb +2 -2
  71. data/test/tc_helper.rb +1 -0
  72. data/test/tc_package.rb +30 -0
  73. data/test/util/tc_serialized_attributes.rb +19 -0
  74. data/test/workbook/tc_shared_strings_table.rb +6 -0
  75. data/test/workbook/tc_workbook.rb +23 -1
  76. data/test/workbook/worksheet/tc_break.rb +49 -0
  77. data/test/workbook/worksheet/tc_comment.rb +17 -6
  78. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  79. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  80. data/test/workbook/worksheet/tc_pivot_table.rb +40 -22
  81. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +9 -1
  82. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  83. data/test/workbook/worksheet/tc_table.rb +2 -2
  84. data/test/workbook/worksheet/tc_worksheet.rb +39 -7
  85. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +2 -11
  86. metadata +37 -10
  87. data/test/example.xlsx +0 -0
@@ -23,6 +23,13 @@ class TestCore < Test::Unit::TestCase
23
23
  assert_equal(@doc.xpath('//dcterms:created').text, @time, "dcterms:created incorrect")
24
24
  end
25
25
 
26
+ def test_created_as_option
27
+ time = Time.utc(2013, 1, 1, 12, 00)
28
+ c = Axlsx::Core.new :created => time
29
+ doc = Nokogiri::XML(c.to_xml_string)
30
+ assert_equal(doc.xpath('//dcterms:created').text, time.xmlschema, "dcterms:created incorrect")
31
+ end
32
+
26
33
  def test_populates_default_name
27
34
  assert_equal(@doc.xpath('//dc:creator').text, "axlsx", "Default name not populated")
28
35
  end
@@ -0,0 +1,8 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestAxes < Test::Unit::TestCase
4
+ def test_constructor_requires_cat_axis_first
5
+ assert_raise(ArgumentError) { Axlsx::Axes.new(:val_axis => Axlsx::ValAxis, :cat_axis => Axlsx::CatAxis) }
6
+ assert_nothing_raised { Axlsx::Axes.new(:cat_axis => Axlsx::CatAxis, :val_axis => Axlsx::ValAxis) }
7
+ end
8
+ end
@@ -62,4 +62,10 @@ class TestBar3DChart < Test::Unit::TestCase
62
62
  assert(errors.empty?, "error free validation")
63
63
  end
64
64
 
65
+ def test_to_xml_string_has_axes_in_correct_order
66
+ str = @chart.to_xml_string
67
+ cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
68
+ val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
69
+ assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
70
+ end
65
71
  end
@@ -45,6 +45,14 @@ class TestChart < Test::Unit::TestCase
45
45
  assert_equal(false, @chart.vary_colors)
46
46
  end
47
47
 
48
+ def test_display_blanks_as
49
+ assert_equal(:gap, @chart.display_blanks_as, "default is not :gap")
50
+ assert_raise(ArgumentError, "did not validate possible values") { @chart.display_blanks_as = :hole }
51
+ assert_nothing_raised { @chart.display_blanks_as = :zero }
52
+ assert_nothing_raised { @chart.display_blanks_as = :span }
53
+ assert_equal(:span, @chart.display_blanks_as)
54
+ end
55
+
48
56
  def test_start_at
49
57
  @chart.start_at 15, 25
50
58
  assert_equal(@chart.graphic_frame.anchor.from.col, 15)
@@ -94,4 +102,9 @@ class TestChart < Test::Unit::TestCase
94
102
  assert(errors.empty?, "error free validation")
95
103
  end
96
104
 
105
+ def test_to_xml_string_for_display_blanks_as
106
+ @chart.display_blanks_as = :span
107
+ doc = Nokogiri::XML(@chart.to_xml_string)
108
+ assert_equal("span", doc.xpath("//c:dispBlanksAs").attr("val").value, "did not use the display_blanks_as configuration")
109
+ end
97
110
  end
@@ -53,11 +53,6 @@ class TestDrawing < Test::Unit::TestCase
53
53
  assert_equal(@ws.drawing.rels_pn, "drawings/_rels/drawing1.xml.rels")
54
54
  end
55
55
 
56
- def test_rId
57
- @ws.add_chart(Axlsx::Pie3DChart)
58
- assert_equal(@ws.drawing.rId, "rId1")
59
- end
60
-
61
56
  def test_index
62
57
  @ws.add_chart(Axlsx::Pie3DChart)
63
58
  assert_equal(@ws.drawing.index, @ws.workbook.drawings.index(@ws.drawing))
@@ -17,14 +17,11 @@ class TestGraphicFrame < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_rId
20
- assert_equal(@frame.rId, "rId1")
21
- chart = @ws.add_chart Axlsx::Chart
22
- assert_equal(chart.graphic_frame.rId, "rId2")
20
+ assert_equal @ws.drawing.relationships.for(@chart).Id, @frame.rId
23
21
  end
24
22
 
25
- def test_rId_with_image_and_chart
26
- image = @ws.add_image :image_src => (File.dirname(__FILE__) + "/../../examples/image1.jpeg"), :start_at => [0,25], :width => 200, :height => 200
27
- assert_equal(2, image.id)
28
- assert_equal(1, @chart.index+1)
23
+ def test_to_xml_has_correct_rId
24
+ doc = Nokogiri::XML(@frame.to_xml_string)
25
+ assert_equal @frame.rId, doc.xpath("//c:chart", doc.collect_namespaces).first["r:id"]
29
26
  end
30
27
  end
@@ -51,10 +51,6 @@ class TestHyperlink < Test::Unit::TestCase
51
51
  assert_equal(@hyperlink.highlightClick, false )
52
52
  end
53
53
 
54
- def test_id
55
- assert_equal(@hyperlink.send(:id), 2)
56
- end
57
-
58
54
  def test_history
59
55
  assert_nothing_raised { @hyperlink.history = false }
60
56
  assert_raise(ArgumentError) {@hyperlink.history = "bob"}
@@ -6,6 +6,7 @@ class TestPic < Test::Unit::TestCase
6
6
  @p = Axlsx::Package.new
7
7
  ws = @p.workbook.add_worksheet
8
8
  @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
9
+ @test_img_up = File.dirname(__FILE__) + "/../../examples/IMAGE1UP.JPEG"
9
10
  @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?"
10
11
  end
11
12
 
@@ -21,21 +22,21 @@ class TestPic < Test::Unit::TestCase
21
22
  def test_anchor_swapping
22
23
  #swap from one cell to two cell when end_at is specified
23
24
  assert(@image.anchor.is_a?(Axlsx::OneCellAnchor))
24
- start_at = @image.anchor.from
25
+ start_at = @image.anchor.from
25
26
  @image.end_at 10,5
26
27
  assert(@image.anchor.is_a?(Axlsx::TwoCellAnchor))
27
28
  assert_equal(start_at.col, @image.anchor.from.col)
28
29
  assert_equal(start_at.row, @image.anchor.from.row)
29
30
  assert_equal(10,@image.anchor.to.col)
30
31
  assert_equal(5, @image.anchor.to.row)
31
-
32
+
32
33
  #swap from two cell to one cell when width or height are specified
33
34
  @image.width = 200
34
35
  assert(@image.anchor.is_a?(Axlsx::OneCellAnchor))
35
36
  assert_equal(start_at.col, @image.anchor.from.col)
36
37
  assert_equal(start_at.row, @image.anchor.from.row)
37
38
  assert_equal(200, @image.width)
38
-
39
+
39
40
  end
40
41
  def test_hyperlink
41
42
  assert_equal(@image.hyperlink.href, "https://github.com/randym")
@@ -76,6 +77,10 @@ class TestPic < Test::Unit::TestCase
76
77
  assert_equal(@image.image_src, @test_img)
77
78
  end
78
79
 
80
+ def test_image_src_downcase
81
+ assert_nothing_raised { @image.image_src = @test_img_up }
82
+ end
83
+
79
84
  def test_descr
80
85
  assert_raise(ArgumentError) { @image.descr = 49 }
81
86
  assert_nothing_raised { @image.descr = "test" }
@@ -93,4 +98,10 @@ class TestPic < Test::Unit::TestCase
93
98
  assert(errors.empty?, "error free validation")
94
99
  end
95
100
 
101
+ def test_to_xml_has_correct_r_id
102
+ r_id = @image.anchor.drawing.relationships.for(@image).Id
103
+ doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
104
+ assert_equal r_id, doc.xpath("//a:blip").first["r:embed"]
105
+ end
106
+
96
107
  end
@@ -10,9 +10,6 @@ class TestTwoCellAnchor < Test::Unit::TestCase
10
10
  @anchor = chart.graphic_frame.anchor
11
11
  end
12
12
 
13
- def teardown
14
- end
15
-
16
13
  def test_initialization
17
14
  assert(@anchor.from.col == 0)
18
15
  assert(@anchor.from.row == 0)
@@ -20,6 +17,9 @@ class TestTwoCellAnchor < Test::Unit::TestCase
20
17
  assert(@anchor.to.row == 10)
21
18
  end
22
19
 
20
+ def test_index
21
+ assert_equal(@anchor.index, @anchor.drawing.anchors.index(@anchor))
22
+ end
23
23
 
24
24
  def test_options
25
25
  assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at=>"1" }
@@ -3,6 +3,8 @@
3
3
  $:.unshift "#{File.dirname(__FILE__)}/../lib"
4
4
  require 'axlsx'
5
5
  require 'ruby-prof'
6
+ #RubyProf.measure_mode = RubyProf::MEMORY
7
+ #
6
8
  row = []
7
9
  # Taking worst case scenario of all string data
8
10
  input = (32..126).to_a.pack('U*').chars.to_a
@@ -11,10 +13,12 @@ input = (32..126).to_a.pack('U*').chars.to_a
11
13
  profile = RubyProf.profile do
12
14
  p = Axlsx::Package.new
13
15
  p.workbook.add_worksheet do |sheet|
14
- 30.times do
16
+ 10000.times do
15
17
  sheet << row
16
18
  end
17
19
  end
20
+ p.to_stream
18
21
  end
19
- printer = RubyProf::CallTreePrinter.new(profile)
20
- printer.print(File.new('axlsx.qcachegrind', 'w'))
22
+
23
+ printer = RubyProf::FlatPrinter.new(profile)
24
+ printer.print(STDOUT, {})
@@ -1,26 +1,44 @@
1
1
  require 'tc_helper.rb'
2
2
 
3
3
  class TestRelationships < Test::Unit::TestCase
4
- def setup
4
+
5
+ def test_instances_with_different_attributes_have_unique_ids
6
+ rel_1 = Axlsx::Relationship.new(Object.new, Axlsx::WORKSHEET_R, 'target')
7
+ rel_2 = Axlsx::Relationship.new(Object.new, Axlsx::COMMENT_R, 'foobar')
8
+ assert_not_equal rel_1.Id, rel_2.Id
5
9
  end
6
-
7
- def teardown
10
+
11
+ def test_instances_with_same_attributes_share_id
12
+ source_obj = Object.new
13
+ instance = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target')
14
+ assert_equal instance.Id, Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target').Id
8
15
  end
9
-
16
+
17
+ def test_target_is_only_considered_for_same_attributes_check_if_target_mode_is_external
18
+ source_obj = Object.new
19
+ rel_1 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target')
20
+ rel_2 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, '../target')
21
+ assert_equal rel_1.Id, rel_2.Id
22
+
23
+ rel_3 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, 'target', :target_mode => :External)
24
+ rel_4 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, '../target', :target_mode => :External)
25
+ assert_not_equal rel_3.Id, rel_4.Id
26
+ end
27
+
10
28
  def test_type
11
- assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target' }
12
- assert_nothing_raised { Axlsx::Relationship.new Axlsx::WORKSHEET_R, 'target' }
13
- assert_nothing_raised { Axlsx::Relationship.new Axlsx::COMMENT_R, 'target' }
29
+ assert_raise(ArgumentError) { Axlsx::Relationship.new nil, 'type', 'target' }
30
+ assert_nothing_raised { Axlsx::Relationship.new nil, Axlsx::WORKSHEET_R, 'target' }
31
+ assert_nothing_raised { Axlsx::Relationship.new nil, Axlsx::COMMENT_R, 'target' }
14
32
  end
15
33
 
16
34
  def test_target_mode
17
- assert_raise(ArgumentError) { Axlsx::Relationship.new 'type', 'target', :target_mode => "FISH" }
18
- assert_nothing_raised { Axlsx::Relationship.new( Axlsx::WORKSHEET_R, 'target', :target_mode => :External) }
35
+ assert_raise(ArgumentError) { Axlsx::Relationship.new nil, 'type', 'target', :target_mode => "FISH" }
36
+ assert_nothing_raised { Axlsx::Relationship.new( nil, Axlsx::WORKSHEET_R, 'target', :target_mode => :External) }
19
37
  end
20
38
 
21
39
  def test_ampersand_escaping_in_target
22
- r = Axlsx::Relationship.new(Axlsx::HYPERLINK_R, "http://example.com?foo=1&bar=2", :target_mod => :External)
23
- doc = Nokogiri::XML(r.to_xml_string(1))
40
+ r = Axlsx::Relationship.new(nil, Axlsx::HYPERLINK_R, "http://example.com?foo=1&bar=2", :target_mod => :External)
41
+ doc = Nokogiri::XML(r.to_xml_string)
24
42
  assert_equal(doc.xpath("//Relationship[@Target='http://example.com?foo=1&bar=2']").size, 1)
25
43
  end
26
44
  end
@@ -2,6 +2,17 @@ require 'tc_helper.rb'
2
2
 
3
3
  class TestRelationships < Test::Unit::TestCase
4
4
 
5
+ def test_for
6
+ source_obj_1, source_obj_2 = Object.new, Object.new
7
+ rel_1 = Axlsx::Relationship.new(source_obj_1, Axlsx::WORKSHEET_R, "bar")
8
+ rel_2 = Axlsx::Relationship.new(source_obj_2, Axlsx::WORKSHEET_R, "bar")
9
+ rels = Axlsx::Relationships.new
10
+ rels << rel_1
11
+ rels << rel_2
12
+ assert_equal rel_1, rels.for(source_obj_1)
13
+ assert_equal rel_2, rels.for(source_obj_2)
14
+ end
15
+
5
16
  def test_valid_document
6
17
  @rels = Axlsx::Relationships.new
7
18
  schema = Nokogiri::XML::Schema(File.open(Axlsx::RELS_XSD))
@@ -12,7 +23,7 @@ class TestRelationships < Test::Unit::TestCase
12
23
  errors << error
13
24
  end
14
25
 
15
- @rels << Axlsx::Relationship.new(Axlsx::WORKSHEET_R, "bar")
26
+ @rels << Axlsx::Relationship.new(nil, Axlsx::WORKSHEET_R, "bar")
16
27
  doc = Nokogiri::XML(@rels.to_xml_string)
17
28
  errors = []
18
29
  schema.validate(doc).each do |error|
@@ -27,6 +27,12 @@ class TestColor < Test::Unit::TestCase
27
27
  assert_equal(@item.rgb, "FF00FF00" )
28
28
  end
29
29
 
30
+ def test_rgb_writer_doesnt_mutate_its_argument
31
+ my_rgb = 'ff00ff00'
32
+ @item.rgb = my_rgb
33
+ assert_equal 'ff00ff00', my_rgb
34
+ end
35
+
30
36
  def test_tint
31
37
  assert_raise(ArgumentError) { @item.tint = -1 }
32
38
  assert_nothing_raised { @item.tint = -1.0 }
@@ -150,7 +150,7 @@ class TestStyles < Test::Unit::TestCase
150
150
  assert_equal(@styles.parse_fill_options(:bg_color => "DE").class, Fixnum, "return index of fill if not :dxf type")
151
151
  assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type")
152
152
  f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf)
153
- assert(f.fill_type.fgColor.rgb == "FFDEDEDE")
153
+ assert(f.fill_type.bgColor.rgb == "FFDEDEDE")
154
154
  end
155
155
 
156
156
  def test_parse_protection_options
@@ -210,7 +210,7 @@ class TestStyles < Test::Unit::TestCase
210
210
  assert_equal(0, style, "returns the zero-based dxfId")
211
211
 
212
212
  dxf = @styles.dxfs.last
213
- assert_equal(@styles.dxfs.last.fill.fill_type.fgColor.rgb, "FF000000", "fill created with color")
213
+ assert_equal(@styles.dxfs.last.fill.fill_type.bgColor.rgb, "FF000000", "fill created with color")
214
214
 
215
215
  assert_equal(font_count, (@styles.fonts.size), "font not created under styles")
216
216
  assert_equal(fill_count, (@styles.fills.size), "fill not created under styles")
@@ -6,4 +6,5 @@ SimpleCov.start do
6
6
  end
7
7
 
8
8
  require 'test/unit'
9
+ require "timecop"
9
10
  require "axlsx.rb"
@@ -59,6 +59,7 @@ class TestPackage < Test::Unit::TestCase
59
59
  image.height=666
60
60
  image.hyperlink.tooltip = "Labeled Link"
61
61
  image.start_at 5, 5
62
+ image.end_at 10, 10
62
63
  end
63
64
  ws.add_image :image_src => File.expand_path('../../examples/image1.gif', __FILE__) do |image|
64
65
  image.start_at 0, 20
@@ -74,6 +75,8 @@ class TestPackage < Test::Unit::TestCase
74
75
 
75
76
  ws.add_pivot_table 'G5:G6', 'A1:B3'
76
77
 
78
+ ws.add_page_break "B2"
79
+
77
80
  end
78
81
 
79
82
  def test_use_autowidth
@@ -105,6 +108,12 @@ class TestPackage < Test::Unit::TestCase
105
108
  assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default')
106
109
  end
107
110
 
111
+ def test_created_at_is_propagated_to_core
112
+ time = Time.utc(2013, 1, 1, 12, 0)
113
+ p = Axlsx::Package.new :created_at => time
114
+ assert_equal(time, p.core.created)
115
+ end
116
+
108
117
  def test_serialization
109
118
  assert_nothing_raised do
110
119
  begin
@@ -117,6 +126,27 @@ class TestPackage < Test::Unit::TestCase
117
126
  end
118
127
  end
119
128
  end
129
+
130
+ # See comment for Package#zip_entry_for_part
131
+ def test_serialization_creates_identical_files_at_any_time_if_created_at_is_set
132
+ @package.core.created = Time.now
133
+ zip_content_now = @package.to_stream.string
134
+ Timecop.travel(3600) do
135
+ zip_content_then = @package.to_stream.string
136
+ assert zip_content_then == zip_content_now, "zip files are not identical"
137
+ end
138
+ end
139
+
140
+ def test_serialization_creates_identical_files_for_identical_packages
141
+ package_1, package_2 = 2.times.map do
142
+ Axlsx::Package.new(:created_at => Time.utc(2013, 1, 1)).tap do |p|
143
+ p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
144
+ sheet.add_row [1, 2, 3]
145
+ end
146
+ end
147
+ end
148
+ assert package_1.to_stream.string == package_2.to_stream.string, "zip files are not identical"
149
+ end
120
150
 
121
151
  def test_validation
122
152
  assert_equal(@package.validate.size, 0, @package.validate)
@@ -0,0 +1,19 @@
1
+ require 'tc_helper.rb'
2
+ class Funk
3
+ include Axlsx::Accessors
4
+ include Axlsx::SerializedAttributes
5
+ serializable_attributes :camel_symbol, :boolean, :integer
6
+
7
+ attr_accessor :camel_symbol, :boolean, :integer
8
+ end
9
+
10
+ class TestSeralizedAttributes < Test::Unit::TestCase
11
+ def setup
12
+ @object = Funk.new
13
+ end
14
+
15
+ def test_camel_symbol
16
+ @object.camel_symbol = :foo_bar
17
+ assert_equal('camelSymbol="fooBar" ', @object.serialized_attributes)
18
+ end
19
+ end
@@ -24,6 +24,12 @@ class TestSharedStringsTable < Test::Unit::TestCase
24
24
  assert_equal(sst.unique_count, 4)
25
25
  end
26
26
 
27
+ def test_uses_workbook_xml_space
28
+ assert_equal(@p.workbook.xml_space, @p.workbook.shared_strings.xml_space)
29
+ @p.workbook.xml_space = :default
30
+ assert_equal(:default, @p.workbook.shared_strings.xml_space)
31
+ end
32
+
27
33
  def test_valid_document
28
34
  schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
29
35
  doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml_string)
@@ -9,6 +9,23 @@ class TestWorkbook < Test::Unit::TestCase
9
9
  def teardown
10
10
  end
11
11
 
12
+ def test_worksheet_users_xml_space
13
+ sheet = @wb.add_worksheet(:name => 'foo')
14
+ ws_xml = Nokogiri::XML(sheet.to_xml_string)
15
+ assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='preserve'"))
16
+
17
+ @wb.xml_space = :default
18
+ ws_xml = Nokogiri::XML(sheet.to_xml_string)
19
+ assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='default'"))
20
+ end
21
+
22
+ def test_xml_space
23
+ assert_equal(:preserve, @wb.xml_space)
24
+ @wb.xml_space = :default
25
+ assert_equal(:default, @wb.xml_space)
26
+ assert_raise(ArgumentError) { @wb.xml_space = :none }
27
+ end
28
+
12
29
  def test_no_autowidth
13
30
  assert_equal(@wb.use_autowidth, true)
14
31
  assert_raise(ArgumentError) {@wb.use_autowidth = 0.1}
@@ -99,5 +116,10 @@ class TestWorkbook < Test::Unit::TestCase
99
116
  assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].auto_filter.defined_name)
100
117
  end
101
118
 
102
-
119
+ def test_to_xml_uses_correct_rIds_for_pivotCache
120
+ ws = @wb.add_worksheet
121
+ pivot_table = ws.add_pivot_table('G5:G6', 'A1:D5')
122
+ doc = Nokogiri::XML(@wb.to_xml_string)
123
+ assert_equal pivot_table.cache_definition.rId, doc.xpath("//xmlns:pivotCache").first["r:id"]
124
+ end
103
125
  end