caxlsx 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -1
  3. data/README.md +4 -11
  4. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  5. data/lib/axlsx/doc_props/app.rb +1 -1
  6. data/lib/axlsx/drawing/chart.rb +25 -2
  7. data/lib/axlsx/drawing/d_lbls.rb +3 -2
  8. data/lib/axlsx/drawing/scatter_series.rb +31 -0
  9. data/lib/axlsx/drawing/title.rb +11 -1
  10. data/lib/axlsx/drawing/view_3D.rb +1 -1
  11. data/lib/axlsx/package.rb +15 -5
  12. data/lib/axlsx/rels/relationship.rb +1 -1
  13. data/lib/axlsx/stylesheet/border.rb +2 -0
  14. data/lib/axlsx/stylesheet/font.rb +1 -1
  15. data/lib/axlsx/stylesheet/styles.rb +139 -24
  16. data/lib/axlsx/util/constants.rb +16 -1
  17. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  18. data/lib/axlsx/util/storage.rb +9 -9
  19. data/lib/axlsx/version.rb +1 -1
  20. data/lib/axlsx/workbook/workbook.rb +55 -0
  21. data/lib/axlsx/workbook/worksheet/border_creator.rb +76 -0
  22. data/lib/axlsx/workbook/worksheet/cell.rb +29 -2
  23. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  24. data/lib/axlsx/workbook/worksheet/col.rb +4 -4
  25. data/lib/axlsx/workbook/worksheet/data_validation.rb +26 -5
  26. data/lib/axlsx/workbook/worksheet/pivot_table.rb +55 -14
  27. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
  28. data/lib/axlsx/workbook/worksheet/worksheet.rb +68 -7
  29. data/lib/axlsx.rb +43 -10
  30. metadata +6 -253
  31. data/test/benchmark.rb +0 -72
  32. data/test/content_type/tc_content_type.rb +0 -76
  33. data/test/content_type/tc_default.rb +0 -16
  34. data/test/content_type/tc_override.rb +0 -14
  35. data/test/doc_props/tc_app.rb +0 -43
  36. data/test/doc_props/tc_core.rb +0 -42
  37. data/test/drawing/tc_area_chart.rb +0 -39
  38. data/test/drawing/tc_area_series.rb +0 -71
  39. data/test/drawing/tc_axes.rb +0 -8
  40. data/test/drawing/tc_axis.rb +0 -112
  41. data/test/drawing/tc_bar_3D_chart.rb +0 -86
  42. data/test/drawing/tc_bar_chart.rb +0 -86
  43. data/test/drawing/tc_bar_series.rb +0 -46
  44. data/test/drawing/tc_bubble_chart.rb +0 -44
  45. data/test/drawing/tc_bubble_series.rb +0 -21
  46. data/test/drawing/tc_cat_axis.rb +0 -31
  47. data/test/drawing/tc_cat_axis_data.rb +0 -27
  48. data/test/drawing/tc_chart.rb +0 -123
  49. data/test/drawing/tc_d_lbls.rb +0 -57
  50. data/test/drawing/tc_data_source.rb +0 -23
  51. data/test/drawing/tc_drawing.rb +0 -80
  52. data/test/drawing/tc_graphic_frame.rb +0 -27
  53. data/test/drawing/tc_hyperlink.rb +0 -64
  54. data/test/drawing/tc_line_3d_chart.rb +0 -47
  55. data/test/drawing/tc_line_chart.rb +0 -39
  56. data/test/drawing/tc_line_series.rb +0 -71
  57. data/test/drawing/tc_marker.rb +0 -44
  58. data/test/drawing/tc_named_axis_data.rb +0 -27
  59. data/test/drawing/tc_num_data.rb +0 -31
  60. data/test/drawing/tc_num_val.rb +0 -29
  61. data/test/drawing/tc_one_cell_anchor.rb +0 -66
  62. data/test/drawing/tc_pic.rb +0 -103
  63. data/test/drawing/tc_picture_locking.rb +0 -72
  64. data/test/drawing/tc_pie_3D_chart.rb +0 -28
  65. data/test/drawing/tc_pie_series.rb +0 -33
  66. data/test/drawing/tc_scaling.rb +0 -36
  67. data/test/drawing/tc_scatter_chart.rb +0 -48
  68. data/test/drawing/tc_scatter_series.rb +0 -56
  69. data/test/drawing/tc_ser_axis.rb +0 -31
  70. data/test/drawing/tc_series.rb +0 -23
  71. data/test/drawing/tc_series_title.rb +0 -54
  72. data/test/drawing/tc_str_data.rb +0 -18
  73. data/test/drawing/tc_str_val.rb +0 -30
  74. data/test/drawing/tc_title.rb +0 -70
  75. data/test/drawing/tc_two_cell_anchor.rb +0 -36
  76. data/test/drawing/tc_val_axis.rb +0 -24
  77. data/test/drawing/tc_view_3D.rb +0 -54
  78. data/test/drawing/tc_vml_drawing.rb +0 -25
  79. data/test/drawing/tc_vml_shape.rb +0 -106
  80. data/test/fixtures/image1.gif +0 -0
  81. data/test/fixtures/image1.jpeg +0 -0
  82. data/test/fixtures/image1.jpg +0 -0
  83. data/test/fixtures/image1.png +0 -0
  84. data/test/fixtures/image1_fake.jpg +0 -0
  85. data/test/profile.rb +0 -24
  86. data/test/rels/tc_relationship.rb +0 -52
  87. data/test/rels/tc_relationships.rb +0 -37
  88. data/test/stylesheet/tc_border.rb +0 -37
  89. data/test/stylesheet/tc_border_pr.rb +0 -32
  90. data/test/stylesheet/tc_cell_alignment.rb +0 -81
  91. data/test/stylesheet/tc_cell_protection.rb +0 -29
  92. data/test/stylesheet/tc_cell_style.rb +0 -57
  93. data/test/stylesheet/tc_color.rb +0 -43
  94. data/test/stylesheet/tc_dxf.rb +0 -81
  95. data/test/stylesheet/tc_fill.rb +0 -18
  96. data/test/stylesheet/tc_font.rb +0 -133
  97. data/test/stylesheet/tc_gradient_fill.rb +0 -72
  98. data/test/stylesheet/tc_gradient_stop.rb +0 -31
  99. data/test/stylesheet/tc_num_fmt.rb +0 -30
  100. data/test/stylesheet/tc_pattern_fill.rb +0 -43
  101. data/test/stylesheet/tc_styles.rb +0 -261
  102. data/test/stylesheet/tc_table_style.rb +0 -44
  103. data/test/stylesheet/tc_table_style_element.rb +0 -45
  104. data/test/stylesheet/tc_table_styles.rb +0 -29
  105. data/test/stylesheet/tc_xf.rb +0 -120
  106. data/test/tc_axlsx.rb +0 -109
  107. data/test/tc_helper.rb +0 -10
  108. data/test/tc_package.rb +0 -314
  109. data/test/util/tc_mime_type_utils.rb +0 -13
  110. data/test/util/tc_serialized_attributes.rb +0 -19
  111. data/test/util/tc_simple_typed_list.rb +0 -77
  112. data/test/util/tc_validators.rb +0 -210
  113. data/test/workbook/tc_defined_name.rb +0 -49
  114. data/test/workbook/tc_shared_strings_table.rb +0 -59
  115. data/test/workbook/tc_workbook.rb +0 -160
  116. data/test/workbook/tc_workbook_view.rb +0 -50
  117. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +0 -38
  118. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +0 -76
  119. data/test/workbook/worksheet/auto_filter/tc_filters.rb +0 -50
  120. data/test/workbook/worksheet/tc_break.rb +0 -49
  121. data/test/workbook/worksheet/tc_cell.rb +0 -453
  122. data/test/workbook/worksheet/tc_cfvo.rb +0 -31
  123. data/test/workbook/worksheet/tc_col.rb +0 -93
  124. data/test/workbook/worksheet/tc_color_scale.rb +0 -58
  125. data/test/workbook/worksheet/tc_comment.rb +0 -72
  126. data/test/workbook/worksheet/tc_comments.rb +0 -57
  127. data/test/workbook/worksheet/tc_conditional_formatting.rb +0 -224
  128. data/test/workbook/worksheet/tc_data_bar.rb +0 -46
  129. data/test/workbook/worksheet/tc_data_validation.rb +0 -265
  130. data/test/workbook/worksheet/tc_date_time_converter.rb +0 -124
  131. data/test/workbook/worksheet/tc_header_footer.rb +0 -151
  132. data/test/workbook/worksheet/tc_icon_set.rb +0 -45
  133. data/test/workbook/worksheet/tc_outline_pr.rb +0 -19
  134. data/test/workbook/worksheet/tc_page_margins.rb +0 -97
  135. data/test/workbook/worksheet/tc_page_set_up_pr.rb +0 -15
  136. data/test/workbook/worksheet/tc_page_setup.rb +0 -143
  137. data/test/workbook/worksheet/tc_pane.rb +0 -54
  138. data/test/workbook/worksheet/tc_pivot_table.rb +0 -143
  139. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +0 -62
  140. data/test/workbook/worksheet/tc_print_options.rb +0 -72
  141. data/test/workbook/worksheet/tc_protected_range.rb +0 -17
  142. data/test/workbook/worksheet/tc_rich_text.rb +0 -44
  143. data/test/workbook/worksheet/tc_rich_text_run.rb +0 -173
  144. data/test/workbook/worksheet/tc_row.rb +0 -160
  145. data/test/workbook/worksheet/tc_selection.rb +0 -55
  146. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +0 -18
  147. data/test/workbook/worksheet/tc_sheet_format_pr.rb +0 -88
  148. data/test/workbook/worksheet/tc_sheet_pr.rb +0 -49
  149. data/test/workbook/worksheet/tc_sheet_protection.rb +0 -117
  150. data/test/workbook/worksheet/tc_sheet_view.rb +0 -214
  151. data/test/workbook/worksheet/tc_table.rb +0 -77
  152. data/test/workbook/worksheet/tc_table_style_info.rb +0 -53
  153. data/test/workbook/worksheet/tc_worksheet.rb +0 -601
  154. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +0 -55
