thinreports 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +39 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +59 -2
  5. data/Dockerfile +12 -0
  6. data/Gemfile +7 -4
  7. data/README.md +44 -22
  8. data/Rakefile +14 -31
  9. data/lib/thinreports.rb +16 -15
  10. data/lib/thinreports/config.rb +2 -24
  11. data/lib/thinreports/core/errors.rb +6 -17
  12. data/lib/thinreports/core/format/base.rb +62 -61
  13. data/lib/thinreports/core/shape.rb +10 -12
  14. data/lib/thinreports/core/shape/base.rb +3 -12
  15. data/lib/thinreports/core/shape/base/interface.rb +34 -32
  16. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  17. data/lib/thinreports/core/shape/basic.rb +12 -12
  18. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  19. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  20. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  21. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  22. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  23. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  24. data/lib/thinreports/core/shape/image_block.rb +9 -9
  25. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  26. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  27. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  28. data/lib/thinreports/core/shape/list.rb +13 -13
  29. data/lib/thinreports/core/shape/list/format.rb +83 -77
  30. data/lib/thinreports/core/shape/list/manager.rb +179 -176
  31. data/lib/thinreports/core/shape/list/page.rb +91 -93
  32. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  33. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  34. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  35. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  36. data/lib/thinreports/core/shape/manager.rb +4 -13
  37. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  38. data/lib/thinreports/core/shape/manager/internal.rb +87 -84
  39. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  40. data/lib/thinreports/core/shape/page_number.rb +9 -9
  41. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  42. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  43. data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
  44. data/lib/thinreports/core/shape/style.rb +5 -14
  45. data/lib/thinreports/core/shape/style/base.rb +121 -120
  46. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  47. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  48. data/lib/thinreports/core/shape/style/text.rb +113 -107
  49. data/lib/thinreports/core/shape/text.rb +9 -9
  50. data/lib/thinreports/core/shape/text/format.rb +10 -9
  51. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  52. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  53. data/lib/thinreports/core/shape/text_block.rb +10 -10
  54. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  55. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  56. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  57. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  58. data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
  59. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  60. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  61. data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
  62. data/lib/thinreports/core/utils.rb +7 -3
  63. data/lib/thinreports/generator/pdf.rb +24 -25
  64. data/lib/thinreports/generator/pdf/document.rb +109 -110
  65. data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
  66. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
  67. data/lib/thinreports/generator/pdf/document/font.rb +67 -58
  68. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  69. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
  70. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
  71. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  72. data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
  73. data/lib/thinreports/generator/pdf/document/page.rb +60 -64
  74. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  75. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  76. data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
  77. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  78. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  79. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  80. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
  81. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
  82. data/lib/thinreports/layout.rb +5 -7
  83. data/lib/thinreports/layout/base.rb +5 -9
  84. data/lib/thinreports/layout/format.rb +17 -13
  85. data/lib/thinreports/layout/legacy_schema.rb +17 -13
  86. data/lib/thinreports/layout/version.rb +22 -25
  87. data/lib/thinreports/report.rb +4 -6
  88. data/lib/thinreports/report/base.rb +24 -51
  89. data/lib/thinreports/report/internal.rb +13 -15
  90. data/lib/thinreports/report/page.rb +5 -11
  91. data/lib/thinreports/version.rb +2 -2
  92. data/thinreports.gemspec +10 -19
  93. metadata +13 -288
  94. data/.travis.yml +0 -19
  95. data/examples/character_spacing/character_spacing.rb +0 -8
  96. data/examples/character_spacing/character_spacing.tlf +0 -293
  97. data/examples/dynamic_image/dynamic_image.rb +0 -31
  98. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  99. data/examples/dynamic_image/img200x100.png +0 -0
  100. data/examples/dynamic_image/img50x50.png +0 -0
  101. data/examples/dynamic_style/dynamic_style.rb +0 -150
  102. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  103. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  104. data/examples/dynamic_style/image.png +0 -0
  105. data/examples/eudc/eudc.rb +0 -20
  106. data/examples/eudc/eudc.tlf +0 -180
  107. data/examples/eudc/eudc.ttf +0 -0
  108. data/examples/helper.rb +0 -50
  109. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  110. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  111. data/examples/list_events/list_events.rb +0 -32
  112. data/examples/list_events/list_events.tlf +0 -361
  113. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  114. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  115. data/examples/list_page_number/list_page_number.rb +0 -17
  116. data/examples/list_page_number/list_page_number.tlf +0 -254
  117. data/examples/page_number/page_number.rb +0 -33
  118. data/examples/page_number/page_number.tlf +0 -215
  119. data/examples/palleted_png/palleted_png.png +0 -0
  120. data/examples/palleted_png/palleted_png.rb +0 -11
  121. data/examples/palleted_png/palleted_png.tlf +0 -47
  122. data/examples/password_setting/password_setting.rb +0 -10
  123. data/examples/password_setting/password_setting.tlf +0 -45
  124. data/examples/report_callbacks/report_callbacks.rb +0 -14
  125. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  126. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  127. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  128. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  129. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  130. data/examples/tblock_styles/font_size.tlf +0 -383
  131. data/examples/tblock_styles/tblock_styles.rb +0 -43
  132. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  133. data/examples/text_align/text_align.rb +0 -8
  134. data/examples/text_align/text_align.tlf +0 -241
  135. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  136. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  137. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  138. data/examples/word_wrap/word_wrap.rb +0 -26
  139. data/examples/word_wrap/word_wrap.tlf +0 -297
  140. data/lib/thinreports/generator.rb +0 -29
  141. data/lib/thinreports/generator/base.rb +0 -40
  142. data/lib/thinreports/generator/configuration.rb +0 -31
  143. data/lib/thinreports/report/events.rb +0 -32
  144. data/test/data/font.ttf +0 -0
  145. data/test/data/image_normal.jpg +0 -0
  146. data/test/data/image_normal.png +0 -0
  147. data/test/data/image_normal_jpg_noext +0 -0
  148. data/test/data/image_normal_png_noext +0 -0
  149. data/test/data/image_pallete_based.png +0 -0
  150. data/test/data/legacy_layout/all-items.tlf +0 -1
  151. data/test/schema_helper.rb +0 -121
  152. data/test/test_helper.rb +0 -42
  153. data/test/tmp/.gitkeep +0 -0
  154. data/test/unit/core/format/test_base.rb +0 -152
  155. data/test/unit/core/shape/base/test_internal.rb +0 -87
  156. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  157. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  158. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  159. data/test/unit/core/shape/basic/test_format.rb +0 -37
  160. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  161. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  162. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  163. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  164. data/test/unit/core/shape/list/test_format.rb +0 -111
  165. data/test/unit/core/shape/list/test_manager.rb +0 -67
  166. data/test/unit/core/shape/list/test_page.rb +0 -82
  167. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  168. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  169. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  170. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  171. data/test/unit/core/shape/manager/test_format.rb +0 -38
  172. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  173. data/test/unit/core/shape/manager/test_target.rb +0 -140
  174. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  175. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  176. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  177. data/test/unit/core/shape/styles/test_base.rb +0 -191
  178. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  179. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  180. data/test/unit/core/shape/styles/test_text.rb +0 -97
  181. data/test/unit/core/shape/text/test_format.rb +0 -44
  182. data/test/unit/core/shape/text/test_internal.rb +0 -20
  183. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  184. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  185. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  186. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  187. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  188. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  189. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  190. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  191. data/test/unit/core/test_shape.rb +0 -52
  192. data/test/unit/core/test_utils.rb +0 -68
  193. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  194. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
  195. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
  196. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  197. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  198. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  199. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  200. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  201. data/test/unit/generator/pdf/test_document.rb +0 -20
  202. data/test/unit/generator/test_base.rb +0 -40
  203. data/test/unit/generator/test_configuration.rb +0 -21
  204. data/test/unit/generator/test_pdf.rb +0 -24
  205. data/test/unit/layout/test_base.rb +0 -41
  206. data/test/unit/layout/test_format.rb +0 -100
  207. data/test/unit/layout/test_legacy_schema.rb +0 -574
  208. data/test/unit/layout/test_version.rb +0 -95
  209. data/test/unit/report/test_base.rb +0 -262
  210. data/test/unit/report/test_internal.rb +0 -206
  211. data/test/unit/test_config.rb +0 -51
  212. data/test/unit/test_layout.rb +0 -12
  213. data/test/unit/test_report.rb +0 -18
