thinreports 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +41 -0
  3. data/.travis.yml +4 -6
  4. data/CHANGELOG.md +21 -2
  5. data/Gemfile +2 -4
  6. data/README.md +4 -5
  7. data/Rakefile +7 -8
  8. data/examples/character_spacing/character_spacing.rb +1 -1
  9. data/examples/dynamic_image/dynamic_image.rb +3 -3
  10. data/examples/dynamic_style/dynamic_style.rb +1 -1
  11. data/examples/eudc/eudc.rb +1 -1
  12. data/examples/helper.rb +2 -2
  13. data/examples/hidden_shapes/hidden_shapes.rb +1 -1
  14. data/examples/list_events/list_events.rb +1 -1
  15. data/examples/list_manual_generation/list_manual_generation.rb +1 -1
  16. data/examples/list_page_number/list_page_number.rb +1 -1
  17. data/examples/page_number/page_number.rb +1 -1
  18. data/examples/palleted_png/palleted_png.rb +1 -3
  19. data/examples/password_setting/password_setting.rb +1 -1
  20. data/examples/report_callbacks/report_callbacks.rb +1 -1
  21. data/examples/single_line_tblock/single_line_tblock.rb +1 -1
  22. data/examples/tblock_overflow/tblock_overflow.rb +1 -1
  23. data/examples/tblock_styles/tblock_styles.rb +1 -1
  24. data/examples/text_align/text_align.rb +1 -1
  25. data/examples/typeB_page_size/typeB_page_size.rb +1 -1
  26. data/examples/word_wrap/word_wrap.rb +1 -1
  27. data/lib/thinreports.rb +16 -15
  28. data/lib/thinreports/config.rb +2 -24
  29. data/lib/thinreports/core/errors.rb +6 -17
  30. data/lib/thinreports/core/format/base.rb +62 -61
  31. data/lib/thinreports/core/shape.rb +13 -14
  32. data/lib/thinreports/core/shape/base.rb +3 -12
  33. data/lib/thinreports/core/shape/base/interface.rb +35 -32
  34. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  35. data/lib/thinreports/core/shape/basic.rb +12 -12
  36. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  37. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  38. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  39. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  40. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  41. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  42. data/lib/thinreports/core/shape/image_block.rb +9 -9
  43. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  44. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  45. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  46. data/lib/thinreports/core/shape/list.rb +13 -13
  47. data/lib/thinreports/core/shape/list/format.rb +83 -77
  48. data/lib/thinreports/core/shape/list/manager.rb +182 -176
  49. data/lib/thinreports/core/shape/list/page.rb +94 -93
  50. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  51. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  52. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  53. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  54. data/lib/thinreports/core/shape/manager.rb +4 -13
  55. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  56. data/lib/thinreports/core/shape/manager/internal.rb +88 -84
  57. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  58. data/lib/thinreports/core/shape/page_number.rb +9 -9
  59. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  60. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  61. data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
  62. data/lib/thinreports/core/shape/style.rb +5 -14
  63. data/lib/thinreports/core/shape/style/base.rb +121 -120
  64. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  65. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  66. data/lib/thinreports/core/shape/style/text.rb +113 -107
  67. data/lib/thinreports/core/shape/text.rb +9 -9
  68. data/lib/thinreports/core/shape/text/format.rb +10 -9
  69. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  70. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  71. data/lib/thinreports/core/shape/text_block.rb +10 -10
  72. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  73. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  74. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  75. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  76. data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
  77. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  78. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  79. data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
  80. data/lib/thinreports/core/utils.rb +4 -3
  81. data/lib/thinreports/generator/pdf.rb +24 -25
  82. data/lib/thinreports/generator/pdf/document.rb +109 -110
  83. data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
  84. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
  85. data/lib/thinreports/generator/pdf/document/font.rb +62 -59
  86. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  87. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
  88. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
  89. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  90. data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
  91. data/lib/thinreports/generator/pdf/document/page.rb +63 -64
  92. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  93. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  94. data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
  95. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  96. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  97. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  98. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
  99. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
  100. data/lib/thinreports/layout.rb +5 -7
  101. data/lib/thinreports/layout/base.rb +5 -7
  102. data/lib/thinreports/layout/format.rb +18 -13
  103. data/lib/thinreports/layout/legacy_schema.rb +18 -10
  104. data/lib/thinreports/layout/version.rb +22 -25
  105. data/lib/thinreports/report.rb +4 -6
  106. data/lib/thinreports/report/base.rb +24 -51
  107. data/lib/thinreports/report/internal.rb +9 -11
  108. data/lib/thinreports/report/page.rb +5 -6
  109. data/lib/thinreports/version.rb +2 -2
  110. data/test/schema_helper.rb +4 -3
  111. data/test/test_helper.rb +9 -3
  112. data/test/unit/core/format/test_base.rb +1 -1
  113. data/test/unit/core/shape/base/test_internal.rb +1 -1
  114. data/test/unit/core/shape/basic/test_block_format.rb +1 -1
  115. data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
  116. data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
  117. data/test/unit/core/shape/basic/test_format.rb +1 -1
  118. data/test/unit/core/shape/basic/test_interface.rb +1 -1
  119. data/test/unit/core/shape/basic/test_internal.rb +1 -1
  120. data/test/unit/core/shape/image_block/test_interface.rb +1 -1
  121. data/test/unit/core/shape/image_block/test_internal.rb +1 -1
  122. data/test/unit/core/shape/list/test_format.rb +1 -1
  123. data/test/unit/core/shape/list/test_manager.rb +4 -4
  124. data/test/unit/core/shape/list/test_page.rb +1 -1
  125. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  126. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  127. data/test/unit/core/shape/list/test_section_interface.rb +2 -2
  128. data/test/unit/core/shape/list/test_section_internal.rb +1 -1
  129. data/test/unit/core/shape/manager/test_format.rb +2 -2
  130. data/test/unit/core/shape/manager/test_internal.rb +3 -3
  131. data/test/unit/core/shape/manager/test_target.rb +1 -1
  132. data/test/unit/core/shape/page_number/test_format.rb +1 -1
  133. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  134. data/test/unit/core/shape/page_number/test_internal.rb +1 -1
  135. data/test/unit/core/shape/styles/test_base.rb +1 -1
  136. data/test/unit/core/shape/styles/test_basic.rb +1 -1
  137. data/test/unit/core/shape/styles/test_graphic.rb +1 -1
  138. data/test/unit/core/shape/styles/test_text.rb +1 -1
  139. data/test/unit/core/shape/text/test_format.rb +1 -1
  140. data/test/unit/core/shape/text/test_internal.rb +1 -1
  141. data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
  142. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
  143. data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
  144. data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
  145. data/test/unit/core/shape/text_block/test_format.rb +1 -1
  146. data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
  147. data/test/unit/core/shape/text_block/test_interface.rb +1 -1
  148. data/test/unit/core/shape/text_block/test_internal.rb +3 -3
  149. data/test/unit/core/test_shape.rb +1 -1
  150. data/test/unit/core/test_utils.rb +2 -2
  151. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
  152. data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
  153. data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
  154. data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
  155. data/test/unit/generator/pdf/document/test_font.rb +2 -2
  156. data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
  157. data/test/unit/generator/pdf/document/test_page.rb +7 -7
  158. data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
  159. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
  160. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
  161. data/test/unit/generator/pdf/test_document.rb +8 -6
  162. data/test/unit/generator/test_pdf.rb +12 -10
  163. data/test/unit/layout/test_base.rb +1 -1
  164. data/test/unit/layout/test_format.rb +2 -2
  165. data/test/unit/layout/test_legacy_schema.rb +4 -4
  166. data/test/unit/layout/test_version.rb +11 -80
  167. data/test/unit/report/test_base.rb +45 -59
  168. data/test/unit/report/test_internal.rb +1 -1
  169. data/test/unit/test_config.rb +1 -16
  170. data/test/unit/test_layout.rb +1 -1
  171. data/test/unit/test_report.rb +1 -1
  172. data/thinreports.gemspec +11 -14
  173. metadata +42 -103
  174. data/lib/thinreports/generator.rb +0 -29
  175. data/lib/thinreports/generator/base.rb +0 -40
  176. data/lib/thinreports/generator/configuration.rb +0 -31
  177. data/lib/thinreports/report/events.rb +0 -32
  178. data/test/unit/generator/test_base.rb +0 -40
  179. data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -26,7 +26,7 @@ class Thinreports::Generator::PDF::TestFont < Minitest::Test
