thinreports 0.6.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +10 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/thinreports.rb +11 -0
  6. data/lib/thinreports/core.rb +20 -0
  7. data/lib/thinreports/core/errors.rb +58 -0
  8. data/lib/thinreports/core/events.rb +71 -0
  9. data/lib/thinreports/core/ext.rb +5 -0
  10. data/lib/thinreports/core/ext/array.rb +19 -0
  11. data/lib/thinreports/core/ext/hash.rb +19 -0
  12. data/lib/thinreports/core/ext/object.rb +25 -0
  13. data/lib/thinreports/core/format.rb +14 -0
  14. data/lib/thinreports/core/format/base.rb +93 -0
  15. data/lib/thinreports/core/format/builder.rb +65 -0
  16. data/lib/thinreports/core/ordered_hash.rb +39 -0
  17. data/lib/thinreports/core/page.rb +91 -0
  18. data/lib/thinreports/core/shape.rb +53 -0
  19. data/lib/thinreports/core/shape/base.rb +16 -0
  20. data/lib/thinreports/core/shape/base/interface.rb +38 -0
  21. data/lib/thinreports/core/shape/base/internal.rb +60 -0
  22. data/lib/thinreports/core/shape/basic.rb +15 -0
  23. data/lib/thinreports/core/shape/basic/format.rb +26 -0
  24. data/lib/thinreports/core/shape/basic/interface.rb +57 -0
  25. data/lib/thinreports/core/shape/basic/internal.rb +29 -0
  26. data/lib/thinreports/core/shape/list.rb +25 -0
  27. data/lib/thinreports/core/shape/list/configuration.rb +33 -0
  28. data/lib/thinreports/core/shape/list/events.rb +30 -0
  29. data/lib/thinreports/core/shape/list/format.rb +72 -0
  30. data/lib/thinreports/core/shape/list/manager.rb +209 -0
  31. data/lib/thinreports/core/shape/list/page.rb +118 -0
  32. data/lib/thinreports/core/shape/list/page_state.rb +40 -0
  33. data/lib/thinreports/core/shape/list/section_format.rb +32 -0
  34. data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
  35. data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
  36. data/lib/thinreports/core/shape/list/store.rb +34 -0
  37. data/lib/thinreports/core/shape/manager.rb +14 -0
  38. data/lib/thinreports/core/shape/manager/format.rb +28 -0
  39. data/lib/thinreports/core/shape/manager/internal.rb +87 -0
  40. data/lib/thinreports/core/shape/manager/target.rb +85 -0
  41. data/lib/thinreports/core/shape/tblock.rb +16 -0
  42. data/lib/thinreports/core/shape/tblock/format.rb +36 -0
  43. data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
  44. data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
  45. data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
  46. data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
  47. data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
  48. data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
  49. data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
  50. data/lib/thinreports/core/shape/text.rb +15 -0
  51. data/lib/thinreports/core/shape/text/format.rb +25 -0
  52. data/lib/thinreports/core/shape/text/interface.rb +16 -0
  53. data/lib/thinreports/core/shape/text/internal.rb +17 -0
  54. data/lib/thinreports/core/utils.rb +48 -0
  55. data/lib/thinreports/generator.rb +30 -0
  56. data/lib/thinreports/generator/base.rb +49 -0
  57. data/lib/thinreports/generator/pdf.rb +63 -0
  58. data/lib/thinreports/generator/pdf/document.rb +171 -0
  59. data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
  60. data/lib/thinreports/generator/pdf/document/font.rb +59 -0
  61. data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
  62. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
  63. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
  64. data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
  65. data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
  66. data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
  67. data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
  68. data/lib/thinreports/generator/pdf/drawer.rb +16 -0
  69. data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
  70. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
  71. data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
  72. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
  73. data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
  74. data/lib/thinreports/generator/pxd.rb +75 -0
  75. data/lib/thinreports/generator/pxd/helper.rb +33 -0
  76. data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
  77. data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
  78. data/lib/thinreports/layout.rb +17 -0
  79. data/lib/thinreports/layout/base.rb +78 -0
  80. data/lib/thinreports/layout/configuration.rb +27 -0
  81. data/lib/thinreports/layout/format.rb +77 -0
  82. data/lib/thinreports/layout/version.rb +43 -0
  83. data/lib/thinreports/report.rb +31 -0
  84. data/lib/thinreports/report/base.rb +160 -0
  85. data/lib/thinreports/report/events.rb +32 -0
  86. data/lib/thinreports/report/internal.rb +131 -0
  87. data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
  88. data/resources/fonts/ipag.ttf +0 -0
  89. data/resources/fonts/ipagp.ttf +0 -0
  90. data/resources/fonts/ipam.ttf +0 -0
  91. data/resources/fonts/ipamp.ttf +0 -0
  92. data/tasks/clean.rake +6 -0
  93. data/tasks/doc.rake +13 -0
  94. data/tasks/test.rake +18 -0
  95. data/test/unit/core/ext/array_spec.rb +29 -0
  96. data/test/unit/core/ext/hash_spec.rb +29 -0
  97. data/test/unit/core/ext/object_spec.rb +30 -0
  98. data/test/unit/core/format/test_base.rb +148 -0
  99. data/test/unit/core/format/test_builder.rb +114 -0
  100. data/test/unit/core/ordered_hash_spec.rb +51 -0
  101. data/test/unit/core/shape/base/test_interface.rb +52 -0
  102. data/test/unit/core/shape/base/test_internal.rb +109 -0
  103. data/test/unit/core/shape/basic/test_format.rb +59 -0
  104. data/test/unit/core/shape/basic/test_interface.rb +70 -0
  105. data/test/unit/core/shape/basic/test_internal.rb +42 -0
  106. data/test/unit/core/shape/list/test_configuration.rb +52 -0
  107. data/test/unit/core/shape/list/test_events.rb +28 -0
  108. data/test/unit/core/shape/list/test_format.rb +71 -0
  109. data/test/unit/core/shape/list/test_page.rb +10 -0
  110. data/test/unit/core/shape/list/test_page_state.rb +31 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +46 -0
  112. data/test/unit/core/shape/list/test_section_interface.rb +52 -0
  113. data/test/unit/core/shape/list/test_section_internal.rb +30 -0
  114. data/test/unit/core/shape/list/test_store.rb +41 -0
  115. data/test/unit/core/shape/manager/test_format.rb +40 -0
  116. data/test/unit/core/shape/manager/test_internal.rb +137 -0
  117. data/test/unit/core/shape/manager/test_target.rb +109 -0
  118. data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
  119. data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
  120. data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
  121. data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
  122. data/test/unit/core/shape/tblock/test_format.rb +125 -0
  123. data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
  124. data/test/unit/core/shape/tblock/test_interface.rb +40 -0
  125. data/test/unit/core/shape/tblock/test_internal.rb +139 -0
  126. data/test/unit/core/shape/text/test_format.rb +73 -0
  127. data/test/unit/core/shape/text/test_internal.rb +21 -0
  128. data/test/unit/core/test_events.rb +91 -0
  129. data/test/unit/core/test_shape.rb +35 -0
  130. data/test/unit/core/utils_spec.rb +56 -0
  131. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
  132. data/test/unit/generator/pdf/document/test_font.rb +54 -0
  133. data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
  134. data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
  135. data/test/unit/generator/test_base.rb +51 -0
  136. data/test/unit/helper.rb +37 -0
  137. data/test/unit/layout/test_base.rb +92 -0
  138. data/test/unit/layout/test_configuration.rb +46 -0
  139. data/test/unit/layout/test_format.rb +104 -0
  140. data/test/unit/layout/test_version.rb +62 -0
  141. data/test/unit/report/test_base.rb +187 -0
  142. data/test/unit/report/test_events.rb +22 -0
  143. data/test/unit/report/test_internal.rb +234 -0
  144. data/test/unit/test_layout.rb +12 -0
  145. data/test/unit/test_report.rb +30 -0
  146. metadata +218 -0
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Base::TestInterface < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ class TestInterface < ThinReports::Core::Shape::Base::Interface
9
+ internal_delegators :m1, :m2
10
+
11
+ # For testing
12
+ # Instead, #internal method is overwritten by flexmock.
13
+ def init_internal(parent, format)
14
+ # Nothing to do
15
+ end
16
+ end
17
+
18
+ def setup
19
+ internal = flexmock(:m1 => 'm1', :m2 => 'm2')
20
+ @interface = TestInterface.new(flexmock('parent'), flexmock('format'))
21
+
22
+ flexmock(@interface, :internal => internal)
23
+ end
24
+
25
+ def test_internal_delegators_macro
26
+ assert_respond_to @interface, :m1
27
+ assert_respond_to @interface, :m2
28
+ end
29
+
30
+ def test_methods_delegated_from_internal
31
+ assert_same @interface.m1, @interface.internal.m1
32
+ assert_same @interface.m2, @interface.internal.m2
33
+ end
34
+
35
+ def test_forced_to_specify_an_internal_argument
36
+ internal = flexmock('forced_internal')
37
+ interface = TestInterface.new(flexmock('parent'), flexmock('format'),
38
+ internal)
39
+
40
+ assert_same internal, interface.internal
41
+ end
42
+
43
+ def test_copy
44
+ flexmock(@interface.internal, :copy => flexmock('new_internal'),
45
+ :format => flexmock('format'))
46
+
47
+ new_interface = @interface.copy(flexmock('new_parent'))
48
+
49
+ refute_same new_interface, @interface
50
+ assert_instance_of TestInterface, new_interface
51
+ end
52
+ end
@@ -0,0 +1,109 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Base::TestInternal < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ class TestInternal < ThinReports::Core::Shape::Base::Internal
9
+ format_delegators :m1, :m2
10
+ end
11
+
12
+ def setup
13
+ @internal = TestInternal.new(flexmock('parent'),
14
+ flexmock(:m1 => 'm1', :m2 => 'm2'))
15
+ end
16
+
17
+ def test_format_delegators_macro
18
+ assert_respond_to @internal, :m1
19
+ assert_respond_to @internal, :m2
20
+ end
21
+
22
+ def test_methods_delegated_from_format
23
+ assert_same @internal.m1, @internal.format.m1
24
+ assert_same @internal.m2, @internal.format.m2
25
+ end
26
+
27
+ def test_switch_parent!
28
+ new_parent = flexmock('new_parent')
29
+ res = @internal.switch_parent!(new_parent)
30
+
31
+ assert_same @internal, res
32
+ assert_same @internal.parent, new_parent
33
+ end
34
+
35
+ def test_available_style?
36
+ assert_operator @internal, :available_style?, :fill
37
+ assert_operator @internal, :available_style?, :stroke
38
+
39
+ refute_operator @internal, :available_style?, 'font-family'
40
+ refute_operator @internal, :available_style?, :x
41
+ end
42
+
43
+ def test_attributes
44
+ format = flexmock('format')
45
+ format.should_receive(:svg_attrs).
46
+ and_return('fill' => 'red',
47
+ 'stroke' => 'black',
48
+ 'x' => 100,
49
+ 'y' => 100,
50
+ 'width' => 200)
51
+ internal = TestInternal.new(flexmock('parent'), format)
52
+ internal.attrs['fill'] = '#ff0000'
53
+ internal.attrs['stroke'] = '#000000'
54
+
55
+ assert_equal internal.attributes, {'fill' => '#ff0000',
56
+ 'stroke' => '#000000',
57
+ 'x' => 100,
58
+ 'y' => 100,
59
+ 'width' => 200}
60
+ end
61
+
62
+ def test_copy
63
+ @internal.attrs.update('stroke' => 'red')
64
+ @internal.states.update(:value => '123')
65
+
66
+ new_internal = @internal.copy(flexmock('new_parent'))
67
+
68
+ refute_same @internal, new_internal
69
+ assert_instance_of TestInternal, new_internal
70
+
71
+ # Test for parent property
72
+ refute_same @internal.parent, new_internal.parent
73
+
74
+ # Test for format property
75
+ assert_same @internal.format, new_internal.format
76
+
77
+ # Test for attrs
78
+ args_attrs_test = [@internal.attrs, new_internal.attrs]
79
+
80
+ assert_equal(*args_attrs_test)
81
+ refute_same(*args_attrs_test)
82
+
83
+ # Test for value of attrs
84
+ args_attr_values_test = [@internal.attrs['stroke'],
85
+ new_internal.attrs['stroke']]
86
+
87
+ assert_equal(*args_attr_values_test)
88
+ refute_same(*args_attr_values_test)
89
+
90
+ @internal.attrs['fill'] = 'black'
91
+ assert_nil new_internal.attrs['fill']
92
+
93
+ # Test for states
94
+ args_states_test = [@internal.states, new_internal.states]
95
+
96
+ assert_equal(*args_states_test)
97
+ refute_same(*args_states_test)
98
+
99
+ # Test for value of states
100
+ args_state_values_test = [@internal.states[:value],
101
+ new_internal.states[:value]]
102
+
103
+ assert_equal(*args_state_values_test)
104
+ refute_same(*args_state_values_test)
105
+
106
+ @internal.states[:value].reverse!
107
+ refute_equal(*args_state_values_test)
108
+ end
109
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Basic::TestFormat < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ TEST_BASIC_FORMAT = {
9
+ "type" => "s-rect",
10
+ "id" => "rect_1",
11
+ "display" => "true",
12
+ "svg" => {
13
+ "tag" => "rect",
14
+ "attrs" => {
15
+ "stroke" => "#000000",
16
+ "stroke-width" => "1",
17
+ "fill" => "#ff0000",
18
+ "fill-opacity" => "1",
19
+ "stroke-dasharray" => "none",
20
+ "rx" => "0",
21
+ "ry" => "0",
22
+ "width" => "196.1",
23
+ "height" => "135.1",
24
+ "x" => "85",
25
+ "y" => "82"
26
+ }
27
+ }
28
+ }
29
+
30
+ # Alias
31
+ Format = ThinReports::Core::Shape::Basic::Format
32
+
33
+ def test_build_basic_format
34
+ build_basic_format
35
+ rescue => e
36
+ flunk exception_details(e, 'Building failed.')
37
+ end
38
+
39
+ def test_basic_config_readers
40
+ format = Format.new(TEST_BASIC_FORMAT)
41
+
42
+ assert_equal format.id, 'rect_1'
43
+ assert_equal format.type, 's-rect'
44
+ assert_equal format.svg_tag, 'rect'
45
+ assert_equal format.display?, true
46
+ assert_equal format.svg_attrs['stroke'], '#000000'
47
+ assert_equal format.svg_attrs['stroke-dasharray'], 'none'
48
+ end
49
+
50
+ def test_display?
51
+ format = Format.new('display' => 'false')
52
+
53
+ assert_equal format.display?, false
54
+ end
55
+
56
+ def build_basic_format
57
+ Format.build(TEST_BASIC_FORMAT)
58
+ end
59
+ end
@@ -0,0 +1,70 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Basic::TestInterface < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Basic = ThinReports::Core::Shape::Basic
10
+
11
+ def setup
12
+ format = flexmock('format')
13
+ format.should_receive(:display? => true)
14
+
15
+ @basic = Basic::Interface.new(flexmock('parent'), format)
16
+ end
17
+
18
+ def test_visible
19
+ assert_equal @basic.visible?, true
20
+ @basic.visible(false)
21
+ assert_equal @basic.visible?, false
22
+ end
23
+
24
+ def test_style
25
+ @basic.style(:fill, '#ff0000')
26
+ @basic.style(:stroke, '#0000ff')
27
+
28
+ assert_equal @basic.internal.attrs, {'fill' => '#ff0000',
29
+ 'stroke' => '#0000ff'}
30
+ assert_raises ThinReports::Errors::UnknownShapeStyleName do
31
+ @basic.style(:unknown, 'unknown value')
32
+ end
33
+ end
34
+
35
+ def test_styles
36
+ @basic.styles(:fill => 'red', :stroke => 'blue')
37
+
38
+ assert_equal @basic.internal.attrs, {'fill' => 'red',
39
+ 'stroke' => 'blue'}
40
+ assert_raises ThinReports::Errors::UnknownShapeStyleName do
41
+ @basic.styles(:fill => 'blue', :unknown => 'black')
42
+ end
43
+ end
44
+
45
+ def test_hide
46
+ @basic.hide
47
+ assert_equal @basic.visible?, false
48
+ end
49
+
50
+ def test_show
51
+ @basic.visible(false)
52
+ @basic.show
53
+ assert_equal @basic.visible?, true
54
+ end
55
+
56
+ def test_method_chain
57
+ @basic.hide.show
58
+ assert_equal @basic.visible?, true
59
+
60
+ @basic.style(:fill, 'red').hide
61
+ assert_equal @basic.internal.attrs['fill'], 'red'
62
+ assert_equal @basic.visible?, false
63
+
64
+ @basic.styles(:fill => 'red', :stroke => 'blue').style(:fill, 'black')
65
+ assert_equal @basic.internal.attrs['fill'], 'black'
66
+
67
+ @basic.visible(true).visible(false)
68
+ assert_equal @basic.visible?, false
69
+ end
70
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Basic::TestInternal < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ Basic = ThinReports::Core::Shape::Basic
9
+
10
+ def setup
11
+ format = flexmock('format')
12
+ format.should_receive(:display? => true)
13
+
14
+ @internal = Basic::Internal.new(flexmock('parent'), format)
15
+ end
16
+
17
+ def test_visible
18
+ assert_equal @internal.visible?, true
19
+
20
+ @internal.visible(false)
21
+
22
+ assert_equal @internal.visible?, false
23
+ assert_equal @internal.format.display?, true
24
+ end
25
+
26
+ def test_svg_attr
27
+ assert_empty @internal.attrs
28
+
29
+ @internal.svg_attr(:fill, 'red')
30
+ @internal.svg_attr(:stroke, 'black')
31
+
32
+ assert_equal @internal.attrs, {'fill' => 'red', 'stroke' => 'black'}
33
+ end
34
+
35
+ def test_type_of?
36
+ flexmock(@internal.format).should_receive(:type => 's-rect')
37
+
38
+ assert_equal @internal.type_of?(:basic), true
39
+ assert_equal @internal.type_of?(:rect), true
40
+ assert_equal @internal.type_of?(:tblock), false
41
+ end
42
+ end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::List::TestConfiguration < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ List = ThinReports::Core::Shape::List
9
+
10
+ def setup
11
+ @events = flexmock('events')
12
+ @store = flexmock('store')
13
+ @config = List::Configuration.new
14
+ end
15
+
16
+ def test_use_stores
17
+ flexmock(List::Store).should_receive(:init).with(::Hash).once
18
+
19
+ @config.use_stores(:a => 0, :b => 0)
20
+ end
21
+
22
+ def test_store
23
+ flexmock(List::Store).should_receive(:init => @store)
24
+
25
+ @config.use_stores(:a => 0, :b => 0)
26
+ assert_same @config.store, @store
27
+ end
28
+
29
+ def test_store_return_nil_when_uninitialized_yet
30
+ assert_nil @config.store
31
+ end
32
+
33
+ def test_copy
34
+ copied_store = flexmock('copied store')
35
+
36
+ flexmock(@store, :copy => copied_store)
37
+ flexmock(List::Store).should_receive(:init => @store)
38
+
39
+ copied_events = flexmock('copied events')
40
+
41
+ flexmock(@events, :copy => copied_events)
42
+ flexmock(List::Events).should_receive(:new => @events)
43
+
44
+ @config = List::Configuration.new
45
+ @config.use_stores(:a => 1)
46
+
47
+ copied_config = @config.copy
48
+
49
+ assert_same copied_config.events, copied_events
50
+ assert_same copied_config.store, copied_store
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::List::TestEvents < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ List = ThinReports::Core::Shape::List
9
+
10
+ def setup
11
+ @events = List::Events.new
12
+ end
13
+
14
+ def test_allowed_event_types
15
+ assert_equal @events.instance_variable_get(:@types),
16
+ [:page_footer_insert, :footer_insert]
17
+ end
18
+
19
+ def test_SectionEvent
20
+ e = List::Events::SectionEvent.new(:section_event,
21
+ :target,
22
+ :store)
23
+ assert_equal e.type, :section_event
24
+ assert_equal e.target, :target
25
+ assert_equal e.section, :target
26
+ assert_equal e.store, :store
27
+ end
28
+ end
@@ -0,0 +1,71 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::List::TestFormat < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ TEST_LIST_FORMAT = {
9
+ "type" => "s-list",
10
+ "id" => "List",
11
+ "display" => "true",
12
+ "page-footer-enabled" => "true",
13
+ "footer-enabled" => "true",
14
+ "header-enabled" => "true",
15
+ "page-break" => "true",
16
+ "content-height" => 255,
17
+ "detail" => {},
18
+ "footer" => {},
19
+ "page-footer" => {},
20
+ "header" => {},
21
+ "svg" => {
22
+ "tag" => "g",
23
+ "attrs" => {}
24
+ }
25
+ }
26
+
27
+ List = ThinReports::Core::Shape::List
28
+
29
+ def test_build_when_all_sections_enabled
30
+ flexmock(List::SectionFormat).
31
+ should_receive(:build).times(4).and_return({})
32
+
33
+ begin
34
+ format = build_format
35
+ rescue => e
36
+ flunk exception_details(e, 'Building failed.')
37
+ end
38
+
39
+ assert_equal format.sections.size, 4
40
+ [:detail, :header, :footer, :page_footer].each do |sec|
41
+ assert_includes format.sections.keys, sec
42
+ end
43
+ end
44
+
45
+ def test_build_when_page_footer_and_footer_disabled
46
+ flexmock(List::SectionFormat).
47
+ should_receive(:build).times(2).and_return({})
48
+
49
+ format = build_format('page-footer-enabled' => 'false',
50
+ 'footer-enabled' => 'false')
51
+
52
+ assert_equal format.sections.size, 2
53
+ [:detail, :header].each do |sec|
54
+ assert_includes format.sections.keys, sec
55
+ end
56
+ end
57
+
58
+ def test_config_readers
59
+ format = List::Format.new(TEST_LIST_FORMAT)
60
+
61
+ assert_equal format.height, 255
62
+ assert_equal format.auto_page_break?, true
63
+ assert_equal format.has_header?, true
64
+ assert_equal format.has_footer?, true
65
+ assert_equal format.has_page_footer?, true
66
+ end
67
+
68
+ def build_format(data = {})
69
+ List::Format.build(TEST_LIST_FORMAT.merge(data))
70
+ end
71
+ end