thinreports 0.7.6 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -5
- data/.travis.yml +8 -4
- data/CHANGELOG.md +220 -0
- data/Gemfile +2 -9
- data/MIT-LICENSE +1 -1
- data/README.md +286 -0
- data/Rakefile +38 -8
- data/examples/character_spacing/character_spacing.rb +8 -0
- data/examples/character_spacing/character_spacing.tlf +1 -0
- data/examples/dynamic_image/dynamic_image.rb +31 -0
- data/examples/dynamic_image/dynamic_image.tlf +1 -0
- data/examples/dynamic_style/dynamic_style.rb +150 -0
- data/examples/dynamic_style/dynamic_style.tlf +1 -0
- data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/examples/helper.rb +50 -0
- data/examples/hidden_shapes/hidden_shapes.rb +9 -0
- data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
- data/examples/list_events/list_events.rb +59 -0
- data/examples/list_events/list_events_0_7_7.tlf +1 -0
- data/examples/list_events/list_events_0_8.tlf +1 -0
- data/examples/list_manual_generation/list_manual_generation.rb +22 -0
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/examples/list_page_number/list_page_number.rb +17 -0
- data/examples/list_page_number/list_page_number.tlf +1 -0
- data/examples/page_number/page_number.rb +33 -0
- data/examples/page_number/page_number.tlf +1 -0
- data/examples/password_setting/password_setting.rb +10 -0
- data/examples/password_setting/password_setting.tlf +1 -0
- data/examples/report_callbacks/report_callbacks.rb +31 -0
- data/examples/report_callbacks/report_callbacks.tlf +1 -0
- data/examples/single_line_tblock/single_line_tblock.rb +13 -0
- data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
- data/examples/tblock_overflow/tblock_overflow.rb +20 -0
- data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
- data/examples/tblock_styles/font_size.tlf +1 -0
- data/examples/tblock_styles/tblock_styles.rb +43 -0
- data/examples/tblock_styles/tblock_styles.tlf +1 -0
- data/examples/text_align/text_align.rb +8 -0
- data/examples/text_align/text_align.tlf +1 -0
- data/examples/typeB_page_size/B4_ISO.tlf +1 -0
- data/examples/typeB_page_size/B4_JIS.tlf +1 -0
- data/examples/typeB_page_size/typeB_page_size.rb +17 -0
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- data/lib/thinreports/config.rb +30 -10
- data/lib/thinreports/core/errors.rb +23 -20
- data/lib/thinreports/core/events.rb +18 -19
- data/lib/thinreports/core/format/base.rb +20 -25
- data/lib/thinreports/core/format/builder.rb +19 -27
- data/lib/thinreports/core/shape/base/interface.rb +15 -15
- data/lib/thinreports/core/shape/base/internal.rb +15 -20
- data/lib/thinreports/core/shape/base.rb +4 -5
- data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
- data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
- data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
- data/lib/thinreports/core/shape/basic/format.rb +11 -10
- data/lib/thinreports/core/shape/basic/interface.rb +3 -3
- data/lib/thinreports/core/shape/basic/internal.rb +9 -6
- data/lib/thinreports/core/shape/basic.rb +1 -1
- data/lib/thinreports/core/shape/image_block/format.rb +5 -6
- data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
- data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +37 -16
- data/lib/thinreports/core/shape/list/events.rb +11 -11
- data/lib/thinreports/core/shape/list/format.rb +27 -28
- data/lib/thinreports/core/shape/list/manager.rb +135 -95
- data/lib/thinreports/core/shape/list/page.rb +57 -51
- data/lib/thinreports/core/shape/list/page_state.rb +19 -17
- data/lib/thinreports/core/shape/list/section_format.rb +14 -15
- data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
- data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
- data/lib/thinreports/core/shape/list/store.rb +10 -11
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +22 -21
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +25 -0
- data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
- data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
- data/lib/thinreports/core/shape/page_number.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +29 -29
- data/lib/thinreports/core/shape/style/basic.rb +1 -1
- data/lib/thinreports/core/shape/style/graphic.rb +10 -25
- data/lib/thinreports/core/shape/style/text.rb +41 -31
- data/lib/thinreports/core/shape/style.rb +1 -1
- data/lib/thinreports/core/shape/text/format.rb +8 -9
- data/lib/thinreports/core/shape/text/interface.rb +2 -2
- data/lib/thinreports/core/shape/text/internal.rb +6 -7
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -17
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape.rb +11 -13
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/page.rb +37 -23
- data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
- data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
- data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
- data/lib/thinreports/generator/pdf.rb +28 -31
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/layout/base.rb +24 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -31
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/report/base.rb +117 -109
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +48 -38
- data/lib/thinreports/{core → report}/page.rb +42 -32
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/version.rb +2 -3
- data/lib/thinreports.rb +14 -2
- data/test/data/font.ttf +0 -0
- data/test/data/layout_block.tlf +1 -0
- data/test/data/layout_list.tlf +1 -0
- data/test/data/layout_list_noheader.tlf +1 -0
- data/test/data/layout_text1.tlf +1 -0
- data/test/data/layout_text2.tlf +1 -0
- data/test/test_helper.rb +74 -0
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +20 -25
- data/test/unit/core/shape/base/test_internal.rb +34 -37
- data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
- data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
- data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
- data/test/unit/core/shape/basic/test_format.rb +4 -4
- data/test/unit/core/shape/basic/test_interface.rb +36 -46
- data/test/unit/core/shape/basic/test_internal.rb +29 -18
- data/test/unit/core/shape/image_block/test_format.rb +5 -5
- data/test/unit/core/shape/image_block/test_interface.rb +17 -16
- data/test/unit/core/shape/image_block/test_internal.rb +19 -16
- data/test/unit/core/shape/list/test_configuration.rb +50 -33
- data/test/unit/core/shape/list/test_events.rb +7 -7
- data/test/unit/core/shape/list/test_format.rb +16 -18
- data/test/unit/core/shape/list/test_manager.rb +15 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +13 -13
- data/test/unit/core/shape/list/test_section_format.rb +16 -17
- data/test/unit/core/shape/list/test_section_interface.rb +30 -22
- data/test/unit/core/shape/list/test_section_internal.rb +21 -19
- data/test/unit/core/shape/list/test_store.rb +7 -7
- data/test/unit/core/shape/manager/test_format.rb +11 -15
- data/test/unit/core/shape/manager/test_internal.rb +9 -9
- data/test/unit/core/shape/manager/test_target.rb +85 -57
- data/test/unit/core/shape/page_number/test_format.rb +73 -0
- data/test/unit/core/shape/page_number/test_interface.rb +33 -0
- data/test/unit/core/shape/page_number/test_internal.rb +81 -0
- data/test/unit/core/shape/styles/test_base.rb +9 -9
- data/test/unit/core/shape/styles/test_basic.rb +5 -5
- data/test/unit/core/shape/styles/test_graphic.rb +19 -33
- data/test/unit/core/shape/styles/test_text.rb +29 -7
- data/test/unit/core/shape/text/test_format.rb +6 -6
- data/test/unit/core/shape/text/test_internal.rb +11 -12
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
- data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
- data/test/unit/core/shape/text_block/test_format.rb +13 -8
- data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
- data/test/unit/core/shape/text_block/test_interface.rb +37 -20
- data/test/unit/core/shape/text_block/test_internal.rb +38 -38
- data/test/unit/core/test_events.rb +10 -8
- data/test/unit/core/test_shape.rb +11 -7
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
- data/test/unit/generator/pdf/document/test_font.rb +79 -58
- data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
- data/test/unit/generator/pdf/document/test_page.rb +68 -43
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/pdf/test_configuration.rb +16 -9
- data/test/unit/generator/pdf/test_document.rb +8 -16
- data/test/unit/generator/test_base.rb +31 -42
- data/test/unit/generator/test_configuration.rb +6 -6
- data/test/unit/generator/test_pdf.rb +15 -21
- data/test/unit/layout/test_base.rb +34 -79
- data/test/unit/layout/test_configuration.rb +12 -37
- data/test/unit/layout/test_format.rb +36 -39
- data/test/unit/layout/test_version.rb +4 -4
- data/test/unit/report/test_base.rb +160 -192
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +102 -82
- data/test/unit/test_config.rb +31 -12
- data/test/unit/test_layout.rb +7 -7
- data/test/unit/test_report.rb +12 -24
- data/thinreports.gemspec +23 -26
- metadata +118 -181
- data/.yardopts +0 -1
- data/LICENSE +0 -1
- data/README.rdoc +0 -167
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core/ext/array.rb +0 -19
- data/lib/thinreports/core/ext/hash.rb +0 -19
- data/lib/thinreports/core/ext/object.rb +0 -25
- data/lib/thinreports/core/ext.rb +0 -5
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -13
- data/tasks/test.rake +0 -56
- data/test/benchmark/basic_estimate.tlf +0 -1
- data/test/benchmark/bench_basic_estimate.rb +0 -95
- data/test/case/character_spacing/character_spacing.rb +0 -7
- data/test/case/character_spacing/character_spacing.tlf +0 -1
- data/test/case/dynamic_image/dynamic_image.rb +0 -41
- data/test/case/dynamic_image/dynamic_image.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style.rb +0 -154
- data/test/case/dynamic_style/dynamic_style.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
- data/test/case/eudc/eudc.rb +0 -20
- data/test/case/eudc/eudc.tlf +0 -1
- data/test/case/helper.rb +0 -29
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
- data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
- data/test/case/list_events/list_events.rb +0 -32
- data/test/case/list_events/list_events.tlf +0 -1
- data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
- data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
- data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
- data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
- data/test/case/tblock_styles/tblock_styles.rb +0 -27
- data/test/case/tblock_styles/tblock_styles.tlf +0 -1
- data/test/case/text_align/text_align.rb +0 -9
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/unit/core/ext/array_spec.rb +0 -29
- data/test/unit/core/ext/hash_spec.rb +0 -29
- data/test/unit/core/ext/object_spec.rb +0 -30
- data/test/unit/core/ordered_hash_spec.rb +0 -51
- data/test/unit/core/shape/base/test_interface.rb +0 -52
- data/test/unit/core/utils_spec.rb +0 -56
- data/test/unit/data/basic_layout1.tlf +0 -1
- data/test/unit/data/basic_layout2.tlf +0 -1
- data/test/unit/data/basic_list_layout.tlf +0 -1
- data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
- data/test/unit/helper.rb +0 -65
- /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- /data/{test/case → examples}/dynamic_style/image.png +0 -0
- /data/{test/case → examples}/eudc/eudc.ttf +0 -0
- /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
- /data/{resources/fonts → fonts}/ipag.ttf +0 -0
- /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
- /data/{resources/fonts → fonts}/ipam.ttf +0 -0
- /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
|
@@ -1,306 +1,274 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class Thinreports::Report::TestBase < Minitest::Test
|
|
6
|
+
include Thinreports::TestHelper
|
|
4
7
|
|
|
5
|
-
class ThinReports::Report::TestBase < MiniTest::Unit::TestCase
|
|
6
|
-
include ThinReports::TestHelpers
|
|
7
|
-
|
|
8
8
|
# Alias
|
|
9
|
-
Report =
|
|
10
|
-
|
|
9
|
+
Report = Thinreports::Report
|
|
10
|
+
|
|
11
11
|
def setup
|
|
12
12
|
@report = Report::Base.new
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
def test_on_page_create_callback
|
|
16
|
+
report = Report::Base.new layout: data_file('layout_text1.tlf')
|
|
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
|
+
|
|
15
30
|
def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
|
|
16
|
-
report = Report::Base.new :
|
|
17
|
-
assert_equal report.default_layout.filename, data_file('
|
|
31
|
+
report = Report::Base.new layout: data_file('layout_text1.tlf')
|
|
32
|
+
assert_equal report.default_layout.filename, data_file('layout_text1.tlf')
|
|
18
33
|
end
|
|
19
|
-
|
|
34
|
+
|
|
20
35
|
def test_initialize_should_initialize_new_Report_without_default_layout
|
|
21
36
|
assert_nil @report.default_layout
|
|
22
37
|
end
|
|
23
|
-
|
|
38
|
+
|
|
24
39
|
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
|
|
25
|
-
@report.use_layout(data_file('
|
|
26
|
-
|
|
27
|
-
assert_equal @report.default_layout.filename, data_file('
|
|
40
|
+
@report.use_layout(data_file('layout_text1.tlf'))
|
|
41
|
+
|
|
42
|
+
assert_equal @report.default_layout.filename, data_file('layout_text1.tlf')
|
|
28
43
|
end
|
|
29
|
-
|
|
44
|
+
|
|
30
45
|
def test_use_layout_should_register_default_layout_when_default_property_is_true
|
|
31
|
-
@report.use_layout(data_file('
|
|
32
|
-
|
|
33
|
-
assert_equal @report.default_layout.filename, data_file('
|
|
46
|
+
@report.use_layout(data_file('layout_text2.tlf'), default: true)
|
|
47
|
+
|
|
48
|
+
assert_equal @report.default_layout.filename, data_file('layout_text2.tlf')
|
|
34
49
|
end
|
|
35
|
-
|
|
50
|
+
|
|
36
51
|
def test_start_new_page_should_properly_create_a_new_Page_and_return
|
|
37
|
-
@report.use_layout(data_file('
|
|
38
|
-
|
|
39
|
-
assert_instance_of
|
|
52
|
+
@report.use_layout(data_file('layout_text1'))
|
|
53
|
+
|
|
54
|
+
assert_instance_of Thinreports::Report::Page, @report.start_new_page
|
|
40
55
|
end
|
|
41
|
-
|
|
56
|
+
|
|
42
57
|
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
|
|
43
|
-
assert_raises
|
|
44
|
-
@report.start_new_page(:
|
|
58
|
+
assert_raises Thinreports::Errors::NoRegisteredLayoutFound do
|
|
59
|
+
@report.start_new_page(layout: :unknown)
|
|
45
60
|
end
|
|
46
61
|
end
|
|
47
|
-
|
|
62
|
+
|
|
48
63
|
def test_start_new_page_should_create_a_new_page_using_a_default_layout
|
|
49
|
-
@report.use_layout(data_file('
|
|
50
|
-
|
|
51
|
-
assert_equal @report.start_new_page.layout.filename, data_file('
|
|
64
|
+
@report.use_layout(data_file('layout_text1.tlf'), default: true)
|
|
65
|
+
|
|
66
|
+
assert_equal @report.start_new_page.layout.filename, data_file('layout_text1.tlf')
|
|
52
67
|
end
|
|
53
|
-
|
|
68
|
+
|
|
54
69
|
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
|
|
55
|
-
@report.use_layout(data_file('
|
|
56
|
-
|
|
57
|
-
assert_equal @report.start_new_page(:
|
|
58
|
-
data_file('
|
|
70
|
+
@report.use_layout(data_file('layout_text1.tlf'), id: :foo)
|
|
71
|
+
|
|
72
|
+
assert_equal @report.start_new_page(layout: :foo).layout.filename,
|
|
73
|
+
data_file('layout_text1.tlf')
|
|
59
74
|
end
|
|
60
|
-
|
|
75
|
+
|
|
61
76
|
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
|
|
62
|
-
new_page = @report.start_new_page(:
|
|
63
|
-
assert_equal new_page.layout.filename, data_file('
|
|
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')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_start_new_page_with_count_option
|
|
82
|
+
@report.use_layout data_file('layout_text1.tlf'), 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
|
|
64
95
|
end
|
|
65
|
-
|
|
96
|
+
|
|
66
97
|
def test_add_blank_page_should_properly_create_a_new_blank_page
|
|
67
|
-
@report.use_layout(data_file('
|
|
68
|
-
|
|
69
|
-
assert_instance_of
|
|
98
|
+
@report.use_layout(data_file('layout_text1'))
|
|
99
|
+
|
|
100
|
+
assert_instance_of Thinreports::Report::BlankPage, @report.add_blank_page
|
|
70
101
|
end
|
|
71
|
-
|
|
102
|
+
|
|
72
103
|
def test_layout_should_return_the_default_layout_with_no_arguments
|
|
73
|
-
@report.use_layout(data_file('
|
|
74
|
-
|
|
75
|
-
assert_equal @report.layout.filename, data_file('
|
|
104
|
+
@report.use_layout(data_file('layout_text1.tlf'), default: true)
|
|
105
|
+
|
|
106
|
+
assert_equal @report.layout.filename, data_file('layout_text1.tlf')
|
|
76
107
|
end
|
|
77
|
-
|
|
108
|
+
|
|
78
109
|
def test_layout_should_raise_when_the_specified_layout_is_not_found
|
|
79
|
-
assert_raises
|
|
110
|
+
assert_raises Thinreports::Errors::UnknownLayoutId do
|
|
80
111
|
@report.layout(:unknown_layout_id)
|
|
81
112
|
end
|
|
82
113
|
end
|
|
83
|
-
|
|
114
|
+
|
|
84
115
|
def test_layout_should_return_the_layout_with_specified_id
|
|
85
|
-
@report.use_layout(data_file('
|
|
86
|
-
|
|
87
|
-
assert_equal @report.layout(:foo).filename, data_file('
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
and_return(flexmock(:generate => 'Success')).once
|
|
104
|
-
|
|
105
|
-
assert_equal @report.generate(:option => :value), 'Success'
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_specified
|
|
109
|
-
generator = flexmock('generator')
|
|
110
|
-
generator.should_receive(:generate_file).with('output.pdf').once
|
|
111
|
-
|
|
112
|
-
flexmock(ThinReports::Generator).
|
|
113
|
-
should_receive(:new).
|
|
114
|
-
with(:pdf, @report, {}).
|
|
115
|
-
and_return(generator).once
|
|
116
|
-
|
|
117
|
-
@report.generate_file(:pdf, 'output.pdf')
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_omitted
|
|
121
|
-
generator = flexmock('generator')
|
|
122
|
-
generator.should_receive(:generate_file).with('output.pdf').once
|
|
123
|
-
|
|
124
|
-
flexmock(ThinReports::Generator).
|
|
125
|
-
should_receive(:new).
|
|
126
|
-
with(:pdf, @report, {:option => :value}).
|
|
127
|
-
and_return(generator).once
|
|
128
|
-
|
|
129
|
-
@report.generate_file('output.pdf', :option => :value)
|
|
130
|
-
end
|
|
131
|
-
|
|
116
|
+
@report.use_layout(data_file('layout_text2.tlf'), id: :foo)
|
|
117
|
+
|
|
118
|
+
assert_equal @report.layout(:foo).filename, data_file('layout_text2.tlf')
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_generate_with_filename
|
|
122
|
+
report = Report::Base.new layout: data_file('layout_text1.tlf')
|
|
123
|
+
|
|
124
|
+
report.generate :pdf, filename: temp_path.join('result1.pdf')
|
|
125
|
+
report.generate filename: temp_path.join('result2.pdf')
|
|
126
|
+
|
|
127
|
+
assert File.exists?(temp_path.join('result1.pdf'))
|
|
128
|
+
assert File.exists?(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
|
+
|
|
132
134
|
def test_events_should_return_Report_Events
|
|
133
|
-
assert_instance_of
|
|
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]'
|
|
134
143
|
end
|
|
135
|
-
|
|
144
|
+
|
|
136
145
|
def test_page_should_return_the_current_page
|
|
137
|
-
@report.use_layout(data_file('
|
|
146
|
+
@report.use_layout(data_file('layout_text1.tlf'))
|
|
138
147
|
@report.start_new_page
|
|
139
|
-
|
|
140
|
-
assert_instance_of
|
|
148
|
+
|
|
149
|
+
assert_instance_of Thinreports::Report::Page, @report.page
|
|
141
150
|
end
|
|
142
|
-
|
|
151
|
+
|
|
143
152
|
def test_page_count_should_return_total_page_count
|
|
144
|
-
@report.use_layout(data_file('
|
|
153
|
+
@report.use_layout(data_file('layout_text1.tlf'))
|
|
145
154
|
2.times { @report.start_new_page }
|
|
146
|
-
|
|
155
|
+
|
|
147
156
|
assert_equal @report.page_count, 2
|
|
148
157
|
end
|
|
149
|
-
|
|
158
|
+
|
|
150
159
|
def test_finalize_should_finalize_report
|
|
151
160
|
@report.finalize
|
|
152
161
|
assert_equal @report.finalized?, true
|
|
153
162
|
end
|
|
154
|
-
|
|
163
|
+
|
|
155
164
|
def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
|
|
156
165
|
assert_equal @report.finalized?, false
|
|
157
166
|
end
|
|
158
|
-
|
|
167
|
+
|
|
159
168
|
def test_finalized_asker_should_return_true_when_report_is_already_finalized
|
|
160
169
|
@report.finalize
|
|
161
170
|
assert_equal @report.finalized?, true
|
|
162
171
|
end
|
|
163
|
-
|
|
172
|
+
|
|
164
173
|
def test_list_should_create_new_page_when_page_is_not_created
|
|
165
|
-
@report.use_layout(data_file('
|
|
174
|
+
@report.use_layout(data_file('layout_list.tlf'))
|
|
166
175
|
@report.list(:list)
|
|
167
|
-
|
|
176
|
+
|
|
168
177
|
refute_nil @report.page
|
|
169
178
|
end
|
|
170
|
-
|
|
179
|
+
|
|
171
180
|
def test_list_should_create_new_page_when_page_is_finalized
|
|
172
181
|
@report.tap do |r|
|
|
173
|
-
r.use_layout(data_file('
|
|
182
|
+
r.use_layout(data_file('layout_list.tlf'))
|
|
174
183
|
r.start_new_page
|
|
175
184
|
r.page.finalize
|
|
176
185
|
end
|
|
177
186
|
@report.list(:list)
|
|
178
|
-
|
|
187
|
+
|
|
179
188
|
assert_equal @report.page.finalized?, false
|
|
180
189
|
end
|
|
181
|
-
|
|
190
|
+
|
|
182
191
|
def test_list_should_properly_return_shape_with_the_specified_id
|
|
183
|
-
@report.use_layout(data_file('
|
|
184
|
-
|
|
192
|
+
@report.use_layout(data_file('layout_list.tlf'))
|
|
193
|
+
|
|
185
194
|
assert_equal @report.list(:list).id, 'list'
|
|
186
195
|
end
|
|
187
|
-
|
|
196
|
+
|
|
197
|
+
def test_start_page_number
|
|
198
|
+
assert_equal @report.start_page_number, 1
|
|
199
|
+
@report.start_page_number_from 10
|
|
200
|
+
assert_equal @report.start_page_number, 10
|
|
201
|
+
end
|
|
202
|
+
|
|
188
203
|
def test_Base_create_should_finalize_report
|
|
189
204
|
report = Report::Base.create do |r|
|
|
190
205
|
assert_instance_of Report::Base, r
|
|
191
206
|
end
|
|
192
207
|
assert_equal report.finalized?, true
|
|
193
208
|
end
|
|
194
|
-
|
|
209
|
+
|
|
195
210
|
def test_Base_create_should_raise_when_no_block_given
|
|
196
211
|
assert_raises ArgumentError do
|
|
197
212
|
Report::Base.create
|
|
198
213
|
end
|
|
199
214
|
end
|
|
200
|
-
|
|
201
|
-
def
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def test_Base_generate_should_properly_generate_when_type_is_omitted
|
|
216
|
-
flexmock(Report::Base).new_instances.
|
|
217
|
-
should_receive(:generate).
|
|
218
|
-
with({}).once
|
|
219
|
-
|
|
220
|
-
flexmock(Report::Base).
|
|
221
|
-
should_receive(:create).
|
|
222
|
-
with({}, Proc).
|
|
223
|
-
and_return(Report::Base.new).once
|
|
224
|
-
|
|
225
|
-
Report::Base.generate {}
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def test_Base_generate_file_should_properly_generate_file_when_type_is_specified
|
|
229
|
-
flexmock(Report::Base).new_instances.
|
|
230
|
-
should_receive(:generate_file).
|
|
231
|
-
with(:pdf, 'output.pdf', {}).once
|
|
232
|
-
|
|
233
|
-
flexmock(Report::Base).
|
|
234
|
-
should_receive(:create).
|
|
235
|
-
with({:layout => 'layout.tlf'}, Proc).
|
|
236
|
-
and_return(Report::Base.new).once
|
|
237
|
-
|
|
238
|
-
Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'}) {}
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def test_Base_generate_file_should_properly_generate_file_when_type_is_omitted
|
|
242
|
-
flexmock(Report::Base).new_instances.
|
|
243
|
-
should_receive(:generate_file).
|
|
244
|
-
with('output.pdf', :option => :value).once
|
|
245
|
-
|
|
246
|
-
flexmock(Report::Base).
|
|
247
|
-
should_receive(:create).
|
|
248
|
-
with({}, Proc).
|
|
249
|
-
and_return(Report::Base.new).once
|
|
250
|
-
|
|
251
|
-
Report::Base.generate_file('output.pdf', :generator => {:option => :value}) {}
|
|
252
|
-
end
|
|
253
|
-
|
|
215
|
+
|
|
216
|
+
def test_Base_generate_with_filename
|
|
217
|
+
layout_file = data_file 'layout_text1.tlf'
|
|
218
|
+
|
|
219
|
+
Report::Base.generate(:pdf, report: { layout: layout_file },
|
|
220
|
+
generator: { filename: temp_path.join('result1.pdf') }) {}
|
|
221
|
+
Report::Base.generate(report: { layout: layout_file },
|
|
222
|
+
generator: { filename: temp_path.join('result2.pdf') }) {}
|
|
223
|
+
|
|
224
|
+
assert_equal temp_path.join('result1.pdf').read,
|
|
225
|
+
temp_path.join('result2.pdf').read
|
|
226
|
+
end
|
|
227
|
+
|
|
254
228
|
def test_Base_generate_should_raise_when_no_block_given
|
|
255
229
|
assert_raises ArgumentError do
|
|
256
230
|
Report::Base.generate(:pdf)
|
|
257
231
|
end
|
|
258
232
|
end
|
|
259
|
-
|
|
260
|
-
def test_Base_generate_file_should_raise_when_no_block_given
|
|
261
|
-
assert_raises ArgumentError do
|
|
262
|
-
Report::Base.generate_file(:pdf, 'output.pdf')
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
233
|
+
|
|
266
234
|
def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
|
|
267
|
-
report, generator = Report::Base.send(:extract_options!, [{:
|
|
235
|
+
report, generator = Report::Base.send(:extract_options!, [{report: {layout: 'hoge.tlf'}}])
|
|
268
236
|
assert_equal report[:layout], 'hoge.tlf'
|
|
269
237
|
end
|
|
270
|
-
|
|
238
|
+
|
|
271
239
|
def test_Base_extract_options_should_operate_an_argument_destructively
|
|
272
|
-
args = [:pdf, 'output.pdf', {:
|
|
240
|
+
args = [:pdf, 'output.pdf', {report: {layout: 'foo.tlf'}}]
|
|
273
241
|
Report::Base.send(:extract_options!, args)
|
|
274
242
|
assert_equal args, [:pdf, 'output.pdf']
|
|
275
243
|
end
|
|
276
|
-
|
|
244
|
+
|
|
277
245
|
def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
|
|
278
|
-
report, generator = Report::Base.send(:extract_options!, [{:
|
|
246
|
+
report, generator = Report::Base.send(:extract_options!, [{layout: 'hoge.tlf'}])
|
|
279
247
|
assert_equal report[:layout], 'hoge.tlf'
|
|
280
248
|
end
|
|
281
|
-
|
|
249
|
+
|
|
282
250
|
def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
|
|
283
251
|
report, generator = Report::Base.send(:extract_options!,
|
|
284
|
-
[{:
|
|
252
|
+
[{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf'}])
|
|
285
253
|
assert_equal report[:layout], 'hoge.tlf'
|
|
286
254
|
end
|
|
287
|
-
|
|
255
|
+
|
|
288
256
|
def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
|
|
289
257
|
report, generator = Report::Base.send(:extract_options!,
|
|
290
|
-
[{:
|
|
258
|
+
[{generator: {option: 'value'}}])
|
|
291
259
|
assert_equal generator[:option], 'value'
|
|
292
260
|
end
|
|
293
|
-
|
|
261
|
+
|
|
294
262
|
def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
|
|
295
263
|
report, generator = Report::Base.send(:extract_options!,
|
|
296
|
-
[{:
|
|
264
|
+
[{generator: {option: 'value1'}, option: 'value2'}])
|
|
297
265
|
assert_equal generator[:option], 'value2'
|
|
298
266
|
end
|
|
299
|
-
|
|
267
|
+
|
|
300
268
|
def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
|
|
301
269
|
report, generator = Report::Base.send(:extract_options!,
|
|
302
|
-
[{:
|
|
303
|
-
:
|
|
270
|
+
[{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf',
|
|
271
|
+
generator_opt1: 'value1', generator_opt2: 'value2'}])
|
|
304
272
|
assert_equal generator.values_at(:generator_opt1, :generator_opt2),
|
|
305
273
|
['value1', 'value2']
|
|
306
274
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'test_helper'
|
|
4
4
|
|
|
5
|
-
class
|
|
6
|
-
include
|
|
5
|
+
class Thinreports::Report::TestEvents < Minitest::Test
|
|
6
|
+
include Thinreports::TestHelper
|
|
7
7
|
|
|
8
8
|
# Alias
|
|
9
|
-
Report =
|
|
9
|
+
Report = Thinreports::Report
|
|
10
10
|
|
|
11
11
|
def test_event_types
|
|
12
12
|
events = Report::Events.new
|