26
26
  pdf.font_families[original_font]
27
27
  end
28
28
 
29
- assert_equal Font::DEFAULT_FALLBACK_FONTS, pdf.fallback_fonts[-2..-1]
29
+ assert_equal Font::DEFAULT_FALLBACK_FONTS, %w[IPAMincho]
30
30
  end
31
31
 
32
32
  def test_setup_fonts_with_custom_fallback_fonts
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -9,20 +9,20 @@ class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
9
9
  @pdf = Thinreports::Generator::PDF::Document.new
10
10
  end
11
11
 
12
- def test_page_geometry
13
- page_geometry = ::PDF::Core::PageGeometry::SIZES
14
- assert_equal page_geometry['B4_JIS'], [728.5, 1031.8]
15
- assert_equal page_geometry['B5_JIS'], [515.9, 728.5]
12
+ def test_JIS_page_size
13
+ sizes = Thinreports::Generator::PDF::Document::JIS_SIZES
14
+ assert_equal sizes['B4'], [728.5, 1031.8]
15
+ assert_equal sizes['B5'], [515.9, 728.5]
16
16
  end
17
17
 
18
- def test_B4_paper_size_should_be_converted_to_B4_JIS
18
+ def test_B4_paper_size_should_returns_size_as_B4_JIS
19
19
  create_pdf