@@ -1,95 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestVersion < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Version = Thinreports::Layout::Version
10
-
11
- def test_comparable_version_should_add_99_when_the_given_version_is_not_PRE
12
- assert_equal Version.comparable_version('0.7.0'), '0.7.0.99'
13
- end
14
-
15
- def test_comparable_version_should_map_pre_to_1_when_the_given_version_is_PRE
16
- assert_equal Version.comparable_version('0.6.0.pre'), '0.6.0.1'
17
- end
18
-
19
- def test_comparable_version_should_map_pre2_to_2_when_the_given_version_is_PRE2
20
- assert_equal Version.comparable_version('0.6.0.pre2'), '0.6.0.2'
21
- end
22
-
23
- def test_compare_with_equal_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
24
- assert Version.compare('0.7.0', '== 0.7.0')
25
- end
26
-
27
- def test_compare_with_equal_rule_should_return_false_when_the_given_version_is_not_equal_to_the_version_of_rule
28
- refute Version.compare('0.6.0.pre3', '== 0.6.0.pre2')
29
- end
30
-
31
- def test_compare_with_larger_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
32
- assert Version.compare('0.7.0', '> 0.6.0.pre3')
33
- end
34
-
35
- def test_compare_with_larger_rule_should_return_false_when_the_given_version_is_not_larger_than_the_version_of_rule
36
- refute Version.compare('0.7.0', '> 0.7.0')
37
- end
38
-
39
- def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
40
- assert Version.compare('0.7.0', '>= 0.7.0')
41
- end
42
-
43
- def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
44
- assert Version.compare('0.7.0', '>= 0.6.0.pre3')
45
- end
46
-
47
- def test_compare_with_one_or_more_rule_should_return_false_when_the_give_version_is_not_more_than_the_version_of_rule
48
- refute Version.compare('0.6.0.pre3', '>= 0.7.0')
49
- end
50
-
51
- def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
52
- assert Version.compare('0.7.0', '<= 0.7.0')
53
- end
54
-
55
- def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_smaller_than_the_version_of_rule
56
- assert Version.compare('0.7.0', '<= 0.7.1')
57
- end
58
-
59
- def test_compare_with_one_or_less_rule_should_return_false_when_the_given_version_is_not_less_than_the_version_of_rule
60
- refute Version.compare('0.7.0', '<= 0.6.0.pre3')
61
- end
62
-
63
- def test_inspect_required_rules_should_properly_return_an_inspection_of_rule_when_one_rule_is_given
64
- required_rules('== 0.6.0') do
65
- assert_equal Version.inspect_required_rules, '(== 0.6.0)'
66
- end
67
- end
68
-
69
- def test_inspect_required_rules_should_properly_return_an_inspection_of_rules_when_multiple_rules_are_given
70
- required_rules('>= 0.6.0.pre3', '< 0.8.0') do
71
- assert_equal Version.inspect_required_rules, '(>= 0.6.0.pre3 and < 0.8.0)'
72
- end
73
- end
74
-
75
- def test_compatible_asker_should_return_true_when_the_given_version_matches_REEQUIRED_RULES
76
- required_rules('>= 0.6.0.pre3', '< 0.8.0') do
77
- assert Version.compatible?('0.7.0')
78
- end
79
- end
80
-
81
- def test_compatible_asker_should_return_false_when_the_given_version_does_not_matches_REQUIRED_RULES
82
- required_rules('>= 0.6.0.pre3', '< 0.8.0') do
83
- refute Version.compatible?('0.8.0')
84
- end
85
- end
86
-
87
- def required_rules(*rules, &block)
88
- original_required_rules = Version::REQUIRED_RULES.dup
89
-
90
- Version::REQUIRED_RULES.replace(rules)
91
- block.call
92
- ensure
93
- Version::REQUIRED_RULES.replace(original_required_rules)
94
- end
95
- end
@@ -1,262 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Report::TestBase < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Report = Thinreports::Report
9
-
10
- def setup
11
- @report = Report::Base.new
12
- @layout_file = layout_file
13
- end
14
-
15
- def test_on_page_create_callback
16
- report = Report::Base.new layout: @layout_file.path
17
-
18
- counter = 0
19
- callback = -> page {
20
- assert_instance_of Report::Page, page
21
- counter += 1
22
- }
23
-
24
- report.on_page_create(&callback)
25
-
26
- 2.times { report.start_new_page }
27
- assert_equal counter, 2
28
- end
29
-
30
- def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
31
- report = Report::Base.new layout: @layout_file.path
32
- assert_equal report.default_layout.filename, @layout_file.path
33
- end
34
-
35
- def test_initialize_should_initialize_new_Report_without_default_layout
36
- assert_nil @report.default_layout
37
- end
38
-
39
- def test_use_layout_should_register_default_layout_when_default_property_is_omitted
40
- @report.use_layout(@layout_file.path)
41
-
42
- assert_equal @report.default_layout.filename, @layout_file.path
43
- end
44
-
45
- def test_use_layout_should_register_default_layout_when_default_property_is_true
46
- @report.use_layout(@layout_file.path, default: true)
47
-
48
- assert_equal @report.default_layout.filename, @layout_file.path
49
- end
50
-
51
- def test_start_new_page_should_properly_create_a_new_Page_and_return
52
- @report.use_layout(@layout_file.path)
53
-
54
- assert_instance_of Thinreports::Report::Page, @report.start_new_page
55
- end
56
-
57
- def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
58
- assert_raises Thinreports::Errors::NoRegisteredLayoutFound do
59
- @report.start_new_page(layout: :unknown)
60
- end
61
- end
62
-
63
- def test_start_new_page_should_create_a_new_page_using_a_default_layout
64
- @report.use_layout(@layout_file.path, default: true)
65
-
66
- assert_equal @report.start_new_page.layout.filename, @layout_file.path
67
- end
68
-
69
- def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
70
- @report.use_layout(@layout_file.path, id: :foo)
71
-
72
- assert_equal @report.start_new_page(layout: :foo).layout.filename,
73
- @layout_file.path
74
- end
75
-
76
- def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
77
- new_page = @report.start_new_page(layout: @layout_file.path)
78
- assert_equal new_page.layout.filename, @layout_file.path
79
- end
80
-
81
- def test_start_new_page_with_count_option
82
- @report.use_layout @layout_file.path, default: true
83
-
84
- new_page = @report.start_new_page count: false
85
- assert_nil new_page.no
86
- assert_equal @report.page_count, 0
87
-
88
- new_page = @report.start_new_page count: true
89
- assert_equal new_page.no, 1
90
- assert_equal @report.page_count, 1
91
-
92
- new_page = @report.start_new_page
93
- assert_equal new_page.no, 2
94
- assert_equal @report.page_count, 2
95
- end
96
-
97
- def test_add_blank_page_should_properly_create_a_new_blank_page
98
- @report.use_layout(@layout_file.path)
99
-
100
- assert_instance_of Thinreports::Report::BlankPage, @report.add_blank_page
101
- end
102
-
103
- def test_layout_should_return_the_default_layout_with_no_arguments
104
- @report.use_layout(@layout_file.path, default: true)
105
-
106
- assert_equal @report.layout.filename, @layout_file.path
107
- end
108
-
109
- def test_layout_should_raise_when_the_specified_layout_is_not_found
110
- assert_raises Thinreports::Errors::UnknownLayoutId do
111
- @report.layout(:unknown_layout_id)
112
- end
113
- end
114
-
115
- def test_layout_should_return_the_layout_with_specified_id
116
- @report.use_layout(@layout_file.path, id: :foo)
117
-
118
- assert_equal @report.layout(:foo).filename, @layout_file.path
119
- end
120
-
121
- def test_generate_with_filename
122
- report = Report::Base.new layout: @layout_file.path
123
-
124
- report.generate :pdf, filename: temp_path.join('result1.pdf')
125
- report.generate filename: temp_path.join('result2.pdf')
126
-
127
- assert File.exist?(temp_path.join('result1.pdf'))
128
- assert File.exist?(temp_path.join('result2.pdf'))
129
-
130
- assert_equal File.read(temp_path.join('result1.pdf')),
131
- File.read(temp_path.join('result2.pdf'))
132
- end
133
-
134
- def test_page_should_return_the_current_page
135
- @report.use_layout(@layout_file.path)
136
- @report.start_new_page
137
-
138
- assert_instance_of Thinreports::Report::Page, @report.page
139
- end
140
-
141
- def test_page_count_should_return_total_page_count
142
- @report.use_layout(@layout_file.path)
143
- 2.times { @report.start_new_page }
144
-
145
- assert_equal @report.page_count, 2
146
- end
147
-
148
- def test_finalize_should_finalize_report
149
- @report.finalize
150
- assert_equal @report.finalized?, true
151
- end
152
-
153
- def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
154
- assert_equal @report.finalized?, false
155
- end
156
-
157
- def test_finalized_asker_should_return_true_when_report_is_already_finalized
158
- @report.finalize
159
- assert_equal @report.finalized?, true
160
- end
161
-
162
- def test_list_should_create_new_page_when_page_is_not_created
163
- @report.use_layout(@layout_file.path)
164
- @report.list
165
-
166
- refute_nil @report.page
167
- end
168
-
169
- def test_list_should_create_new_page_when_page_is_finalized
170
- @report.tap do |r|
171
- r.use_layout(@layout_file.path)
172
- r.start_new_page
173
- r.page.finalize
174
- end
175
- @report.list
176
-
177
- assert_equal @report.page.finalized?, false
178
- end
179
-
180
- def test_list_should_properly_return_shape_with_the_specified_id
181
- @report.use_layout(@layout_file.path)
182
-
183
- assert_equal @report.list.id, 'default'
184
- end
185
-
186
- def test_start_page_number
187
- assert_equal @report.start_page_number, 1
188
- @report.start_page_number_from 10
189
- assert_equal @report.start_page_number, 10
190
- end
191
-
192
- def test_Base_create_should_finalize_report
193
- report = Report::Base.create do |r|
194
- assert_instance_of Report::Base, r
195
- end
196
- assert_equal report.finalized?, true
197
- end
198
-
199
- def test_Base_create_should_raise_when_no_block_given
200
- assert_raises ArgumentError do
201
- Report::Base.create
202
- end
203
- end
204
-
205
- def test_Base_generate_with_filename
206
- Report::Base.generate(:pdf, report: { layout: @layout_file.path },
207
- generator: { filename: temp_path.join('result1.pdf') }) {}
208
- Report::Base.generate(report: { layout: @layout_file.path },
209
- generator: { filename: temp_path.join('result2.pdf') }) {}
210
-
211
- assert_equal temp_path.join('result1.pdf').read,
212
- temp_path.join('result2.pdf').read
213
- end
214
-
215
- def test_Base_generate_should_raise_when_no_block_given
216
- assert_raises ArgumentError do
217
- Report::Base.generate(:pdf)
218
- end
219
- end
220
-
221
- def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
222
- report, _generator = Report::Base.send(:extract_options!, [{report: {layout: 'hoge.tlf'}}])
223
- assert_equal report[:layout], 'hoge.tlf'
224
- end
225
-
226
- def test_Base_extract_options_should_operate_an_argument_destructively
227
- args = [:pdf, 'output.pdf', {report: {layout: 'foo.tlf'}}]
228
- Report::Base.send(:extract_options!, args)
229
- assert_equal args, [:pdf, 'output.pdf']
230
- end
231
-
232
- def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
233
- report, _generator = Report::Base.send(:extract_options!, [{layout: 'hoge.tlf'}])
234
- assert_equal report[:layout], 'hoge.tlf'
235
- end
236
-
237
- def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
238
- report, _generator = Report::Base.send(:extract_options!,
239
- [{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf'}])
240
- assert_equal report[:layout], 'hoge.tlf'
241
- end
242
-
243
- def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
244
- _report, generator = Report::Base.send(:extract_options!,
245
- [{generator: {option: 'value'}}])
246
- assert_equal generator[:option], 'value'
247
- end
248
-
249
- def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
250
- _report, generator = Report::Base.send(:extract_options!,
251
- [{generator: {option: 'value1'}, option: 'value2'}])
252
- assert_equal generator[:option], 'value2'
253
- end
254
-
255
- def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
256
- _report, generator = Report::Base.send(:extract_options!,
257
- [{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf',
258
- generator_opt1: 'value1', generator_opt2: 'value2'}])
259
- assert_equal generator.values_at(:generator_opt1, :generator_opt2),
260
- ['value1', 'value2']
261
- end
262
- end
@@ -1,206 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Report::TestInternal < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Report = Thinreports::Report
9
-
10
- def setup
11
- @layout_file = layout_file
12
- end
13
-
14
- def report
15
- Report::Base.new
16
- end
17
-
18
- def test_layout_specified_in_new_method_should_be_defined_as_default_layout
19
- internal = Report::Internal.new(report, layout: @layout_file.path)
20
- assert_equal internal.default_layout.filename, @layout_file.path
21
- end
22
-
23
- def test_register_layout_should_be_set_as_default_layout_when_options_are_omitted
24
- internal = Report::Internal.new(report, {})
25
- internal.register_layout(@layout_file.path)
26
-
27
- assert_equal internal.default_layout.filename, @layout_file.path
28
- end
29
-
30
- def test_register_layout_should_be_set_as_default_layout_when_default_option_is_true
31
- internal = Report::Internal.new(report, {})
32
- internal.register_layout(@layout_file.path, default: true)
33
-
34
- assert_equal internal.default_layout.filename, @layout_file.path
35
- end
36
-
37
- def test_register_layout_should_be_able_to_change_the_default_layout
38
- internal = Report::Internal.new(report, layout: @layout_file.path)
39
- internal.register_layout(@layout_file.path, default: true)
40
-
41
- assert_equal internal.default_layout.filename, @layout_file.path
42
- end
43
-
44
- def test_register_layout_should_be_set_as_with_id_when_id_option_is_set
45
- internal = Report::Internal.new(report, {})
46
- internal.register_layout(@layout_file.path, id: :foo)
47
-
48
- assert_equal internal.layout_registry[:foo].filename, @layout_file.path
49
- end
50
-
51
- def test_register_layout_should_raise_an_error_when_id_is_already_registered
52
- internal = Report::Internal.new(report, {})
53
- internal.register_layout(@layout_file.path, id: :foo)
54
-
55
- assert_raises ArgumentError do
56
- internal.register_layout(@layout_file.path, id: :foo)
57
- end
58
- end
59
-
60
- def test_add_page_should_finalize_the_current_page
61
- layout = Thinreports::Layout.new(@layout_file.path)
62
-
63
- internal = Report::Internal.new(report, layout: @layout_file.path)
64
- page = internal.add_page(Thinreports::Report::Page.new(report, layout))
65
- internal.add_page(Thinreports::Report::Page.new(report, layout))
66
-
67
- assert_equal page.finalized?, true
68
- end
69
-
70
- def test_add_page_should_return_the_current_page
71
- layout = Thinreports::Layout.new(@layout_file.path)
72
- new_page = Thinreports::Report::Page.new(report, layout)
73
-
74
- internal = Report::Internal.new(report, layout: @layout_file.path)
75
-
76
- assert_same new_page, internal.add_page(new_page)
77
- end
78
-
79
- def test_add_page_should_add_the_initialized_page
80
- layout = Thinreports::Layout.new(@layout_file.path)
81
- new_page = Thinreports::Report::Page.new(report, layout)
82
-
83
- internal = Report::Internal.new(report, layout: @layout_file.path)
84
- internal.add_page(new_page)
85
-
86
- assert_same new_page, internal.pages.last
87
- end
88
-
89
- def test_add_page_should_count_up_the_total_page_count
90
- layout = Thinreports::Layout.new(@layout_file.path)
91
-
92
- internal = Report::Internal.new(report, layout: @layout_file.path)
93
- internal.add_page(Thinreports::Report::Page.new(report, layout))
94
-
95
- assert_equal internal.page_count, 1
96
- end
97
-
98
- def test_add_page_should_switch_to_a_reference_to_the_current_page
99
- layout = Thinreports::Layout.new(@layout_file.path)
100
- new_pages = (1..2).inject([]) do |pages|
101
- pages << Thinreports::Report::Page.new(report, layout)
102
- end
103
-
104
- internal = Report::Internal.new(report, layout: @layout_file.path)
105
- internal.add_page(new_pages[0])
106
-
107
- assert_same internal.page, new_pages[0]
108
-
109
- internal.add_page(new_pages[1])
110
-
111
- assert_same internal.page, new_pages[1]
112
- end
113
-
114
- def test_add_blank_page_should_not_count_up_the_total_page_count_when_count_is_disabled
115
- internal = Report::Internal.new(report, layout: @layout_file.path)
116
- internal.add_page(Thinreports::Report::BlankPage.new(false))
117
-
118
- assert_equal internal.page_count, 0
119
- end
120
-
121
- def test_add_blank_page_should_count_up_the_total_page_count_when_count_is_enabled
122
- internal = Report::Internal.new(report, layout: @layout_file.path)
123
- internal.add_page(Thinreports::Report::BlankPage.new)
124
-
125
- assert_equal internal.page_count, 1
126
- end
127
-
128
- def test_finalize_should_finalize_the_report
129
- internal = Report::Internal.new(report, layout: @layout_file.path)
130
- internal.finalize
131
-
132
- assert internal.finalized?
133
- end
134
-
135
- def test_finalize_should_not_work_when_report_is_already_finalized
136
- internal = Report::Internal.new(report, layout: @layout_file.path)
137
- internal.finalize
138
-
139
- # #finalize_current_page must never be called
140
- internal.expects(:finalize_current_page).never
141
- internal.finalize
142
- end
143
-
144
- def test_finalized_should_return_true_when_report_is_already_finalized
145
- internal = Report::Internal.new(report, layout: @layout_file.path)
146
- internal.finalize
147
-
148
- assert internal.finalized?
149
- end
150
-
151
- def test_load_layout_with_String
152
- internal = Report::Internal.new(report, layout: @layout_file.path)
153
-
154
- assert_equal internal.load_layout(@layout_file.path).filename,
155
- @layout_file.path
156
- end
157
-
158
- def test_load_layout_with_id
159
- internal = Report::Internal.new(report, {})
160
- internal.register_layout(@layout_file.path, id: :sample)
161
-
162
- assert_equal internal.load_layout(:sample).filename,
163
- @layout_file.path
164
- end
165
-
166
- def test_load_layout_with_unknown_id
167
- internal = Report::Internal.new(report, {})
168
- assert_nil internal.load_layout(:unknown)
169
- end
170
-
171
- def test_load_layout_should_set_default_layout_when_default_layout_is_nil
172
- internal = Report::Internal.new(report, {})
173
- internal.load_layout(@layout_file.path)
174
-
175
- assert_equal internal.default_layout.filename,
176
- @layout_file.path
177
- end
178
-
179
- def test_load_layout_should_raise_error_when_invalid_value_set
180
- internal = Report::Internal.new(report, {})
181
-
182
- assert_raises Thinreports::Errors::LayoutFileNotFound do
183
- internal.load_layout('/path/to/unkown.tlf')
184
- end
185
- end
186
-
187
- def test_copy_page_should_finalize_current_page
188
- layout = Thinreports::Layout.new(@layout_file.path)
189
-
190
- internal = Report::Internal.new(report, layout: @layout_file.path)
191
- internal.add_page(page = Thinreports::Report::Page.new(report, layout))
192
- internal.copy_page
193
-
194
- assert page.finalized?
195
- end
196
-
197
- def test_copy_page_should_add_the_copied_page
198
- layout = Thinreports::Layout.new(@layout_file.path)
199
-
200
- internal = Report::Internal.new(report, layout: @layout_file.path)
201
- internal.add_page(Thinreports::Report::Page.new(report, layout))
202
- internal.copy_page
203
-
204
- assert_equal internal.page_count, 2
205
- end
206
- end