thinreports 0.8.2 → 0.9.0

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