20
20
 
21
21
  format = Thinreports::Layout::Format.build(layout_file.path)
22
22
  format.stubs(page_paper_type: 'B4')
23
23
 
24
24
  @pdf.start_new_page(format)
25
- assert_equal @pdf.internal.page.size, 'B4_JIS'
25
+ assert_equal @pdf.internal.page.size, [728.5, 1031.8]
26
26
  end
27
27
 
28
28
  def test_B4_ISO_paper_size_should_be_converted_to_B4
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PrawnExt::TestCalcImageDimensions < Minitest::Test
6
+ class Klass
7
+ prepend Thinreports::Generator::PrawnExt::CalcImageDimensions
8
+
9
+ def calc_image_dimensions(options)
10
+ options
11
+ end
12
+ end
13
+
14
+ def setup
15
+ @klass = Klass.new
16
+ end
17
+
18
+ def test_calc_image_dimensions
19
+ res_options = @klass.calc_image_dimensions(
20
+ auto_fit: [100, 200],
21
+ width: 101,
22
+ height: 199
23
+ )
24
+ assert_equal [100, 200], res_options[:fit]
25
+ refute_includes res_options.keys, :auto_fit
26
+
27
+ res_options = @klass.calc_image_dimensions(
28
+ auto_fit: [100, 200],
29
+ width: 99,
30
+ height: 201
31
+ )
32
+ assert_equal [100, 200], res_options[:fit]
33
+
34
+ res_options = @klass.calc_image_dimensions(
35
+ auto_fit: [100, 200],
36
+ width: 99,
37
+ height: 199
38
+ )
39
+ refute_includes res_options.keys, :fit
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Generator::PrawnExt::TestWidthOf < Minitest::Test
6
+ def setup
7
+ @pdf = Prawn::Document.new
8
+ end
9
+
10
+ def test_width_of
11
+ text_width = @pdf.width_of('abcd')
12
+
13
+ @pdf.character_spacing(1) do
14
+ expected_character_space_width = 1 * 3
15
+ assert_equal text_width + expected_character_space_width, @pdf.width_of('abcd')
16
+ end
17
+
18
+ @pdf.character_spacing(1) do
19
+ assert_equal 0, @pdf.width_of('')
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -8,13 +8,15 @@ class Thinreports::Generator::PDF::TestDocument < Minitest::Test
8
8
  # Alias
9
9
  Document = Thinreports::Generator::PDF::Document
10
10
 
11
- def test_new_without_page_creation
11
+ def test_new
12
12
  pdf = Document.new
13
13
  assert_equal pdf.internal.page_count, 0
14
- end
15
-
16
- def test_new_with_zero_margin_canvas
17
- pdf = Document.new
18
14
  assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
15
+
16
+ pdf = Document.new(security: { owner_password: 'abc' })
17
+ assert_equal true, pdf.internal.state.encrypt
18
+
19
+ pdf = Document.new(title: 'Title')
20
+ assert_equal 'Title', pdf.internal.state.store.info.data[:Title]
19
21
  end
20
22
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -7,18 +7,20 @@ class Thinreports::Generator::TestPDF < Minitest::Test
7
7
 
8
8
  PDF = Thinreports::Generator::PDF
9
9
 
10
- def test_new_should_set_title_as_metadata
10
+ def test_default_layout
11
+ layout_filename = layout_file.path
12
+ report = Thinreports::Report.new layout: layout_filename
13
+
14
+ generator = PDF.new report
15
+ assert_equal layout_filename, generator.default_layout.filename
16
+ end
17
+
18
+ def test_initialize
11
19
  report = Thinreports::Report.new layout: layout_file.path
12
20
  report.start_new_page
13
21
 
14
- actual_pdf_title = nil
15
- PDF::Document.define_singleton_method(:new) {|_options, meta|
16
- actual_pdf_title = meta[:Title]
17
- }
18
- PDF.new report, {}
22
+ PDF.new(report)
19
23
 
20
- assert_equal 'Report Title', actual_pdf_title
21
- ensure
22
- PDF::Document.singleton_class.send(:remove_method, :new)
24
+ assert_equal true, report.finalized?
23
25
  end
24
26
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -27,7 +27,7 @@ class Thinreports::Layout::TestFormat < Minitest::Test
27
27
  ]