@@ -1,59 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestSharedStringsTable < Test::Unit::TestCase
4
-
5
- def setup
6
- @p = Axlsx::Package.new :use_shared_strings=>true
7
-
8
- ws = @p.workbook.add_worksheet
9
- ws.add_row ['a', 1, 'b']
10
- ws.add_row ['b', 1, 'c']
11
- ws.add_row ['c', 1, 'd']
12
- ws.rows.last.add_cell('b', :type => :text)
13
- end
14
-
15
- def test_workbook_has_shared_strings
16
- assert(@p.workbook.shared_strings.is_a?(Axlsx::SharedStringsTable), "shared string table was not created")
17
- end
18
-
19
- def test_count
20
- sst = @p.workbook.shared_strings
21
- assert_equal(sst.count, 7)
22
- end
23
-
24
- def test_unique_count
25
- sst = @p.workbook.shared_strings
26
- assert_equal(sst.unique_count, 4)
27
- end
28
-
29
- def test_uses_workbook_xml_space
30
- assert_equal(@p.workbook.xml_space, @p.workbook.shared_strings.xml_space)
31
- @p.workbook.xml_space = :default
32
- assert_equal(:default, @p.workbook.shared_strings.xml_space)
33
- end
34
-
35
- def test_valid_document
36
- schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
37
- doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml_string)
38
- errors = []
39
- schema.validate(doc).each do |error|
40
- puts error.message
41
- errors << error
42
- end
43
- assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s)
44
- end
45
-
46
- def test_remove_control_characters_in_xml_serialization
47
- nasties = "hello\x10\x00\x1C\x1Eworld"
48
- @p.workbook.worksheets[0].add_row [nasties]
49
-
50
- # test that the nasty string was added to the shared strings
51
- assert @p.workbook.shared_strings.unique_cells.has_key?(nasties)
52
-
53
- # test that none of the control characters are in the XML output for shared strings
54
- assert_no_match(/#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string)
55
-
56
- # assert that the shared string was normalized to remove the control characters
57
- assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld")
58
- end
59
- end
@@ -1,160 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestWorkbook < Test::Unit::TestCase
4
- def setup
5
- p = Axlsx::Package.new
6
- @wb = p.workbook
7
- end
8
-
9
- def teardown
10
- end
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
-
29
- def test_no_autowidth
30
- assert_equal(@wb.use_autowidth, true)
31
- assert_raise(ArgumentError) {@wb.use_autowidth = 0.1}
32
- assert_nothing_raised {@wb.use_autowidth = false}
33
- assert_equal(@wb.use_autowidth, false)
34
- end
35
-
36
- def test_is_reversed
37
- assert_equal(@wb.is_reversed, nil)
38
- assert_raise(ArgumentError) {@wb.is_reversed = 0.1}
39
- assert_nothing_raised {@wb.is_reversed = true }
40
- assert_equal(@wb.use_autowidth, true)
41
- end
42
-
43
- def test_sheet_by_name_retrieval
44
- @wb.add_worksheet(:name=>'foo')
45
- @wb.add_worksheet(:name=>'bar')
46
- assert_equal('foo', @wb.sheet_by_name('foo').name)
47
-
48
- end
49
- def test_date1904
50
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
51
- @wb.date1904 = :false
52
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
53
- Axlsx::Workbook.date1904 = :true
54
- assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
55
- end
56
-
57
- def test_add_defined_name
58
- @wb.add_defined_name 'Sheet1!1:1', :name => '_xlnm.Print_Titles', :hidden => true
59
- assert_equal(1, @wb.defined_names.size)
60
- end
61
-
62
- def test_add_view
63
- @wb.add_view visibility: :hidden, window_width: 800
64
- assert_equal(1, @wb.views.size)
65
- end
66
-
67
- def test_shared_strings
68
- assert_equal(@wb.use_shared_strings, nil)
69
- assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
70
- assert_nothing_raised {@wb.use_shared_strings = :true}
71
- end
72
-
73
- def test_add_worksheet
74
- assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
75
- ws = @wb.add_worksheet(:name=>"bob")
76
- assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!")
77
- assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
78
- assert_equal(ws.name, "bob", "name option gets passed to worksheet")
79
- end
80
-
81
- def test_insert_worksheet
82
- @wb.add_worksheet(:name => 'A')
83
- @wb.add_worksheet(:name => 'B')
84
- ws3 = @wb.insert_worksheet(0, :name => 'C')
85
- assert_equal(ws3.name, @wb.worksheets.first.name)
86
- end
87
-
88
- def test_relationships
89
- #current relationship size is 1 due to style relation
90
- assert(@wb.relationships.size == 1)
91
- @wb.add_worksheet
92
- assert(@wb.relationships.size == 2)
93
- @wb.use_shared_strings = true
94
- assert(@wb.relationships.size == 3)
95
- end
96
-
97
- def test_to_xml
98
- schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
99
- doc = Nokogiri::XML(@wb.to_xml_string)
100
- errors = []
101
- schema.validate(doc).each do |error|
102
- errors.push error
103
- puts error.message
104
- end
105
- assert(errors.empty?, "error free validation")
106
- end
107
-
108
- def test_to_xml_reversed
109
- @wb.is_reversed = true
110
- @wb.add_worksheet(:name => 'first')
111
- second = @wb.add_worksheet(:name => 'second')
112
- doc = Nokogiri::XML(@wb.to_xml_string)
113
- assert_equal second.name, doc.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
114
- end
115
-
116
- def test_range_requires_valid_sheet
117
- ws = @wb.add_worksheet :name=>'fish'
118
- ws.add_row [1,2,3]
119
- ws.add_row [4,5,6]
120
- assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"]}
121
- assert_equal @wb['fish!A1:C2'].size, 6
122
- end
123
-
124
- def test_to_xml_adds_worksheet_when_worksheets_is_empty
125
- assert(@wb.worksheets.empty?)
126
- @wb.to_xml_string
127
- assert(@wb.worksheets.size == 1)
128
- end
129
-
130
- def test_to_xml_string_defined_names
131
- @wb.add_worksheet do |sheet|
132
- sheet.add_row [1, "two"]
133
- sheet.auto_filter = "A1:B1"
134
- end
135
- doc = Nokogiri::XML(@wb.to_xml_string)
136
- assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].auto_filter.defined_name)
137
- end
138
-
139
- def test_to_xml_string_book_views
140
- @wb.add_worksheet do |sheet|
141
- sheet.add_row [1, "two"]
142
- end
143
- @wb.add_view active_tab: 0, first_sheet: 0
144
- doc = Nokogiri::XML(@wb.to_xml_string)
145
- assert_equal(1, doc.xpath('//xmlns:workbook/xmlns:bookViews/xmlns:workbookView[@activeTab=0]').size)
146
- end
147
-
148
- def test_to_xml_uses_correct_rIds_for_pivotCache
149
- ws = @wb.add_worksheet
150
- pivot_table = ws.add_pivot_table('G5:G6', 'A1:D5')
151
- doc = Nokogiri::XML(@wb.to_xml_string)
152
- assert_equal pivot_table.cache_definition.rId, doc.xpath("//xmlns:pivotCache").first["r:id"]
153
- end
154
-
155
- def test_worksheet_name_is_intact_after_serialized_into_xml
156
- sheet = @wb.add_worksheet(:name => '_Example')
157
- wb_xml = Nokogiri::XML(@wb.to_xml_string)
158
- assert_equal sheet.name, wb_xml.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
159
- end
160
- end
@@ -1,50 +0,0 @@
1
- require 'tc_helper'
2
-
3
- class TestWorkbookView < Test::Unit::TestCase
4
-
5
- def setup
6
- @options = { visibility: :hidden, minimized: true, show_horizontal_scroll: true, show_vertical_scroll: true,
7
- show_sheet_tabs: true, tab_ratio: 750, first_sheet: 0, active_tab: 1, x_window: 500, y_window: 400,
8
- window_width: 800, window_height: 600, auto_filter_date_grouping: true }
9
- @book_view = Axlsx::WorkbookView.new @options
10
- end
11
-
12
- def test_options_assignation
13
- @options.each do |key, value|
14
- assert_equal(value, @book_view.send(key))
15
- end
16
- end
17
-
18
- def test_boolean_attribute_validation
19
- %w(minimized show_horizontal_scroll show_vertical_scroll show_sheet_tabs auto_filter_date_grouping).each do |attr|
20
- assert_raise(ArgumentError, 'only booleanish allowed in boolean attributes') { @book_view.send("#{attr}=", "banana") }
21
- assert_nothing_raised { @book_view.send("#{attr}=", false )}
22
- end
23
- end
24
-
25
- def test_integer_attribute_validation
26
- %w(tab_ratio first_sheet active_tab x_window y_window window_width window_height).each do |attr|
27
- assert_raise(ArgumentError, 'only integer allowed in integer attributes') { @book_view.send("#{attr}=", "b") }
28
- assert_nothing_raised { @book_view.send("#{attr}=", 7 )}
29
- end
30
- end
31
-
32
- def test_visibility_attribute_validation
33
- assert_raise(ArgumentError) { @book_view.visibility = :foobar }
34
- assert_nothing_raised { @book_view.visibility = :hidden }
35
- assert_nothing_raised { @book_view.visibility = :very_hidden }
36
- assert_nothing_raised { @book_view.visibility = :visible }
37
- end
38
-
39
- def test_to_xml_string
40
- xml = @book_view.to_xml_string
41
- doc = Nokogiri::XML(xml)
42
- @options.each do |key, value|
43
- if value == true || value == false
44
- value = value ? 1 : 0
45
- end
46
- path = "workbookView[@#{Axlsx.camel(key, false)}='#{value}']"
47
- assert_equal(1, doc.xpath(path).size)
48
- end
49
- end
50
- end
@@ -1,38 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestAutoFilter < Test::Unit::TestCase
4
-
5
- def setup
6
- ws = Axlsx::Package.new.workbook.add_worksheet
7
- 3.times { |index| ws.add_row [1*index,2*index,3*index] }
8
- @auto_filter = ws.auto_filter
9
- @auto_filter.range = 'A1:C3'
10
- @auto_filter.add_column 0, :filters, :filter_items => [1]
11
- end
12
-
13
- def test_defined_name
14
- assert_equal("'Sheet1'!$A$1:$C$3", @auto_filter.defined_name)
15
- end
16
-
17
- def test_to_xml_string
18
- doc = Nokogiri::XML(@auto_filter.to_xml_string)
19
- assert(doc.xpath("autoFilter[@ref='#{@auto_filter.range}']"))
20
- end
21
-
22
- def test_columns
23
- assert @auto_filter.columns.is_a?(Axlsx::SimpleTypedList)
24
- assert_equal @auto_filter.columns.allowed_types, [Axlsx::FilterColumn]
25
- end
26
-
27
- def test_add_column
28
- @auto_filter.add_column(0, :filters) do |column|
29
- assert column.is_a? FilterColumn
30
- end
31
- end
32
-
33
- def test_applya
34
- assert_equal nil, @auto_filter.worksheet.rows.last.hidden
35
- @auto_filter.apply
36
- assert_equal true, @auto_filter.worksheet.rows.last.hidden
37
- end
38
- end
@@ -1,76 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestFilterColumn < Test::Unit::TestCase
4
-
5
- def setup
6
- @filter_column = Axlsx::FilterColumn.new(0, :filters, :filter_items => [200])
7
- end
8
-
9
-
10
- def test_initialize_col_id
11
- assert_raise ArgumentError do
12
- Axlsx::FilterColumn.new(0, :bobs_house_of_filter)
13
- end
14
- assert_raise ArgumentError do
15
- Axlsx::FilterColumn.new(:penut, :filters)
16
- end
17
- end
18
-
19
- def test_initailize_filter_type
20
- assert @filter_column.filter.is_a?(Axlsx::Filters)
21
- assert_equal 1, @filter_column.filter.filter_items.size
22
- end
23
-
24
- def test_initialize_filter_type_filters_with_options
25
- assert_equal 200, @filter_column.filter.filter_items.first.val
26
- end
27
-
28
- def test_initialize_with_block
29
- filter_column = Axlsx::FilterColumn.new(0, :filters) do |filters|
30
- filters.filter_items = [700, 100, 5]
31
- end
32
- assert_equal 3, filter_column.filter.filter_items.size
33
- assert_equal 700, filter_column.filter.filter_items.first.val
34
- assert_equal 5, filter_column.filter.filter_items.last.val
35
- end
36
-
37
- def test_default_show_button
38
- assert_equal true, @filter_column.show_button
39
- end
40
-
41
- def test_default_hidden_button
42
- assert_equal false, @filter_column.hidden_button
43
- end
44
-
45
- def test_show_button
46
- assert_raise ArgumentError do
47
- @filter_column.show_button = :foo
48
- end
49
- assert_nothing_raised { @filter_column.show_button = false }
50
- end
51
-
52
- def test_hidden_button
53
- assert_raise ArgumentError do
54
- @filter_column.hidden_button = :hoge
55
- end
56
- assert_nothing_raised { @filter_column.hidden_button = true }
57
- end
58
-
59
- def test_col_id=
60
- assert_raise ArgumentError do
61
- @filter_column.col_id = :bar
62
- end
63
- assert_nothing_raised { @filter_column.col_id = 7 }
64
- end
65
-
66
- def test_to_xml_string
67
- doc = Nokogiri::XML(@filter_column.to_xml_string)
68
- assert doc.xpath("//filterColumn[@colId=#{@filter_column.col_id}]")
69
- assert doc.xpath("//filterColumn[@hiddenButton=#{@filter_column.hidden_button}]")
70
- assert doc.xpath("//filterColumn[@showButton=#{@filter_column.show_button}]")
71
-
72
-
73
-
74
- assert doc.xpath("//filterColumn/filters")
75
- end
76
- end
@@ -1,50 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestFilters < Test::Unit::TestCase
4
- def setup
5
- @filters = Axlsx::Filters.new(:filter_items => [1, 'a'],
6
- :date_group_items =>[ { :date_time_grouping => :year, :year => 2011, :month => 11, :day => 11, :hour => 0, :minute => 0, :second => 0 } ] ,
7
- :blank => true)
8
- end
9
-
10
- def test_blank
11
- assert_equal true, @filters.blank
12
- assert_raise(ArgumentError) { @filters.blank = :only_if_you_want_it }
13
- @filters.blank = true
14
- assert_equal true, @filters.blank
15
- end
16
-
17
- def test_calendar_type
18
- assert_raise(ArgumentError) { @filters.calendar_type = 'monkey calendar' }
19
- @filters.calendar_type = 'japan'
20
- assert_equal('japan', @filters.calendar_type)
21
- end
22
-
23
- def test_filters_items
24
- assert @filters.filter_items.is_a?(Array)
25
- assert_equal 2, @filters.filter_items.size
26
- end
27
-
28
- def test_date_group_items
29
- assert @filters.date_group_items.is_a?(Array)
30
- assert_equal 1, @filters.date_group_items.size
31
- end
32
-
33
- def test_apply_is_false_for_matching_values
34
- keeper = Object.new
35
- def keeper.value; 'a'; end
36
- assert_equal false, @filters.apply(keeper)
37
- end
38
-
39
- def test_apply_is_true_for_non_matching_values
40
- hidden = Object.new
41
- def hidden.value; 'b'; end
42
- assert_equal true, @filters.apply(hidden)
43
- end
44
-
45
- def test_to_xml_string
46
- doc = Nokogiri::XML(@filters.to_xml_string)
47
- assert_equal(1, doc.xpath('//filters[@blank=1]').size)
48
- end
49
- end
50
-
@@ -1,49 +0,0 @@
1
- require 'tc_helper.rb'
2
-
3
- class TestBreak < Test::Unit::TestCase
4
-
5
- def setup
6
- @break = Axlsx::Break.new(:id => 1, :min => 1, :max => 10, :man => true, :pt => false)
7
- end
8
-
9
- def test_id
10
- assert_equal(1, @break.id)
11
- assert_raises ArgumentError do
12
- Axlsx::Break.new(:hoge, {:id => -1})
13
- end
14
- end
15
-
16
- def test_min
17
- assert_equal(1, @break.min)
18
- assert_raises ArgumentError do
19
- Axlsx::Break.new(:hoge, :min => -1)
20
- end
21
- end
22
-
23
- def test_max
24
- assert_equal(10, @break.max)
25
- assert_raises ArgumentError do
26
- Axlsx::Break.new(:hoge, :max => -1)
27
- end
28
- end
29
-
30
-
31
- def test_man
32
- assert_equal(true, @break.man)
33
- assert_raises ArgumentError do
34
- Axlsx::Break.new(:man => -1)
35
- end
36
- end
37
-
38
- def test_pt
39
- assert_equal(false, @break.pt)
40
- assert_raises ArgumentError do
41
- Axlsx::Break.new(:pt => -1)
42
- end
43
- end
44
-
45
- def test_to_xml_string
46
- doc = Nokogiri::XML(@break.to_xml_string)
47
- assert_equal(doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size, 1)
48
- end
49
- end