thinreports 0.6.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/README.rdoc +100 -0
- data/Rakefile +10 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/thinreports.rb +11 -0
- data/lib/thinreports/core.rb +20 -0
- data/lib/thinreports/core/errors.rb +58 -0
- data/lib/thinreports/core/events.rb +71 -0
- data/lib/thinreports/core/ext.rb +5 -0
- data/lib/thinreports/core/ext/array.rb +19 -0
- data/lib/thinreports/core/ext/hash.rb +19 -0
- data/lib/thinreports/core/ext/object.rb +25 -0
- data/lib/thinreports/core/format.rb +14 -0
- data/lib/thinreports/core/format/base.rb +93 -0
- data/lib/thinreports/core/format/builder.rb +65 -0
- data/lib/thinreports/core/ordered_hash.rb +39 -0
- data/lib/thinreports/core/page.rb +91 -0
- data/lib/thinreports/core/shape.rb +53 -0
- data/lib/thinreports/core/shape/base.rb +16 -0
- data/lib/thinreports/core/shape/base/interface.rb +38 -0
- data/lib/thinreports/core/shape/base/internal.rb +60 -0
- data/lib/thinreports/core/shape/basic.rb +15 -0
- data/lib/thinreports/core/shape/basic/format.rb +26 -0
- data/lib/thinreports/core/shape/basic/interface.rb +57 -0
- data/lib/thinreports/core/shape/basic/internal.rb +29 -0
- data/lib/thinreports/core/shape/list.rb +25 -0
- data/lib/thinreports/core/shape/list/configuration.rb +33 -0
- data/lib/thinreports/core/shape/list/events.rb +30 -0
- data/lib/thinreports/core/shape/list/format.rb +72 -0
- data/lib/thinreports/core/shape/list/manager.rb +209 -0
- data/lib/thinreports/core/shape/list/page.rb +118 -0
- data/lib/thinreports/core/shape/list/page_state.rb +40 -0
- data/lib/thinreports/core/shape/list/section_format.rb +32 -0
- data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
- data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
- data/lib/thinreports/core/shape/list/store.rb +34 -0
- data/lib/thinreports/core/shape/manager.rb +14 -0
- data/lib/thinreports/core/shape/manager/format.rb +28 -0
- data/lib/thinreports/core/shape/manager/internal.rb +87 -0
- data/lib/thinreports/core/shape/manager/target.rb +85 -0
- data/lib/thinreports/core/shape/tblock.rb +16 -0
- data/lib/thinreports/core/shape/tblock/format.rb +36 -0
- data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
- data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
- data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
- data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
- data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
- data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
- data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
- data/lib/thinreports/core/shape/text.rb +15 -0
- data/lib/thinreports/core/shape/text/format.rb +25 -0
- data/lib/thinreports/core/shape/text/interface.rb +16 -0
- data/lib/thinreports/core/shape/text/internal.rb +17 -0
- data/lib/thinreports/core/utils.rb +48 -0
- data/lib/thinreports/generator.rb +30 -0
- data/lib/thinreports/generator/base.rb +49 -0
- data/lib/thinreports/generator/pdf.rb +63 -0
- data/lib/thinreports/generator/pdf/document.rb +171 -0
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
- data/lib/thinreports/generator/pdf/document/font.rb +59 -0
- data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
- data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
- data/lib/thinreports/generator/pdf/drawer.rb +16 -0
- data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
- data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
- data/lib/thinreports/generator/pxd.rb +75 -0
- data/lib/thinreports/generator/pxd/helper.rb +33 -0
- data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
- data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
- data/lib/thinreports/layout.rb +17 -0
- data/lib/thinreports/layout/base.rb +78 -0
- data/lib/thinreports/layout/configuration.rb +27 -0
- data/lib/thinreports/layout/format.rb +77 -0
- data/lib/thinreports/layout/version.rb +43 -0
- data/lib/thinreports/report.rb +31 -0
- data/lib/thinreports/report/base.rb +160 -0
- data/lib/thinreports/report/events.rb +32 -0
- data/lib/thinreports/report/internal.rb +131 -0
- data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
- data/resources/fonts/ipag.ttf +0 -0
- data/resources/fonts/ipagp.ttf +0 -0
- data/resources/fonts/ipam.ttf +0 -0
- data/resources/fonts/ipamp.ttf +0 -0
- data/tasks/clean.rake +6 -0
- data/tasks/doc.rake +13 -0
- data/tasks/test.rake +18 -0
- data/test/unit/core/ext/array_spec.rb +29 -0
- data/test/unit/core/ext/hash_spec.rb +29 -0
- data/test/unit/core/ext/object_spec.rb +30 -0
- data/test/unit/core/format/test_base.rb +148 -0
- data/test/unit/core/format/test_builder.rb +114 -0
- data/test/unit/core/ordered_hash_spec.rb +51 -0
- data/test/unit/core/shape/base/test_interface.rb +52 -0
- data/test/unit/core/shape/base/test_internal.rb +109 -0
- data/test/unit/core/shape/basic/test_format.rb +59 -0
- data/test/unit/core/shape/basic/test_interface.rb +70 -0
- data/test/unit/core/shape/basic/test_internal.rb +42 -0
- data/test/unit/core/shape/list/test_configuration.rb +52 -0
- data/test/unit/core/shape/list/test_events.rb +28 -0
- data/test/unit/core/shape/list/test_format.rb +71 -0
- data/test/unit/core/shape/list/test_page.rb +10 -0
- data/test/unit/core/shape/list/test_page_state.rb +31 -0
- data/test/unit/core/shape/list/test_section_format.rb +46 -0
- data/test/unit/core/shape/list/test_section_interface.rb +52 -0
- data/test/unit/core/shape/list/test_section_internal.rb +30 -0
- data/test/unit/core/shape/list/test_store.rb +41 -0
- data/test/unit/core/shape/manager/test_format.rb +40 -0
- data/test/unit/core/shape/manager/test_internal.rb +137 -0
- data/test/unit/core/shape/manager/test_target.rb +109 -0
- data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
- data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
- data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
- data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
- data/test/unit/core/shape/tblock/test_format.rb +125 -0
- data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
- data/test/unit/core/shape/tblock/test_interface.rb +40 -0
- data/test/unit/core/shape/tblock/test_internal.rb +139 -0
- data/test/unit/core/shape/text/test_format.rb +73 -0
- data/test/unit/core/shape/text/test_internal.rb +21 -0
- data/test/unit/core/test_events.rb +91 -0
- data/test/unit/core/test_shape.rb +35 -0
- data/test/unit/core/utils_spec.rb +56 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
- data/test/unit/generator/pdf/document/test_font.rb +54 -0
- data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
- data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
- data/test/unit/generator/test_base.rb +51 -0
- data/test/unit/helper.rb +37 -0
- data/test/unit/layout/test_base.rb +92 -0
- data/test/unit/layout/test_configuration.rb +46 -0
- data/test/unit/layout/test_format.rb +104 -0
- data/test/unit/layout/test_version.rb +62 -0
- data/test/unit/report/test_base.rb +187 -0
- data/test/unit/report/test_events.rb +22 -0
- data/test/unit/report/test_internal.rb +234 -0
- data/test/unit/test_layout.rb +12 -0
- data/test/unit/test_report.rb +30 -0
- metadata +218 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::Pdf::TestParseColor < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
class TestColorParser
|
9
|
+
include ThinReports::Generator::Pdf::ParseColor
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@parser = TestColorParser.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_parse_color_with_hexcolor
|
17
|
+
assert_equal @parser.parse_color('#ff0000'), 'ff0000'
|
18
|
+
assert_equal @parser.parse_color('000000'), '000000'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parse_color_with_colorname
|
22
|
+
assert_equal @parser.parse_color('red'), 'ff0000'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_color_with_colorname_raise_when_unknown_name_given
|
26
|
+
assert_raises ThinReports::Errors::UnsupportedColorName do
|
27
|
+
@parser.parse_color('whitesmoke')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Generator::TestBase < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Generator = ThinReports::Generator
|
10
|
+
|
11
|
+
class FooHoge < Generator::Base; end
|
12
|
+
|
13
|
+
def test_subcclasses_are_registered_as_generator_when_inherited
|
14
|
+
assert_same FooHoge, Generator.registry.delete(:foohoge)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize_finalize_given_the_report
|
18
|
+
report = flexmock('report').
|
19
|
+
should_receive(:finalize).once.
|
20
|
+
should_receive(:internal).once.mock
|
21
|
+
|
22
|
+
Generator::Base.new(report)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_generate_is_abstract_method
|
26
|
+
assert_raises NotImplementedError do
|
27
|
+
new_generator.generate
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_generate_file_is_abstract_method
|
32
|
+
assert_raises NotImplementedError do
|
33
|
+
new_generator.generate_file('output.pdf')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_default_layout
|
38
|
+
generator = new_generator
|
39
|
+
flexmock(generator.report).
|
40
|
+
should_receive(:default_layout).and_return(flexmock('default_layout')).once
|
41
|
+
|
42
|
+
assert_equal generator.default_layout.flexmock_name, 'default_layout'
|
43
|
+
end
|
44
|
+
|
45
|
+
def new_generator
|
46
|
+
report = flexmock('report').
|
47
|
+
should_receive(:finalize).
|
48
|
+
should_receive(:internal).and_return(flexmock('report_internal')).mock
|
49
|
+
Generator::Base.new(report)
|
50
|
+
end
|
51
|
+
end
|
data/test/unit/helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
require 'minitest/unit'
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'flexmock'
|
8
|
+
rescue LoadError => e
|
9
|
+
$stderr.puts 'To run the unit tests, you need minitest and flexmock.'
|
10
|
+
raise e
|
11
|
+
end
|
12
|
+
|
13
|
+
# Run a test automaticaly
|
14
|
+
MiniTest::Unit.autorun
|
15
|
+
|
16
|
+
# Load misc
|
17
|
+
require 'digest/sha1'
|
18
|
+
|
19
|
+
module ThinReports::TestHelpers
|
20
|
+
include FlexMock::TestCase
|
21
|
+
|
22
|
+
def clean_whitespaces(str)
|
23
|
+
str.gsub(/^\s*|\n\s*/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
def skip_if_ruby19
|
27
|
+
if RUBY_VERSION > '1.9'
|
28
|
+
skip('This test is not required more than Ruby 1.9.')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def skip_if_ruby18
|
33
|
+
if RUBY_VERSION < '1.9'
|
34
|
+
skip('This test is not required Ruby 1.8 below.')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Layout::TestBase < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Layout = ThinReports::Layout::Base
|
10
|
+
|
11
|
+
def test_load_format_raise_error_when_file_not_found
|
12
|
+
assert_raises ThinReports::Errors::LayoutFileNotFound do
|
13
|
+
Layout.load_format('dummy.tlf')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_load_format
|
18
|
+
flexmock(File).should_receive(:exists? => true).once
|
19
|
+
flexmock(ThinReports::Layout::Format).should_receive(:build).once
|
20
|
+
|
21
|
+
Layout.load_format('sample.tlf')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_load_format_when_omit_the_file_extension
|
25
|
+
specified_name = 'sample'
|
26
|
+
resolved_name = 'sample.tlf'
|
27
|
+
|
28
|
+
flexmock(File).
|
29
|
+
should_receive(:exists?).with(resolved_name).and_return(true).once
|
30
|
+
flexmock(ThinReports::Layout::Format).should_receive(:build).once
|
31
|
+
|
32
|
+
Layout.load_format(specified_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_Page_when_not_defined_PageHelpers
|
36
|
+
assert_same Layout.Page, ThinReports::Core::Page
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_Page_when_defined_PageHelpers
|
40
|
+
Layout.send(:PageHelpers, &proc{})
|
41
|
+
|
42
|
+
refute_same Layout.Page, ThinReports::Core::Page
|
43
|
+
|
44
|
+
# Teardown
|
45
|
+
ThinReports::Layout::Base.send(:remove_const, :Page)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_PageHelpers
|
49
|
+
Layout.send(:PageHelpers) do
|
50
|
+
def foo
|
51
|
+
'foo'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_same Layout::Page.superclass, ThinReports::Core::Page
|
56
|
+
assert Layout::Page.method_defined?(:foo)
|
57
|
+
|
58
|
+
# Teardown
|
59
|
+
ThinReports::Layout::Base.send(:remove_const, :Page)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_initialize_with_specified_id
|
63
|
+
layout = init_layout(:id => :foo)
|
64
|
+
assert_equal layout.id, :foo
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_default?
|
68
|
+
assert_equal init_layout.default?, true
|
69
|
+
assert_equal init_layout(:id => :foo).default?, false
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_config
|
73
|
+
layout = init_layout
|
74
|
+
assert_instance_of ThinReports::Layout::Configuration, layout.config
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_init_new_page
|
78
|
+
parent = flexmock('parent')
|
79
|
+
layout = init_layout
|
80
|
+
|
81
|
+
# Should call ThinReports::Core::Page#new with parent and layout.
|
82
|
+
flexmock(ThinReports::Core::Page).
|
83
|
+
should_receive(:new).with(parent, layout).once
|
84
|
+
|
85
|
+
layout.init_new_page(parent)
|
86
|
+
end
|
87
|
+
|
88
|
+
def init_layout(options = {})
|
89
|
+
flexmock(Layout).should_receive(:load_format => flexmock('format'))
|
90
|
+
Layout.new('dummy.tlf', options)
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Layout::TestConfiguration < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Configuration = ThinReports::Layout::Configuration
|
10
|
+
|
11
|
+
def setup
|
12
|
+
layout = flexmock('layout')
|
13
|
+
flexmock(layout).should_receive(:format => flexmock('layout_format'))
|
14
|
+
|
15
|
+
@config = Configuration.new(layout)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_undef_items_method
|
19
|
+
refute_respond_to @config, :items
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_undef_values_method
|
23
|
+
refute_respond_to @config, :values
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_properly_set_init_item_handler
|
27
|
+
list_format = flexmock('list_format').should_receive(:type => 's-list').once.mock
|
28
|
+
list_config = flexmock('list_config').should_receive(:new).once.mock
|
29
|
+
|
30
|
+
flexmock(ThinReports::Core::Shape).
|
31
|
+
should_receive(:Configuration).with('s-list').and_return(list_config).once
|
32
|
+
|
33
|
+
@config.manager.init_item(list_format)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_activate
|
37
|
+
list_config = flexmock('list_config').should_receive(:copy).once.mock
|
38
|
+
@config.manager.shapes[:foo] = list_config
|
39
|
+
|
40
|
+
@config.activate(:foo)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_activate_return_nil_when_unknown_shape_id
|
44
|
+
assert_nil @config.activate(:unknown)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Layout::TestFormat < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
TEST_SIMPLE_FORMAT = <<-'EOF'
|
9
|
+
{
|
10
|
+
"built-at":"",
|
11
|
+
"version":"%s",
|
12
|
+
"encoding":"utf-8",
|
13
|
+
"updated-at":"20110528120710",
|
14
|
+
"finger-print":-860627816,
|
15
|
+
"config":{
|
16
|
+
"title":"Sample Layout",
|
17
|
+
"page":{
|
18
|
+
"paper-type":"A4",
|
19
|
+
"width":null,
|
20
|
+
"height":null,
|
21
|
+
"orientation":"portrait",
|
22
|
+
"margin-top":"20",
|
23
|
+
"margin-bottom":"20",
|
24
|
+
"margin-left":"20",
|
25
|
+
"margin-right":"20"
|
26
|
+
},
|
27
|
+
"option":{}
|
28
|
+
},
|
29
|
+
"svg":"<!--SHAPE{\"type\":\"s-rect\",\"id\":\"rect1\"}SHAPE-->
|
30
|
+
<!--SHAPE{\"type\":\"s-image\",\"id\":\"image1\"}SHAPE-->
|
31
|
+
<!--SHAPE{\"type\":\"s-tblock\",\"id\":\"tblock1\"}SHAPE-->
|
32
|
+
<!--SHAPE{\"type\":\"s-tblock\",\"id\":\"tblock2\"}SHAPE-->"
|
33
|
+
}
|
34
|
+
EOF
|
35
|
+
|
36
|
+
# Alias
|
37
|
+
Shape = ThinReports::Core::Shape
|
38
|
+
Layout = ThinReports::Layout
|
39
|
+
|
40
|
+
def test_build_simple_format
|
41
|
+
flexmock(Layout::Format).
|
42
|
+
should_receive(:read_format_file).and_return(create_raw_format).once
|
43
|
+
|
44
|
+
begin
|
45
|
+
format = Layout::Format.build('dummy.tlf', :force => true)
|
46
|
+
rescue => e
|
47
|
+
flunk exception_details(e, 'Faile to build.')
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal format.shapes.size, 4
|
51
|
+
[:rect1, :image1, :tblock1, :tblock2].each do |shape|
|
52
|
+
assert_includes format.shapes.keys, shape
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_identifier_return_the_digest_value
|
57
|
+
flexmock(Layout::Format).
|
58
|
+
should_receive(:read_format_file).and_return(create_raw_format).once
|
59
|
+
|
60
|
+
format = Layout::Format.build('dummy.tlf')
|
61
|
+
expect = Digest::SHA1.hexdigest(create_raw_format)
|
62
|
+
|
63
|
+
assert_equal format.identifier, expect.to_sym
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_always_return_the_same_result_when_build_in_cached_mode
|
67
|
+
flexmock(Layout::Format).
|
68
|
+
should_receive(:read_format_file).and_return(create_raw_format).times(2)
|
69
|
+
|
70
|
+
# Run building with in cached mode.
|
71
|
+
# First time, not be cached.
|
72
|
+
result1 = Layout::Format.build('dummy.tlf')
|
73
|
+
|
74
|
+
# Later, be cached if format is same.
|
75
|
+
result2 = Layout::Format.build('dummy.tlf')
|
76
|
+
|
77
|
+
assert_same result1, result2
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_build_raise_when_layout_file_is_incompatible
|
81
|
+
original_rules = Layout::Version::REQUIRED_RULES.dup
|
82
|
+
Layout::Version::REQUIRED_RULES.replace(['== 2.0.0'])
|
83
|
+
|
84
|
+
flexmock(Layout::Format).
|
85
|
+
should_receive(:read_format_file).and_return(create_raw_format('1.0.0'))
|
86
|
+
|
87
|
+
assert_raises ThinReports::Errors::IncompatibleLayoutFormat do
|
88
|
+
Layout::Format.build('dummy.tlf')
|
89
|
+
end
|
90
|
+
ensure
|
91
|
+
Layout::Version::REQUIRED_RULES.replace(original_rules)
|
92
|
+
end
|
93
|
+
|
94
|
+
def setup
|
95
|
+
flexmock(Shape::Tblock::Format).
|
96
|
+
should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
|
97
|
+
flexmock(Shape::Basic::Format).
|
98
|
+
should_receive(:build).and_return {|f| flexmock(:id => f['id']) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_raw_format(version = ThinReports::VERSION)
|
102
|
+
clean_whitespaces(TEST_SIMPLE_FORMAT) % version
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Layout::TestVersion < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Version = ThinReports::Layout::Version
|
10
|
+
|
11
|
+
def test_comparable_version
|
12
|
+
assert_equal Version.comparable_version('0.6.0'), '0.6.0.99'
|
13
|
+
assert_equal Version.comparable_version('0.6.0.pre'), '0.6.0.1'
|
14
|
+
assert_equal Version.comparable_version('0.6.0.pre2'), '0.6.0.2'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_compare_with_simple_rule
|
18
|
+
assert Version.compare('0.6.0', '== 0.6.0')
|
19
|
+
refute Version.compare('0.6.0', '== 0.6.1')
|
20
|
+
|
21
|
+
refute Version.compare('0.6.0', '> 0.6.0')
|
22
|
+
assert Version.compare('0.6.1', '> 0.6.0')
|
23
|
+
assert Version.compare('0.6.0', '> 0.5.9')
|
24
|
+
assert Version.compare('0.6.0', '> 0.6.0.pre3')
|
25
|
+
assert Version.compare('0.6.0.pre2', '> 0.6.0.pre')
|
26
|
+
|
27
|
+
assert Version.compare('0.6.0.pre', '< 0.6.0.pre3')
|
28
|
+
|
29
|
+
assert Version.compare('0.6.0', '>= 0.6.0')
|
30
|
+
assert Version.compare('0.6.0', '<= 0.6.0')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_compare_with_multiple_rules
|
34
|
+
assert Version.compare('0.6.0', '> 0.5.0', '< 1.0.0')
|
35
|
+
refute Version.compare('0.6.5', '> 0.6.0', '< 0.6.4')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_compatible?
|
39
|
+
required_rules('== 0.6.0.pre3') do
|
40
|
+
assert Version.compatible?('0.6.0.pre3')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_required_rules_inspect
|
45
|
+
required_rules('== 0.6.0.pre3') do
|
46
|
+
assert_equal Version.required_rules_inspect, '(== 0.6.0.pre3)'
|
47
|
+
end
|
48
|
+
required_rules('> 0.6.0', '< 0.7.0') do
|
49
|
+
assert_equal Version.required_rules_inspect, '(> 0.6.0 and < 0.7.0)'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def required_rules(*rules, &block)
|
54
|
+
original_required_rules = Version::REQUIRED_RULES.dup
|
55
|
+
|
56
|
+
Version::REQUIRED_RULES.clear
|
57
|
+
rules.each {|rule| Version::REQUIRED_RULES << rule }
|
58
|
+
block.call
|
59
|
+
ensure
|
60
|
+
original_required_rules.each {|rule| Version::REQUIRED_RULES << rule }
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit/helper'
|
4
|
+
|
5
|
+
class ThinReports::Report::TestBase < MiniTest::Unit::TestCase
|
6
|
+
include ThinReports::TestHelpers
|
7
|
+
|
8
|
+
# Alias
|
9
|
+
Report = ThinReports::Report
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@report = Report::Base.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize_with_options
|
16
|
+
flexmock(Report::Internal).
|
17
|
+
should_receive(:new).with(Report::Base, {:layout => 'layout.tlf'}).
|
18
|
+
and_return(flexmock('report_internal')).once
|
19
|
+
|
20
|
+
report = Report::Base.new(:layout => 'layout.tlf')
|
21
|
+
assert_equal report.internal.flexmock_name, 'report_internal'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_use_layout
|
25
|
+
flexmock(@report.internal).
|
26
|
+
should_receive(:register_layout).with('layout.tlf', {:default => true}).
|
27
|
+
and_return(flexmock('layout_config')).once
|
28
|
+
|
29
|
+
assert_equal @report.use_layout('layout.tlf', :default => true).flexmock_name,
|
30
|
+
'layout_config'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_start_new_page
|
34
|
+
layout = flexmock('layout')
|
35
|
+
layout.should_receive(:init_new_page).once
|
36
|
+
|
37
|
+
flexmock(@report.internal).
|
38
|
+
should_receive(:load_layout).and_return(layout).once.
|
39
|
+
should_receive(:add_page).and_return(flexmock('new_page')).once
|
40
|
+
|
41
|
+
assert_equal @report.start_new_page.flexmock_name, 'new_page'
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_start_new_page_raise_when_no_layout_registered_yet
|
45
|
+
assert_raises ThinReports::Errors::NoRegisteredLayoutFound do
|
46
|
+
@report.start_new_page(:layout => :unknown)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_blank_page
|
51
|
+
blank_page = flexmock('blank_page')
|
52
|
+
|
53
|
+
flexmock(ThinReports::Core::BlankPage).
|
54
|
+
should_receive(:new).and_return(blank_page)
|
55
|
+
|
56
|
+
flexmock(@report.internal).
|
57
|
+
should_receive(:add_page).with(blank_page)
|
58
|
+
|
59
|
+
@report.add_blank_page
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_layout_with_nil_return_the_default_layout
|
63
|
+
flexmock(@report.internal).
|
64
|
+
should_receive(:default_layout).and_return(flexmock('default_layout'))
|
65
|
+
|
66
|
+
assert_equal @report.layout.flexmock_name, 'default_layout'
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_layout_with_id_raise_when_no_layout_found
|
70
|
+
assert_raises ThinReports::Errors::UnknownLayoutId do
|
71
|
+
@report.layout(:unknown)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_generate
|
76
|
+
setup_generator do |g|
|
77
|
+
g.should_receive(:generate).and_return('output').once
|
78
|
+
end
|
79
|
+
assert_equal @report.generate(:pdf, {:option => :value}), 'output'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_generate_file
|
83
|
+
setup_generator do |g|
|
84
|
+
g.should_receive(:generate_file).with(String).once
|
85
|
+
end
|
86
|
+
@report.generate_file(:pdf, 'output.pdf', {:option => :value})
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_events
|
90
|
+
flexmock(@report.internal).
|
91
|
+
should_receive(:events).and_return(flexmock('report_events')).once
|
92
|
+
|
93
|
+
assert_equal @report.events.flexmock_name, 'report_events'
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_page
|
97
|
+
flexmock(@report.internal).
|
98
|
+
should_receive(:page).and_return(flexmock('current_page')).once
|
99
|
+
|
100
|
+
assert_equal @report.page.flexmock_name, 'current_page'
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_page_count
|
104
|
+
assert_equal @report.page_count, 0
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_finalize
|
108
|
+
@report.finalize
|
109
|
+
assert_equal @report.finalized?, true
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_Base_create
|
113
|
+
report = Report::Base.create do |r|
|
114
|
+
assert_instance_of Report::Base, r
|
115
|
+
end
|
116
|
+
assert_equal report.finalized?, true
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_Base_create_raise_when_no_block_given
|
120
|
+
assert_raises ArgumentError do
|
121
|
+
Report::Base.create
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_Base_generate
|
126
|
+
flexmock(Report::Base).new_instances.
|
127
|
+
should_receive(:generate).with(:pdf, Hash).once
|
128
|
+
|
129
|
+
flexmock(Report::Base).
|
130
|
+
should_receive(:create).with(Hash, Proc).
|
131
|
+
and_return(Report::Base.new).once
|
132
|
+
|
133
|
+
Report::Base.generate(:pdf, :report => {:layout => 'layout.tlf'},
|
134
|
+
:generator => {:option => :value}) {}
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_Base_generate_raise_when_no_block_given
|
138
|
+
assert_raises ArgumentError do
|
139
|
+
Report::Base.generate(:pdf)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_Base_generate_file
|
144
|
+
flexmock(Report::Base).new_instances.
|
145
|
+
should_receive(:generate_file).with(:pdf, String, Hash).once
|
146
|
+
|
147
|
+
flexmock(Report::Base).
|
148
|
+
should_receive(:create).with(Hash, Proc).
|
149
|
+
and_return(Report::Base.new).once
|
150
|
+
|
151
|
+
Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'},
|
152
|
+
:generator => {:option => :value}) {}
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_Base_generate_file_raise_when_no_block_given
|
156
|
+
assert_raises ArgumentError do
|
157
|
+
Report::Base.generate_file(:pdf, 'output.pdf')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_Base_init_generate_params_with_empty_options
|
162
|
+
Report::Base.send(:init_generate_params, options = {}) {}
|
163
|
+
assert_equal options.values_at(:report, :generator), [{}, {}]
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_Base_init_generate_params_with_configured_options
|
167
|
+
options = {:report => {:layout => 'layout.tlf'},
|
168
|
+
:generator => {:option => :value}}
|
169
|
+
Report::Base.send(:init_generate_params, options) {}
|
170
|
+
|
171
|
+
assert_equal options[:report], {:layout => 'layout.tlf'}
|
172
|
+
assert_equal options[:generator], {:option => :value}
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_Base_init_generate_params_raise_when_no_block_given
|
176
|
+
assert_raises ArgumentError do
|
177
|
+
Report::Base.send(:init_generate_params)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def setup_generator(&block)
|
182
|
+
block.call(generator = flexmock('generator'))
|
183
|
+
|
184
|
+
flexmock(ThinReports::Generator).
|
185
|
+
should_receive(:new).with(:pdf, @report, Hash).and_return(generator)
|
186
|
+
end
|
187
|
+
end
|