28
28
  }
29
29
 
30
- Shape = Thinreports::Core::Shape
30
+ Shape = Thinreports::Core::Shape
31
31
  Layout = Thinreports::Layout
32
32
 
33
33
  def test_attribute_readers
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class Thinreports::Layout::TestLegacySchema < Minitest::Test
@@ -559,11 +560,10 @@ SVG
559
560
  )
560
561
  end
561
562
 
562
- def test_normalize_svg
563
+ def test_cleanup_svg
563
564
  svg = '<!--SHAPE{"id":"item1"}SHAPE--><!--LAYOUT<rect id="item2"/>LAYOUT--><!--SHAPE{"id":"item2"}SHAPE-->'
564
565
 
565
- layout_legacy_schema.normalize_svg!(svg)
566
- assert_equal '<rect id="item2"/>', svg
566
+ assert_equal '<rect id="item2"/>', layout_legacy_schema.cleanup_svg(svg)
567
567
  end
568
568
 
569
569
  private
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -8,88 +8,19 @@ class Thinreports::Layout::TestVersion < Minitest::Test
8
8
  # Alias
9
9
  Version = Thinreports::Layout::Version
10
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
11
+ def test_compatible?
12
+ Version.stubs(:compatible_rules).returns(['>= 0.8.0', '< 1.0.0'])
42
13
 
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
14
+ assert Version.new('0.8.0').compatible?
15
+ assert Version.new('0.9.9').compatible?
16
+ assert Version.new('0.10.0').compatible?
46
17
 
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')
18
+ refute Version.new('0.7.9').compatible?
19
+ refute Version.new('1.0.0').compatible?
49
20
  end
50
21
 
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)
22
+ def test_legacy?
23
+ assert Version.new('0.8.9').legacy?
24
+ refute Version.new('0.9.0').legacy?
94
25
  end
95
26
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
4
 
@@ -118,17 +118,20 @@ class Thinreports::Report::TestBase < Minitest::Test
118
118
  assert_equal @report.layout(:foo).filename, @layout_file.path
119
119
  end
120
120
 
121
- def test_generate_with_filename
122
- report = Report::Base.new layout: @layout_file.path
121
+ def test_generate
122
+ report = Report::Base.new(layout: @layout_file.path)
123
123
 
124
- report.generate :pdf, filename: temp_path.join('result1.pdf')
125
- report.generate filename: temp_path.join('result2.pdf')
124
+ generator = mock('generator')
125
+ generator.expects(:generate).with('result.pdf')
126
126
 
127
- assert File.exist?(temp_path.join('result1.pdf'))
128
- assert File.exist?(temp_path.join('result2.pdf'))
127
+ Thinreports::Generator::PDF.expects(:new)
128
+ .with(report, { security: { owner_password: 'pass' }})
129
+ .returns(generator)
129
130
 
130
- assert_equal File.read(temp_path.join('result1.pdf')),
131
- File.read(temp_path.join('result2.pdf'))
131
+ report.generate(
132
+ filename: 'result.pdf',
133
+ security: { owner_password: 'pass' }
134
+ )
132
135
  end
133
136
 
134
137
  def test_page_should_return_the_current_page
@@ -202,61 +205,44 @@ class Thinreports::Report::TestBase < Minitest::Test
202
205
  end
203
206
  end
204
207
 
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
208
  def test_Base_generate_should_raise_when_no_block_given
216
209
  assert_raises ArgumentError do
217
210
  Report::Base.generate(:pdf)
218
211
  end
219
212
  end
220
213
 
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']
214
+ def test_Base_generate_with_deprecated_arguments
215
+ Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report)
216
+ @report.expects(:generate).with(
217
+ filename: 'result.pdf',
218
+ security: { owner_password: 'pass' }
219
+ )
220
+
221
+ Report::Base.generate(
222
+ report: { layout: '/path/to/layout.tlf' },
223
+ generator: {
224
+ filename: 'result.pdf',
225
+ security: { owner_password: 'pass' }
226
+ }
227
+ ) { |_| }
228
+ end
229
+
230
+ def test_Base_generate_argument_priority
231
+ Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report)
232
+ @report.expects(:generate).with(
233
+ filename: 'result.pdf',
234
+ security: { owner_password: 'pass' }
235
+ )
236
+
237
+ Report::Base.generate(
238
+ layout: '/path/to/layout.tlf',
239
+ filename: 'result.pdf',
240
+ security: { owner_password: 'pass' },
241
+ report: { layout: '/path/to/deprecated.tlf' },
242
+ generator: {
243
+ filename: 'deprecated.pdf',
244
+ security: { owner_password: 'deprecated' }
245
+ }
246
+ ) { |_| }
261
247
  end
262
248
  end