thinreports 0.6.0.pre3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -32
- data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
- data/lib/thinreports.rb +2 -1
- data/lib/thinreports/config.rb +21 -0
- data/lib/thinreports/core/errors.rb +14 -1
- data/lib/thinreports/core/format/builder.rb +6 -1
- data/lib/thinreports/core/page.rb +6 -6
- data/lib/thinreports/core/shape.rb +8 -9
- data/lib/thinreports/core/shape/base/internal.rb +6 -12
- data/lib/thinreports/core/shape/basic.rb +3 -0
- data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
- data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
- data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
- data/lib/thinreports/core/shape/basic/interface.rb +37 -11
- data/lib/thinreports/core/shape/basic/internal.rb +3 -12
- data/lib/thinreports/core/shape/image_block.rb +15 -0
- data/lib/thinreports/core/shape/image_block/format.rb +13 -0
- data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
- data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
- data/lib/thinreports/core/shape/list/events.rb +19 -2
- data/lib/thinreports/core/shape/list/manager.rb +17 -4
- data/lib/thinreports/core/shape/list/page.rb +2 -2
- data/lib/thinreports/core/shape/list/page_state.rb +4 -0
- data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
- data/lib/thinreports/core/shape/manager/format.rb +1 -1
- data/lib/thinreports/core/shape/manager/internal.rb +24 -11
- data/lib/thinreports/core/shape/manager/target.rb +2 -2
- data/lib/thinreports/core/shape/style.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +149 -0
- data/lib/thinreports/core/shape/style/basic.rb +17 -0
- data/lib/thinreports/core/shape/style/graphic.rb +60 -0
- data/lib/thinreports/core/shape/style/text.rb +138 -0
- data/lib/thinreports/core/shape/text/internal.rb +4 -0
- data/lib/thinreports/core/shape/text_block.rb +16 -0
- data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
- data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
- data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
- data/lib/thinreports/core/utils.rb +0 -8
- data/lib/thinreports/generator.rb +2 -2
- data/lib/thinreports/generator/configuration.rb +30 -0
- data/lib/thinreports/generator/pdf.rb +13 -10
- data/lib/thinreports/generator/pdf/configuration.rb +28 -0
- data/lib/thinreports/generator/pdf/document.rb +16 -56
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
- data/lib/thinreports/generator/pdf/document/font.rb +25 -9
- data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
- data/lib/thinreports/generator/pdf/document/page.rb +70 -0
- data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
- data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
- data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
- data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
- data/lib/thinreports/layout/format.rb +2 -2
- data/lib/thinreports/layout/version.rb +2 -2
- data/lib/thinreports/report/base.rb +68 -31
- data/tasks/test.rake +48 -4
- data/test/benchmark/basic_estimate.tlf +1 -0
- data/test/benchmark/bench_basic_estimate.rb +95 -0
- data/test/case/character_spacing/character_spacing.rb +7 -0
- data/test/case/character_spacing/character_spacing.tlf +1 -0
- data/test/case/dynamic_image/dynamic_image.rb +41 -0
- data/test/case/dynamic_image/dynamic_image.tlf +1 -0
- data/test/case/dynamic_image/img200x100.png +0 -0
- data/test/case/dynamic_image/img50x50.png +0 -0
- data/test/case/dynamic_style/dynamic_style.rb +154 -0
- data/test/case/dynamic_style/dynamic_style.tlf +1 -0
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/test/case/dynamic_style/image.png +0 -0
- data/test/case/eudc/eudc.rb +20 -0
- data/test/case/eudc/eudc.tlf +1 -0
- data/test/case/eudc/eudc.ttf +0 -0
- data/test/case/helper.rb +27 -0
- data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
- data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
- data/test/case/list_events/list_events.rb +32 -0
- data/test/case/list_events/list_events.tlf +1 -0
- data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
- data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
- data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
- data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
- data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
- data/test/case/tblock_styles/tblock_styles.rb +27 -0
- data/test/case/tblock_styles/tblock_styles.tlf +1 -0
- data/test/case/text_align/text_align.rb +9 -0
- data/test/case/text_align/text_align.tlf +1 -0
- data/test/unit/core/shape/base/test_internal.rb +65 -85
- data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
- data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
- data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
- data/test/unit/core/shape/basic/test_interface.rb +84 -36
- data/test/unit/core/shape/basic/test_internal.rb +32 -24
- data/test/unit/core/shape/image_block/test_format.rb +58 -0
- data/test/unit/core/shape/image_block/test_interface.rb +23 -0
- data/test/unit/core/shape/image_block/test_internal.rb +28 -0
- data/test/unit/core/shape/list/test_events.rb +19 -11
- data/test/unit/core/shape/list/test_manager.rb +112 -0
- data/test/unit/core/shape/list/test_page.rb +57 -0
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +37 -30
- data/test/unit/core/shape/list/test_section_internal.rb +39 -14
- data/test/unit/core/shape/manager/test_format.rb +12 -18
- data/test/unit/core/shape/manager/test_internal.rb +127 -93
- data/test/unit/core/shape/manager/test_target.rb +63 -56
- data/test/unit/core/shape/styles/test_base.rb +219 -0
- data/test/unit/core/shape/styles/test_basic.rb +24 -0
- data/test/unit/core/shape/styles/test_graphic.rb +69 -0
- data/test/unit/core/shape/styles/test_text.rb +318 -0
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
- data/test/unit/core/shape/text_block/test_format.rb +160 -0
- data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
- data/test/unit/core/shape/text_block/test_interface.rb +46 -0
- data/test/unit/core/shape/text_block/test_internal.rb +128 -0
- data/test/unit/core/test_shape.rb +31 -6
- data/test/unit/data/basic_layout1.tlf +1 -0
- data/test/unit/data/basic_layout2.tlf +1 -0
- data/test/unit/data/basic_list_layout.tlf +1 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
- data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
- data/test/unit/generator/pdf/document/test_font.rb +21 -6
- data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
- data/test/unit/generator/pdf/document/test_page.rb +95 -0
- data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
- data/test/unit/generator/pdf/test_configuration.rb +24 -0
- data/test/unit/generator/pdf/test_document.rb +28 -0
- data/test/unit/generator/test_configuration.rb +25 -0
- data/test/unit/generator/test_pdf.rb +19 -0
- data/test/unit/helper.rb +18 -0
- data/test/unit/layout/test_format.rb +24 -7
- data/test/unit/layout/test_version.rb +61 -27
- data/test/unit/report/test_base.rb +185 -89
- data/test/unit/test_config.rb +22 -0
- data/test/unit/test_report.rb +4 -4
- metadata +94 -43
- data/lib/thinreports/core/shape/tblock.rb +0 -16
- data/lib/thinreports/generator/pxd.rb +0 -75
- data/lib/thinreports/generator/pxd/helper.rb +0 -33
- data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
- data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
- data/tasks/clean.rake +0 -6
- data/test/unit/core/shape/tblock/test_format.rb +0 -125
- data/test/unit/core/shape/tblock/test_interface.rb +0 -40
- data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'test/unit/helper'
|
4
4
|
|
5
|
-
class ThinReports::Generator::
|
5
|
+
class ThinReports::Generator::PDF::TestParseColor < MiniTest::Unit::TestCase
|
6
6
|
include ThinReports::TestHelpers
|
7
7
|
|
8
8
|
class TestColorParser
|
9
|
-
include ThinReports::Generator::
|
9
|
+
include ThinReports::Generator::PDF::ParseColor
|
10
10
|
end
|
11
11
|
|
12
12
|
def setup
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::PDF::TestConfiguration < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@config = ThinReports::Generator::PDF::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_eudc_fonts_can_only_set_font_of_TTF
|
13
|
+
assert_raises ArgumentError do
|
14
|
+
@config.eudc_fonts = '/path/to/eudc'
|
15
|
+
end
|
16
|
+
assert_raises ArgumentError do
|
17
|
+
@config.eudc_fonts = %w( /path/to/eudc1.ttf /path/to/eudc2 )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_eudc_fonts_should_return_empty_array_by_default
|
22
|
+
assert_equal @config.eudc_fonts, []
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::PDF::TestDocument < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Document = ThinReports::Generator::PDF::Document
|
10
|
+
|
11
|
+
def test_new_without_page_creation
|
12
|
+
pdf = Document.new
|
13
|
+
assert_equal pdf.internal.page_count, 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_new_with_zero_margin_canvas
|
17
|
+
pdf = Document.new
|
18
|
+
assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_new_with_security_settings
|
22
|
+
flexmock(Prawn::Document).new_instances.
|
23
|
+
should_receive(:encrypt_document).once.
|
24
|
+
with(:user_password => 'foo')
|
25
|
+
|
26
|
+
Document.new(:security => {:user_password => 'foo'})
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::TestConfiguration < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@config = ThinReports::Generator::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_pdf_should_return_configuration_of_pdf
|
13
|
+
assert_instance_of ThinReports::Generator::PDF::Configuration, @config.pdf
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_should_return_pdf_by_default
|
17
|
+
assert_equal @config.default, :pdf
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_default_should_raise_when_value_is_unknown_generator_type
|
21
|
+
assert_raises ThinReports::Errors::UnknownGeneratorType do
|
22
|
+
@config.default = :unknown
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::TestPDF < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
PDF = ThinReports::Generator::PDF
|
10
|
+
|
11
|
+
def test_new_should_set_title_as_metadata
|
12
|
+
report = create_basic_report('basic_layout1.tlf') {|r| r.start_new_page }
|
13
|
+
|
14
|
+
flexmock(PDF::Document).should_receive(:new).
|
15
|
+
with(Hash, :Title => 'Basic Layout').once
|
16
|
+
|
17
|
+
PDF.new(report, {})
|
18
|
+
end
|
19
|
+
end
|
data/test/unit/helper.rb
CHANGED
@@ -34,4 +34,22 @@ module ThinReports::TestHelpers
|
|
34
34
|
skip('This test is not required Ruby 1.8 below.')
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def create_basic_report(file, &block)
|
39
|
+
report = ThinReports::Report.new :layout => data_file(file)
|
40
|
+
block.call(report) if block_given?
|
41
|
+
report
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_basic_layout(file)
|
45
|
+
ThinReports::Layout.new(data_file(file))
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_basic_layout_format(file)
|
49
|
+
ThinReports::Layout::Format.build(data_file(file))
|
50
|
+
end
|
51
|
+
|
52
|
+
def data_file(filename)
|
53
|
+
File.join(File.dirname(__FILE__), 'data', filename)
|
54
|
+
end
|
37
55
|
end
|
@@ -7,10 +7,7 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
|
|
7
7
|
|
8
8
|
TEST_SIMPLE_FORMAT = <<-'EOF'
|
9
9
|
{
|
10
|
-
"built-at":"",
|
11
10
|
"version":"%s",
|
12
|
-
"encoding":"utf-8",
|
13
|
-
"updated-at":"20110528120710",
|
14
11
|
"finger-print":-860627816,
|
15
12
|
"config":{
|
16
13
|
"title":"Sample Layout",
|
@@ -37,6 +34,26 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
|
|
37
34
|
Shape = ThinReports::Core::Shape
|
38
35
|
Layout = ThinReports::Layout
|
39
36
|
|
37
|
+
def test_report_title
|
38
|
+
format = Layout::Format.new('config' => {'title' => 'Title'})
|
39
|
+
assert_equal format.report_title, 'Title'
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_user_paper_type_return_true_when_type_is_user
|
43
|
+
format = Layout::Format.new('config' => {'page' => {'paper-type' => 'user'}})
|
44
|
+
assert_equal format.user_paper_type?, true
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_user_paper_type_return_false_when_type_is_not_user
|
48
|
+
format = Layout::Format.new('config' => {'page' => {'paper-type' => 'A4'}})
|
49
|
+
assert_equal format.user_paper_type?, false
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_last_version
|
53
|
+
format = Layout::Format.new('version' => '1.0')
|
54
|
+
assert_equal format.last_version, '1.0'
|
55
|
+
end
|
56
|
+
|
40
57
|
def test_build_simple_format
|
41
58
|
flexmock(Layout::Format).
|
42
59
|
should_receive(:read_format_file).and_return(create_raw_format).once
|
@@ -77,12 +94,12 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
|
|
77
94
|
assert_same result1, result2
|
78
95
|
end
|
79
96
|
|
80
|
-
def
|
97
|
+
def test_build_should_raise_when_layout_file_is_incompatible
|
81
98
|
original_rules = Layout::Version::REQUIRED_RULES.dup
|
82
|
-
Layout::Version::REQUIRED_RULES.replace(['
|
99
|
+
Layout::Version::REQUIRED_RULES.replace(['>= 0.6.0.pre3', '< 0.8.0'])
|
83
100
|
|
84
101
|
flexmock(Layout::Format).
|
85
|
-
should_receive(:read_format_file).and_return(create_raw_format('
|
102
|
+
should_receive(:read_format_file).and_return(create_raw_format('0.6.0.pre2'))
|
86
103
|
|
87
104
|
assert_raises ThinReports::Errors::IncompatibleLayoutFormat do
|
88
105
|
Layout::Format.build('dummy.tlf')
|
@@ -92,7 +109,7 @@ class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
|
|
92
109
|
end
|
93
110
|
|
94
111
|
def setup
|
95
|
-
flexmock(Shape::
|
112
|
+
flexmock(Shape::TextBlock::Format).
|
96
113
|
should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
|
97
114
|
flexmock(Shape::Basic::Format).
|
98
115
|
should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
|
@@ -8,45 +8,79 @@ class ThinReports::Layout::TestVersion < MiniTest::Unit::TestCase
|
|
8
8
|
# Alias
|
9
9
|
Version = ThinReports::Layout::Version
|
10
10
|
|
11
|
-
def
|
12
|
-
assert_equal Version.comparable_version('0.
|
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
|
13
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
|
14
20
|
assert_equal Version.comparable_version('0.6.0.pre2'), '0.6.0.2'
|
15
21
|
end
|
16
22
|
|
17
|
-
def
|
18
|
-
assert Version.compare('0.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
def test_compare_with_equal_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
24
|
+
assert Version.compare('0.7.0', '== 0.7.0')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_compare_with_equal_rule_should_return_false_when_the_given_version_is_not_equal_to_the_version_of_rule
|
28
|
+
refute Version.compare('0.6.0.pre3', '== 0.6.0.pre2')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_compare_with_larger_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
|
32
|
+
assert Version.compare('0.7.0', '> 0.6.0.pre3')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_compare_with_larger_rule_should_return_false_when_the_given_version_is_not_larger_than_the_version_of_rule
|
36
|
+
refute Version.compare('0.7.0', '> 0.7.0')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
40
|
+
assert Version.compare('0.7.0', '>= 0.7.0')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_compare_with_one_or_more_rule_should_return_true_when_the_given_version_is_larger_than_the_version_of_rule
|
44
|
+
assert Version.compare('0.7.0', '>= 0.6.0.pre3')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_compare_with_one_or_more_rule_should_return_false_when_the_give_version_is_not_more_than_the_version_of_rule
|
48
|
+
refute Version.compare('0.6.0.pre3', '>= 0.7.0')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_compare_with_one_or_less_rule_should_return_true_when_the_given_version_is_equal_to_the_version_of_rule
|
52
|
+
assert Version.compare('0.7.0', '<= 0.7.0')
|
31
53
|
end
|
32
54
|
|
33
|
-
def
|
34
|
-
assert Version.compare('0.
|
35
|
-
refute Version.compare('0.6.5', '> 0.6.0', '< 0.6.4')
|
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')
|
36
57
|
end
|
37
58
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
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)'
|
41
66
|
end
|
42
67
|
end
|
43
68
|
|
44
|
-
def
|
45
|
-
required_rules('
|
46
|
-
assert_equal Version.
|
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)'
|
47
72
|
end
|
48
|
-
|
49
|
-
|
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')
|
50
84
|
end
|
51
85
|
end
|
52
86
|
|
@@ -12,176 +12,272 @@ class ThinReports::Report::TestBase < MiniTest::Unit::TestCase
|
|
12
12
|
@report = Report::Base.new
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
|
16
|
+
report = Report::Base.new :layout => data_file('basic_layout1.tlf')
|
17
|
+
assert_equal report.default_layout.filename, data_file('basic_layout1.tlf')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize_should_initialize_new_Report_without_default_layout
|
21
|
+
assert_nil @report.default_layout
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
should_receive(:register_layout).with('layout.tlf', {:default => true}).
|
27
|
-
and_return(flexmock('layout_config')).once
|
24
|
+
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
|
25
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
28
26
|
|
29
|
-
assert_equal @report.
|
30
|
-
'layout_config'
|
27
|
+
assert_equal @report.default_layout.filename, data_file('basic_layout1.tlf')
|
31
28
|
end
|
32
29
|
|
33
|
-
def
|
34
|
-
|
35
|
-
layout.should_receive(:init_new_page).once
|
30
|
+
def test_use_layout_should_register_default_layout_when_default_property_is_true
|
31
|
+
@report.use_layout(data_file('basic_layout2.tlf'), :default => true)
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
assert_equal @report.default_layout.filename, data_file('basic_layout2.tlf')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_start_new_page_should_properly_create_a_new_Page_and_return
|
37
|
+
@report.use_layout(data_file('basic_layout1'))
|
40
38
|
|
41
|
-
|
39
|
+
assert_instance_of ThinReports::Core::Page, @report.start_new_page
|
42
40
|
end
|
43
41
|
|
44
|
-
def
|
42
|
+
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
|
45
43
|
assert_raises ThinReports::Errors::NoRegisteredLayoutFound do
|
46
44
|
@report.start_new_page(:layout => :unknown)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
51
|
-
|
48
|
+
def test_start_new_page_should_create_a_new_page_using_a_default_layout
|
49
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
52
50
|
|
53
|
-
|
54
|
-
|
51
|
+
assert_equal @report.start_new_page.layout.filename, data_file('basic_layout1.tlf')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
|
55
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :id => :foo)
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
assert_equal @report.start_new_page(:layout => :foo).layout.filename,
|
58
|
+
data_file('basic_layout1.tlf')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
|
62
|
+
new_page = @report.start_new_page(:layout => data_file('basic_layout1.tlf'))
|
63
|
+
assert_equal new_page.layout.filename, data_file('basic_layout1.tlf')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_add_blank_page_should_properly_create_a_new_blank_page
|
67
|
+
@report.use_layout(data_file('basic_layout1'))
|
58
68
|
|
59
|
-
@report.add_blank_page
|
69
|
+
assert_instance_of ThinReports::Core::BlankPage, @report.add_blank_page
|
60
70
|
end
|
61
71
|
|
62
|
-
def
|
63
|
-
|
64
|
-
should_receive(:default_layout).and_return(flexmock('default_layout'))
|
72
|
+
def test_layout_should_return_the_default_layout_with_no_arguments
|
73
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
65
74
|
|
66
|
-
assert_equal @report.layout.
|
75
|
+
assert_equal @report.layout.filename, data_file('basic_layout1.tlf')
|
67
76
|
end
|
68
77
|
|
69
|
-
def
|
78
|
+
def test_layout_should_raise_when_the_specified_layout_is_not_found
|
70
79
|
assert_raises ThinReports::Errors::UnknownLayoutId do
|
71
|
-
@report.layout(:
|
80
|
+
@report.layout(:unknown_layout_id)
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
assert_equal @report.generate(:pdf, {:option => :value}), 'output'
|
84
|
+
def test_layout_should_return_the_layout_with_specified_id
|
85
|
+
@report.use_layout(data_file('basic_layout2.tlf'), :id => :foo)
|
86
|
+
|
87
|
+
assert_equal @report.layout(:foo).filename, data_file('basic_layout2.tlf')
|
80
88
|
end
|
81
89
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_specified
|
91
|
+
flexmock(ThinReports::Generator).
|
92
|
+
should_receive(:new).
|
93
|
+
with(:pdf, @report, {:option => :value}).
|
94
|
+
and_return(flexmock(:generate => 'Success')).once
|
95
|
+
|
96
|
+
assert_equal @report.generate(:pdf, :option => :value), 'Success'
|
87
97
|
end
|
88
98
|
|
89
|
-
def
|
90
|
-
flexmock(
|
91
|
-
should_receive(:
|
99
|
+
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_omitted
|
100
|
+
flexmock(ThinReports::Generator).
|
101
|
+
should_receive(:new).
|
102
|
+
with(:pdf, @report, {:option => :value}).
|
103
|
+
and_return(flexmock(:generate => 'Success')).once
|
92
104
|
|
93
|
-
assert_equal @report.
|
105
|
+
assert_equal @report.generate(:option => :value), 'Success'
|
94
106
|
end
|
95
107
|
|
96
|
-
def
|
97
|
-
flexmock(
|
98
|
-
|
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
|
99
111
|
|
100
|
-
|
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
|
+
|
132
|
+
def test_events_should_return_Report_Events
|
133
|
+
assert_instance_of ThinReports::Report::Events, @report.events
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_page_should_return_the_current_page
|
137
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
138
|
+
@report.start_new_page
|
139
|
+
|
140
|
+
assert_instance_of ThinReports::Core::Page, @report.page
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_page_count_should_return_total_page_count
|
144
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
145
|
+
2.times { @report.start_new_page }
|
146
|
+
|
147
|
+
assert_equal @report.page_count, 2
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_finalize_should_finalize_report
|
151
|
+
@report.finalize
|
152
|
+
assert_equal @report.finalized?, true
|
101
153
|
end
|
102
154
|
|
103
|
-
def
|
104
|
-
assert_equal @report.
|
155
|
+
def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
|
156
|
+
assert_equal @report.finalized?, false
|
105
157
|
end
|
106
158
|
|
107
|
-
def
|
159
|
+
def test_finalized_asker_should_return_true_when_report_is_already_finalized
|
108
160
|
@report.finalize
|
109
161
|
assert_equal @report.finalized?, true
|
110
162
|
end
|
111
163
|
|
112
|
-
def
|
164
|
+
def test_Base_create_should_finalize_report
|
113
165
|
report = Report::Base.create do |r|
|
114
166
|
assert_instance_of Report::Base, r
|
115
167
|
end
|
116
168
|
assert_equal report.finalized?, true
|
117
169
|
end
|
118
170
|
|
119
|
-
def
|
171
|
+
def test_Base_create_should_raise_when_no_block_given
|
120
172
|
assert_raises ArgumentError do
|
121
173
|
Report::Base.create
|
122
174
|
end
|
123
175
|
end
|
124
176
|
|
125
|
-
def
|
177
|
+
def test_Base_generate_should_properly_generate_when_type_is_specified
|
126
178
|
flexmock(Report::Base).new_instances.
|
127
|
-
should_receive(:generate).
|
179
|
+
should_receive(:generate).
|
180
|
+
with(:pdf, :option => :value).once
|
128
181
|
|
129
182
|
flexmock(Report::Base).
|
130
|
-
should_receive(:create).
|
183
|
+
should_receive(:create).
|
184
|
+
with({:layout => 'layout.tlf'}, Proc).
|
131
185
|
and_return(Report::Base.new).once
|
132
186
|
|
133
187
|
Report::Base.generate(:pdf, :report => {:layout => 'layout.tlf'},
|
134
188
|
:generator => {:option => :value}) {}
|
135
189
|
end
|
136
190
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
191
|
+
def test_Base_generate_should_properly_generate_when_type_is_omitted
|
192
|
+
flexmock(Report::Base).new_instances.
|
193
|
+
should_receive(:generate).
|
194
|
+
with({}).once
|
195
|
+
|
196
|
+
flexmock(Report::Base).
|
197
|
+
should_receive(:create).
|
198
|
+
with({}, Proc).
|
199
|
+
and_return(Report::Base.new).once
|
200
|
+
|
201
|
+
Report::Base.generate {}
|
141
202
|
end
|
142
203
|
|
143
|
-
def
|
204
|
+
def test_Base_generate_file_should_properly_generate_file_when_type_is_specified
|
144
205
|
flexmock(Report::Base).new_instances.
|
145
|
-
should_receive(:generate_file).
|
206
|
+
should_receive(:generate_file).
|
207
|
+
with(:pdf, 'output.pdf', {}).once
|
208
|
+
|
209
|
+
flexmock(Report::Base).
|
210
|
+
should_receive(:create).
|
211
|
+
with({:layout => 'layout.tlf'}, Proc).
|
212
|
+
and_return(Report::Base.new).once
|
146
213
|
|
214
|
+
Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'}) {}
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_Base_generate_file_should_properly_generate_file_when_type_is_omitted
|
218
|
+
flexmock(Report::Base).new_instances.
|
219
|
+
should_receive(:generate_file).
|
220
|
+
with('output.pdf', :option => :value).once
|
221
|
+
|
147
222
|
flexmock(Report::Base).
|
148
|
-
should_receive(:create).
|
223
|
+
should_receive(:create).
|
224
|
+
with({}, Proc).
|
149
225
|
and_return(Report::Base.new).once
|
150
226
|
|
151
|
-
Report::Base.generate_file(
|
152
|
-
:generator => {:option => :value}) {}
|
227
|
+
Report::Base.generate_file('output.pdf', :generator => {:option => :value}) {}
|
153
228
|
end
|
154
229
|
|
155
|
-
def
|
230
|
+
def test_Base_generate_should_raise_when_no_block_given
|
231
|
+
assert_raises ArgumentError do
|
232
|
+
Report::Base.generate(:pdf)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_Base_generate_file_should_raise_when_no_block_given
|
156
237
|
assert_raises ArgumentError do
|
157
238
|
Report::Base.generate_file(:pdf, 'output.pdf')
|
158
239
|
end
|
159
240
|
end
|
160
241
|
|
161
|
-
def
|
162
|
-
Report::Base.send(:
|
163
|
-
assert_equal
|
242
|
+
def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
|
243
|
+
report, generator = Report::Base.send(:extract_options!, [{:report => {:layout => 'hoge.tlf'}}])
|
244
|
+
assert_equal report[:layout], 'hoge.tlf'
|
164
245
|
end
|
165
246
|
|
166
|
-
def
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
assert_equal options[:report], {:layout => 'layout.tlf'}
|
172
|
-
assert_equal options[:generator], {:option => :value}
|
247
|
+
def test_Base_extract_options_should_operate_an_argument_destructively
|
248
|
+
args = [:pdf, 'output.pdf', {:report => {:layout => 'foo.tlf'}}]
|
249
|
+
Report::Base.send(:extract_options!, args)
|
250
|
+
assert_equal args, [:pdf, 'output.pdf']
|
173
251
|
end
|
174
252
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
end
|
253
|
+
def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
|
254
|
+
report, generator = Report::Base.send(:extract_options!, [{:layout => 'hoge.tlf'}])
|
255
|
+
assert_equal report[:layout], 'hoge.tlf'
|
179
256
|
end
|
180
257
|
|
181
|
-
def
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
258
|
+
def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
|
259
|
+
report, generator = Report::Base.send(:extract_options!,
|
260
|
+
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf'}])
|
261
|
+
assert_equal report[:layout], 'hoge.tlf'
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
|
265
|
+
report, generator = Report::Base.send(:extract_options!,
|
266
|
+
[{:generator => {:option => 'value'}}])
|
267
|
+
assert_equal generator[:option], 'value'
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
|
271
|
+
report, generator = Report::Base.send(:extract_options!,
|
272
|
+
[{:generator => {:option => 'value1'}, :option => 'value2'}])
|
273
|
+
assert_equal generator[:option], 'value2'
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
|
277
|
+
report, generator = Report::Base.send(:extract_options!,
|
278
|
+
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf',
|
279
|
+
:generator_opt1 => 'value1', :generator_opt2 => 'value2'}])
|
280
|
+
assert_equal generator.values_at(:generator_opt1, :generator_opt2),
|
281
|
+
['value1', 'value2']
|
186
282
|
end
|
187
283
|
end
|