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.
Files changed (158) hide show
  1. data/README.rdoc +37 -32
  2. data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
  3. data/lib/thinreports.rb +2 -1
  4. data/lib/thinreports/config.rb +21 -0
  5. data/lib/thinreports/core/errors.rb +14 -1
  6. data/lib/thinreports/core/format/builder.rb +6 -1
  7. data/lib/thinreports/core/page.rb +6 -6
  8. data/lib/thinreports/core/shape.rb +8 -9
  9. data/lib/thinreports/core/shape/base/internal.rb +6 -12
  10. data/lib/thinreports/core/shape/basic.rb +3 -0
  11. data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
  12. data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
  13. data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
  14. data/lib/thinreports/core/shape/basic/interface.rb +37 -11
  15. data/lib/thinreports/core/shape/basic/internal.rb +3 -12
  16. data/lib/thinreports/core/shape/image_block.rb +15 -0
  17. data/lib/thinreports/core/shape/image_block/format.rb +13 -0
  18. data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
  19. data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
  20. data/lib/thinreports/core/shape/list/events.rb +19 -2
  21. data/lib/thinreports/core/shape/list/manager.rb +17 -4
  22. data/lib/thinreports/core/shape/list/page.rb +2 -2
  23. data/lib/thinreports/core/shape/list/page_state.rb +4 -0
  24. data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
  25. data/lib/thinreports/core/shape/manager/format.rb +1 -1
  26. data/lib/thinreports/core/shape/manager/internal.rb +24 -11
  27. data/lib/thinreports/core/shape/manager/target.rb +2 -2
  28. data/lib/thinreports/core/shape/style.rb +15 -0
  29. data/lib/thinreports/core/shape/style/base.rb +149 -0
  30. data/lib/thinreports/core/shape/style/basic.rb +17 -0
  31. data/lib/thinreports/core/shape/style/graphic.rb +60 -0
  32. data/lib/thinreports/core/shape/style/text.rb +138 -0
  33. data/lib/thinreports/core/shape/text/internal.rb +4 -0
  34. data/lib/thinreports/core/shape/text_block.rb +16 -0
  35. data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
  36. data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
  37. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
  38. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
  39. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
  40. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
  41. data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
  42. data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
  43. data/lib/thinreports/core/utils.rb +0 -8
  44. data/lib/thinreports/generator.rb +2 -2
  45. data/lib/thinreports/generator/configuration.rb +30 -0
  46. data/lib/thinreports/generator/pdf.rb +13 -10
  47. data/lib/thinreports/generator/pdf/configuration.rb +28 -0
  48. data/lib/thinreports/generator/pdf/document.rb +16 -56
  49. data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
  50. data/lib/thinreports/generator/pdf/document/font.rb +25 -9
  51. data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
  52. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
  53. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
  54. data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
  55. data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
  56. data/lib/thinreports/generator/pdf/document/page.rb +70 -0
  57. data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
  58. data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
  59. data/lib/thinreports/generator/pdf/drawer.rb +1 -1
  60. data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
  61. data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
  62. data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
  63. data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
  64. data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
  65. data/lib/thinreports/layout/format.rb +2 -2
  66. data/lib/thinreports/layout/version.rb +2 -2
  67. data/lib/thinreports/report/base.rb +68 -31
  68. data/tasks/test.rake +48 -4
  69. data/test/benchmark/basic_estimate.tlf +1 -0
  70. data/test/benchmark/bench_basic_estimate.rb +95 -0
  71. data/test/case/character_spacing/character_spacing.rb +7 -0
  72. data/test/case/character_spacing/character_spacing.tlf +1 -0
  73. data/test/case/dynamic_image/dynamic_image.rb +41 -0
  74. data/test/case/dynamic_image/dynamic_image.tlf +1 -0
  75. data/test/case/dynamic_image/img200x100.png +0 -0
  76. data/test/case/dynamic_image/img50x50.png +0 -0
  77. data/test/case/dynamic_style/dynamic_style.rb +154 -0
  78. data/test/case/dynamic_style/dynamic_style.tlf +1 -0
  79. data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
  80. data/test/case/dynamic_style/image.png +0 -0
  81. data/test/case/eudc/eudc.rb +20 -0
  82. data/test/case/eudc/eudc.tlf +1 -0
  83. data/test/case/eudc/eudc.ttf +0 -0
  84. data/test/case/helper.rb +27 -0
  85. data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
  86. data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
  87. data/test/case/list_events/list_events.rb +32 -0
  88. data/test/case/list_events/list_events.tlf +1 -0
  89. data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
  90. data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
  91. data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
  92. data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
  93. data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
  94. data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
  95. data/test/case/tblock_styles/tblock_styles.rb +27 -0
  96. data/test/case/tblock_styles/tblock_styles.tlf +1 -0
  97. data/test/case/text_align/text_align.rb +9 -0
  98. data/test/case/text_align/text_align.tlf +1 -0
  99. data/test/unit/core/shape/base/test_internal.rb +65 -85
  100. data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
  101. data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
  102. data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
  103. data/test/unit/core/shape/basic/test_interface.rb +84 -36
  104. data/test/unit/core/shape/basic/test_internal.rb +32 -24
  105. data/test/unit/core/shape/image_block/test_format.rb +58 -0
  106. data/test/unit/core/shape/image_block/test_interface.rb +23 -0
  107. data/test/unit/core/shape/image_block/test_internal.rb +28 -0
  108. data/test/unit/core/shape/list/test_events.rb +19 -11
  109. data/test/unit/core/shape/list/test_manager.rb +112 -0
  110. data/test/unit/core/shape/list/test_page.rb +57 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  112. data/test/unit/core/shape/list/test_section_interface.rb +37 -30
  113. data/test/unit/core/shape/list/test_section_internal.rb +39 -14
  114. data/test/unit/core/shape/manager/test_format.rb +12 -18
  115. data/test/unit/core/shape/manager/test_internal.rb +127 -93
  116. data/test/unit/core/shape/manager/test_target.rb +63 -56
  117. data/test/unit/core/shape/styles/test_base.rb +219 -0
  118. data/test/unit/core/shape/styles/test_basic.rb +24 -0
  119. data/test/unit/core/shape/styles/test_graphic.rb +69 -0
  120. data/test/unit/core/shape/styles/test_text.rb +318 -0
  121. data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
  122. data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
  123. data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
  124. data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
  125. data/test/unit/core/shape/text_block/test_format.rb +160 -0
  126. data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
  127. data/test/unit/core/shape/text_block/test_interface.rb +46 -0
  128. data/test/unit/core/shape/text_block/test_internal.rb +128 -0
  129. data/test/unit/core/test_shape.rb +31 -6
  130. data/test/unit/data/basic_layout1.tlf +1 -0
  131. data/test/unit/data/basic_layout2.tlf +1 -0
  132. data/test/unit/data/basic_list_layout.tlf +1 -0
  133. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
  134. data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
  135. data/test/unit/generator/pdf/document/test_font.rb +21 -6
  136. data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
  137. data/test/unit/generator/pdf/document/test_page.rb +95 -0
  138. data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
  139. data/test/unit/generator/pdf/test_configuration.rb +24 -0
  140. data/test/unit/generator/pdf/test_document.rb +28 -0
  141. data/test/unit/generator/test_configuration.rb +25 -0
  142. data/test/unit/generator/test_pdf.rb +19 -0
  143. data/test/unit/helper.rb +18 -0
  144. data/test/unit/layout/test_format.rb +24 -7
  145. data/test/unit/layout/test_version.rb +61 -27
  146. data/test/unit/report/test_base.rb +185 -89
  147. data/test/unit/test_config.rb +22 -0
  148. data/test/unit/test_report.rb +4 -4
  149. metadata +94 -43
  150. data/lib/thinreports/core/shape/tblock.rb +0 -16
  151. data/lib/thinreports/generator/pxd.rb +0 -75
  152. data/lib/thinreports/generator/pxd/helper.rb +0 -33
  153. data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
  154. data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
  155. data/tasks/clean.rake +0 -6
  156. data/test/unit/core/shape/tblock/test_format.rb +0 -125
  157. data/test/unit/core/shape/tblock/test_interface.rb +0 -40
  158. data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -8,23 +8,48 @@ class ThinReports::Core::Shape::List::TestSectionInternal < MiniTest::Unit::Test
8
8
  # Alias
9
9
  List = ThinReports::Core::Shape::List
10
10
 
11
- def setup
12
- parent = flexmock('parent')
13
- format = flexmock(:height => 100,
14
- :relative_left => 100,
15
- :relative_top => 200,
16
- :svg_tag => 'g')
17
- @internal = List::SectionInternal.new(parent, format)
11
+ def create_internal(format_config = {})
12
+ List::SectionInternal.new(flexmock('parent'),
13
+ List::SectionFormat.new(format_config))
18
14
  end
19
15
 
20
- def test_move_top_to
21
- @internal.move_top_to(100)
22
- assert_equal @internal.states[:relative_top], 100
16
+ def test_height_should_operate_as_delegator_of_format
17
+ list = create_internal('height' => 100)
18
+ assert_same list.height, list.format.height
23
19
  end
24
20
 
25
- def test_relative_position
26
- assert_equal @internal.relative_position, [100, 200]
27
- @internal.move_top_to(50)
28
- assert_equal @internal.relative_position, [100, 250]
21
+ def test_relative_left_should_operate_as_delegator_of_format
22
+ list = create_internal('translate' => {'x' => 10})
23
+ assert_same list.relative_left, list.format.relative_left
24
+ end
25
+
26
+ def test_relative_top_should_operate_as_delegator_of_format
27
+ list = create_internal('translate' => {'y' => 10})
28
+ assert_same list.relative_top, list.format.relative_top
29
+ end
30
+
31
+ def test_svg_tag_should_operate_as_delegator_of_format
32
+ list = create_internal('svg' => {'tag' => 'g'})
33
+ assert_same list.svg_tag, list.format.svg_tag
34
+ end
35
+
36
+ def test_move_top_to_should_properly_set_value_to_states_as_relative_top
37
+ list = create_internal
38
+ list.move_top_to(200)
39
+
40
+ assert_equal list.states[:relative_top], 200
41
+ end
42
+
43
+ def test_relative_position_should_return_Array_included_coordinates
44
+ list = create_internal('translate' => {'x' => 100, 'y' => 200})
45
+
46
+ assert_equal list.relative_position, [100, 200]
47
+ end
48
+
49
+ def test_Y_coordinate_which_relative_position_returns_should_be_calculated_position_with_relative_top_of_states
50
+ list = create_internal('translate' => {'x' => 100, 'y' => 100})
51
+ list.move_top_to(50)
52
+
53
+ assert_equal list.relative_position.last, 150
29
54
  end
30
55
  end
@@ -5,36 +5,30 @@ require 'test/unit/helper'
5
5
  class ThinReports::Core::Shape::Manager::TestFormat < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
- class TestFormat < ThinReports::Core::Shape::Manager::Format
9
- end
8
+ class TestFormat < ThinReports::Core::Shape::Manager::Format; end
10
9
 
11
- def test_identifier_equal_the_object_id
10
+ def test_identifier_should_return_the_same_as_object_id_when_id_is_not_given
12
11
  format = TestFormat.new({})
13
12
  assert_equal format.identifier, format.object_id
14
13
  end
15
14
 
16
- def test_identifier_equal_the_given_id
17
- format = TestFormat.new({}, :any_id)
18
- assert_equal format.identifier, :any_id
15
+ def test_identifier_should_return_the_specified_id_when_id_is_given
16
+ assert_equal TestFormat.new({}, :any_id).identifier, :any_id
19
17
  end
20
18
 
21
- def test_shapes
22
- format = TestFormat.new({})
23
- assert_instance_of ThinReports::Core::OrderedHash, format.shapes
19
+ def test_shapes_should_return_instance_of_OrderedHash
20
+ assert_instance_of ThinReports::Core::OrderedHash, TestFormat.new({}).shapes
24
21
  end
25
22
 
26
- def test_find_shape
23
+ def test_find_shape_should_return_format_of_shape_when_shape_is_found
27
24
  format = TestFormat.new({}) do |f|
28
- f.shapes[:foo] = 'foo'
29
- f.shapes[:boo] = 'boo'
25
+ f.shapes[:foo] = ThinReports::Core::Shape::TextBlock::Format.new('id' => 'foo',
26
+ 'type' => 's-tblock')
30
27
  end
31
-
32
- assert_equal format.find_shape(:foo), 'foo'
33
- assert_equal format.find_shape(:boo), 'boo'
28
+ assert_equal format.find_shape(:foo).id, 'foo'
34
29
  end
35
30
 
36
- def test_find_shape_return_nil_when_id_is_not_found
37
- format = TestFormat.new({})
38
- assert_nil format.find_shape(:unknown)
31
+ def test_find_shape_should_return_nil_when_shape_is_not_found
32
+ assert_nil TestFormat.new({}).find_shape(:unknown)
39
33
  end
40
34
  end
@@ -5,133 +5,167 @@ require 'test/unit/helper'
5
5
  class ThinReports::Core::Shape::Manager::TestInternal < MiniTest::Unit::TestCase
6
6
  include ThinReports::TestHelpers
7
7
 
8
- def setup
9
- @init_item_handler = flexmock('init_item_handler')
10
-
11
- @format_tblock = flexmock(:type => 's-tblock')
12
- @format_list = flexmock(:type => 's-list')
13
- @format_rect = flexmock(:type => 's-rect')
14
-
15
- @item_tblock = flexmock(:type => 's-tblock')
16
- @item_list = flexmock(:type => 's-list')
17
- @item_rect = flexmock(:type => 's-rect')
8
+ # Alias
9
+ Shape = ThinReports::Core::Shape
10
+
11
+ def create_shape_format(type, id, other_config = {})
12
+ Shape::Format(type).new({'id' => id,
13
+ 'type' => type,
14
+ 'display' => 'true'}.merge(other_config))
15
+ end
16
+
17
+ def create_internal(&block)
18
+ report = create_basic_report('basic_layout1.tlf')
19
+ format = report.layout.format
18
20
 
19
- layout_format = flexmock('layout_format')
21
+ # Add to default dummy shapes.
22
+ format.shapes[:t1] = create_shape_format('s-tblock', 't1', 'value' => '')
23
+ format.shapes[:t2] = create_shape_format('s-tblock', 't2', 'value' => '')
24
+ format.shapes[:ls] = create_shape_format('s-list', 'ls')
20
25
 
21
- layout_format.should_receive(:find_shape).
22
- with(:tblock).and_return(@format_tblock)
23
- layout_format.should_receive(:find_shape).
24
- with(:list).and_return(@format_list)
25
- layout_format.should_receive(:find_shape).
26
- with(:rect).and_return(@format_rect)
27
- layout_format.should_receive(:find_shape).
28
- with(:unknown).and_return(nil)
26
+ block.call(format) if block_given?
29
27
 
30
- @manager = ThinReports::Core::Shape::Manager::Internal.new(layout_format,
31
- @init_item_handler)
28
+ report.start_new_page.manager
32
29
  end
33
30
 
34
- def test_find_format
35
- assert_same @manager.find_format(:tblock), @format_tblock
36
- assert_same @manager.find_format('list'), @format_list
37
- assert_nil @manager.find_format(:unknown)
31
+ def test_find_format_should_return_format_with_the_specified_Symbol_id
32
+ assert_equal create_internal.find_format(:t1).id, 't1'
38
33
  end
39
34
 
40
- def test_valid_type?
41
- # Without limit options.
42
- assert_equal @manager.valid_type?('s-list'), true
43
- # With only limitation.
44
- assert_equal @manager.valid_type?('s-list', :only => 's-list'), true
45
- assert_equal @manager.valid_type?('s-list', :only => 'other'), false
46
- # With except limitation.
47
- assert_equal @manager.valid_type?('s-list', :except => 'other'), true
48
- assert_equal @manager.valid_type?('s-list', :except => 's-list'), false
35
+ def test_find_format_should_return_format_with_the_specified_String_id
36
+ assert_equal create_internal.find_format('t2').id, 't2'
49
37
  end
50
38
 
51
- def test_find_item
52
- flexmock(@init_item_handler).
53
- should_receive(:call).once.and_return(@item_tblock)
54
-
55
- # Should initialize item.
56
- @manager.find_item(:tblock)
57
- # Should be stored a one initialized item.
58
- assert_equal @manager.shapes.size, 1
59
- assert_same @manager.shapes[:tblock], @item_tblock
60
-
61
- flexmock(@init_item_handler).
62
- should_receive(:call).times(0)
63
-
64
- # Should must not be initialized when given a initialized item.
65
- assert_same @manager.find_item(:tblock), @item_tblock
39
+ def test_find_format_should_return_nil_when_format_with_specified_id_is_not_found
40
+ assert_nil create_internal.find_format(:unknown)
41
+ end
42
+
43
+ def test_find_item_should_return_shape_with_the_specified_id
44
+ assert_instance_of Shape::TextBlock::Interface, create_internal.find_item(:t1)
45
+ end
46
+
47
+ def test_find_item_should_return_shape_in_shapes_registry_when_the_specified_shape_exists_in_registry
48
+ internal = create_internal
49
+ internal.find_item(:t1)
66
50
 
67
- # Should returnes the nil value when given unknown item.
68
- assert_nil @manager.find_item(:unknown)
51
+ assert_same internal.find_item(:t1), internal.shapes[:t1]
52
+ end
53
+
54
+ def test_find_item_should_return_shape_when_passing_in_the_specified_only_filter
55
+ internal = create_internal
56
+ assert_equal internal.find_item(:t1, :only => 's-tblock').id, 't1'
57
+ end
58
+
59
+ def test_find_item_should_return_nil_when_not_passing_in_the_specified_only_filter
60
+ internal = create_internal
61
+ assert_nil internal.find_item(:t1, :only => 's-list')
69
62
  end
70
63
 
71
- def test_find_item_with_limitation
72
- # Should returns the nil value when outside limitation.
73
- assert_nil @manager.find_item(:tblock, :only => 's-list')
74
- assert_nil @manager.find_item(:list, :except => 's-list')
64
+ def test_find_item_should_return_shape_when_passing_in_the_specified_except_filter
65
+ internal = create_internal
66
+ assert_equal internal.find_item(:ls, :except => 's-tblock').id, 'ls'
67
+ end
68
+
69
+ def test_find_item_should_return_shape_when_not_passing_in_the_specified_except_filter
70
+ internal = create_internal
71
+ assert_nil internal.find_item(:ls, :except => 's-list')
72
+ end
73
+
74
+ def test_final_shape_should_return_nil_when_shape_is_not_found
75
+ internal = create_internal
76
+ assert_nil internal.final_shape(:unknown)
77
+ end
78
+
79
+ def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_hidden
80
+ internal = create_internal
81
+ internal.find_item(:t1).hide
75
82
 
76
- flexmock(@init_item_handler).
77
- should_receive(:call).and_return(@item_tblock)
83
+ assert_nil internal.final_shape(:t1)
84
+ end
85
+
86
+ def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_not_Block
87
+ internal = create_internal do |f|
88
+ f.shapes[:rect] = create_shape_format('s-rect', 'rect')
89
+ end
90
+ internal.find_item(:rect)
78
91
 
79
- # Should initialize and store item.
80
- @manager.find_item(:tblock, :except => 's-list')
81
- assert_equal @manager.shapes[:tblock], @item_tblock
92
+ assert_equal internal.final_shape(:rect).id, 'rect'
93
+ end
94
+
95
+ def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_TextBlock_with_value
96
+ internal = create_internal
97
+ internal.find_item(:t1).value('value')
82
98
 
83
- # Should returns the nil value.
84
- assert_nil @manager.find_item(:tblock, :only => 's-list')
99
+ assert_equal internal.final_shape(:t1).id, 't1'
85
100
  end
86
101
 
87
- def test_final_shape_when_give_the_initialized_item_that_visibility_is_enabled
88
- @manager.shapes[:tblock] = flexmock(:visible? => true)
102
+ def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_TextBlock_with_no_value
103
+ internal = create_internal
104
+ internal.find_item(:t2)
89
105
 
90
- assert_same @manager.final_shape(:tblock), @manager.shapes[:tblock]
106
+ assert_nil internal.final_shape(:t2)
91
107
  end
92
108
 
93
- def test_final_shape_when_give_the_initialized_item_that_visibility_is_disabled
94
- @manager.shapes[:tblock] = flexmock(:visible? => false)
109
+ def test_final_shape_should_return_shape_when_shape_is_stored_in_shapes_and_ImageBlock_with_src
110
+ internal = create_internal do |f|
111
+ f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
112
+ end
113
+ internal.find_item(:iblock).src('/path/to/image.png')
95
114
 
96
- assert_nil @manager.final_shape(:tblock)
115
+ assert_equal internal.final_shape(:iblock).id, 'iblock'
97
116
  end
98
117
 
99
- def test_final_shape_when_give_the_uninitialized_basic_item
100
- flexmock(@format_rect, :display? => true)
118
+ def test_final_shape_should_return_nil_when_shape_is_stored_in_shapes_and_ImageBlock_with_no_src
119
+ internal = create_internal do |f|
120
+ f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
121
+ end
101
122
 
102
- flexmock(@init_item_handler).
103
- should_receive(:call).once.and_return(@item_rect)
123
+ assert_nil internal.final_shape(:iblock)
124
+ end
125
+
126
+ def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_hidden
127
+ internal = create_internal do |f|
128
+ f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'display' => 'false')
129
+ end
104
130
 
105
- # Should initialize item.
106
- assert_same @manager.final_shape(:rect), @item_rect
131
+ assert_nil internal.final_shape(:t3)
107
132
  end
108
133
 
109
- def test_final_shape_return_nil_when_give_the_tblock_item_that_has_no_value
110
- flexmock(@format_tblock, :display? => true,
111
- :has_reference? => false,
112
- :value => '')
113
- assert_nil @manager.final_shape(:tblock)
134
+ def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_not_Block
135
+ internal = create_internal do |f|
136
+ f.shapes[:rect] = create_shape_format('s-rect', 'rect')
137
+ end
138
+
139
+ assert_equal internal.final_shape(:rect).id, 'rect'
114
140
  end
115
141
 
116
- def test_final_shape_initialize_item_when_give_the_tblock_item_that_has_an_reference
117
- flexmock(@format_tblock, :display? => true,
118
- :has_reference? => true,
119
- :value => '')
142
+ def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_ImageBlock
143
+ internal = create_internal do |f|
144
+ f.shapes[:iblock] = create_shape_format('s-iblock', 'iblock')
145
+ end
120
146
 
121
- flexmock(@init_item_handler).
122
- should_receive(:call).once.and_return(@item_tblock)
147
+ assert_nil internal.final_shape(:iblock)
148
+ end
149
+
150
+ def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_TextBlock_with_value
151
+ internal = create_internal do |f|
152
+ f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'value' => 'default value')
153
+ end
123
154
 
124
- assert_same @manager.final_shape(:tblock), @item_tblock
155
+ assert_equal internal.final_shape(:t3).id, 't3'
125
156
  end
126
157
 
127
- def test_final_shape_initialize_item_when_give_the_tblock_item_that_has_a_value
128
- flexmock(@format_tblock, :display? => true,
129
- :has_reference? => false,
130
- :value => 'value')
158
+ def test_final_shape_should_return_shape_when_shape_isnot_stored_in_shapes_and_TextBlock_with_reference
159
+ internal = create_internal do |f|
160
+ f.shapes[:t3] = create_shape_format('s-tblock', 't3', 'ref-id' => 't1')
161
+ end
131
162
 
132
- flexmock(@init_item_handler).
133
- should_receive(:call).once.and_return(@item_tblock)
163
+ assert_equal internal.final_shape(:t3).id, 't3'
164
+ end
165
+
166
+ def test_final_shape_should_return_nil_when_shape_isnot_stored_in_shapes_and_TextBlock_with_no_value_no_reference
167
+ internal = create_internal
134
168
 
135
- assert_same @manager.final_shape(:tblock), @item_tblock
169
+ assert_nil internal.final_shape(:t1)
136
170
  end
137
171
  end
@@ -8,102 +8,109 @@ class ThinReports::Core::Shape::Manager::TestTarget < MiniTest::Unit::TestCase
8
8
  # Alias
9
9
  Shape = ThinReports::Core::Shape
10
10
 
11
- class TestFormat < Shape::Manager::Format; end
12
-
13
11
  class TestManager
14
12
  include Shape::Manager::Target
15
13
 
16
- def initialize(format)
17
- initialize_manager(format) do |f|
14
+ attr_reader :layout, :report
15
+
16
+ def initialize(report, layout)
17
+ @report = report
18
+ @layout = layout
19
+
20
+ initialize_manager(layout.format) do |f|
18
21
  Shape::Interface(self, f)
19
22
  end
20
23
  end
21
24
  end
22
25
 
23
- def setup
24
- tblock1_format = Shape::Tblock::Format.new('id' => 'tblock1',
25
- 'type' => 's-tblock')
26
- tblock2_format = Shape::Tblock::Format.new('id' => 'tblock2',
27
- 'type' => 's-tblock')
28
- list_format = Shape::List::Format.new('id' => 'list',
29
- 'type' => 's-list')
26
+ def create_shape_format(type, id)
27
+ Shape::Format(type).new('id' => id, 'type' => type)
28
+ end
29
+
30
+ def create_manager
31
+ report = create_basic_report('basic_layout1.tlf')
32
+ layout = report.layout
30
33
 
31
- @format = TestFormat.new({}) do |f|
32
- f.shapes[:tblock1] = tblock1_format
33
- f.shapes[:tblock2] = tblock2_format
34
- f.shapes[:list] = list_format
35
- end
36
- @manager = TestManager.new(@format)
34
+ # Add to dummy shapes.
35
+ layout.format.shapes[:t1] = create_shape_format('s-tblock', 't1')
36
+ layout.format.shapes[:t2] = create_shape_format('s-tblock', 't2')
37
+ layout.format.shapes[:ls] = create_shape_format('s-list', 'ls')
38
+
39
+ TestManager.new(report, layout)
40
+ end
41
+
42
+ def test_manager_should_return_instance_of_ManagerInternal
43
+ assert_instance_of Shape::Manager::Internal, create_manager.manager
37
44
  end
38
45
 
39
- def test_item_with_Symbol_id
40
- assert_instance_of Shape::Tblock::Interface, @manager.item(:tblock1)
46
+ def test_item_should_properly_return_shape_with_the_specified_Symbol_id
47
+ assert_equal create_manager.item(:t1).id, 't1'
41
48
  end
42
49
 
43
- def test_item_with_String_id
44
- assert_instance_of Shape::Tblock::Interface, @manager.item('tblock1')
50
+ def test_item_should_properly_return_shape_with_the_specified_String_id
51
+ assert_equal create_manager.item('t2').id, 't2'
45
52
  end
46
53
 
47
- def test_item_raise_error_when_given_the_id_of_list
54
+ def test_item_should_raise_when_the_shape_with_the_specified_id_is_not_found
48
55
  assert_raises ThinReports::Errors::UnknownItemId do
49
- @manager.item(:list)
56
+ create_manager.item(:unknown)
50
57
  end
51
58
  end
52
59
 
53
- def test_item_raise_error_when_given_the_unknown_id
60
+ def test_item_should_set_an_shape_as_argument_when_a_block_is_given
61
+ id = nil
62
+ create_manager.item(:t1) {|s| id = s.id }
63
+ assert_equal id, 't1'
64
+ end
65
+
66
+ def test_item_should_raise_when_type_of_shape_with_the_specified_id_is_list
54
67
  assert_raises ThinReports::Errors::UnknownItemId do
55
- @manager.item(:unknown)
68
+ create_manager.item(:ls)
56
69
  end
57
70
  end
58
71
 
59
- def test_item_with_block_that_has_no_arguments
60
- @manager.item(:tblock1) do
61
- value(1000)
62
- end
63
- assert_equal @manager.item(:tblock1).value, 1000
72
+ def test_list_should_properly_return_list_with_the_specified_Symbol_id
73
+ assert_equal create_manager.list(:ls).id, 'ls'
64
74
  end
65
75
 
66
- def test_item_with_block_that_has_an_argument
67
- @manager.item(:tblock2) do |t|
68
- t.value(1000)
69
- end
70
- assert_equal @manager.item(:tblock2).value, 1000
76
+ def test_list_should_properly_return_list_with_the_specified_String_id
77
+ assert_equal create_manager.list('ls').id, 'ls'
71
78
  end
72
79
 
73
- def test_list_raise_error_when_given_id_of_non_list
80
+ def test_list_should_raise_when_type_of_shape_with_the_specified_id_is_not_list
74
81
  assert_raises ThinReports::Errors::UnknownItemId do
75
- @manager.list(:tblock1)
82
+ create_manager.list(:t1)
76
83
  end
77
84
  end
78
85
 
79
- def test_list_should_be_stored_in_the_special_store
80
- flexmock(@manager).
81
- should_receive(:find_item).and_return(flexmock('item_list'))
86
+ def test_values_should_properly_set_values_to_shapes_with_specified_id
87
+ manager = create_manager
88
+ manager.values(:t1 => 1000, 't2' => 'value')
82
89
 
83
- @manager.list(:list)
84
- assert_includes @manager.manager.lists, :list
90
+ assert_equal [manager.item(:t1).value, manager.item(:t2).value], [1000, 'value']
85
91
  end
86
92
 
87
- def test_items_should_be_warned_as_deprecated
93
+ def test_items_should_show_deprecation_warning
88
94
  out, err = capture_io do
89
- @manager.items :tblock1 => 1000
95
+ create_manager.items(:t1 => 1000)
90
96
  end
91
97
  assert_match %r!DEPRECATION!, err
92
98
  end
93
99
 
94
- def test_values
95
- @manager.values :tblock1 => 1000,
96
- :tblock2 => 2000
97
-
98
- assert_equal @manager.item(:tblock1).value, 1000
99
- assert_equal @manager.item(:tblock2).value, 2000
100
+ def test_item_exists_asker_should_return_true_when_shape_with_specified_Symbol_id_is_found
101
+ assert_equal create_manager.item_exists?(:t1), true
102
+ end
103
+
104
+ def test_item_exists_asker_should_return_true_when_shape_with_specified_String_id_is_found
105
+ assert_equal create_manager.item_exists?('t2'), true
106
+ end
107
+
108
+ def test_item_exists_asker_should_return_false_when_shape_with_specified_id_not_found
109
+ assert_equal create_manager.item_exists?('unknown'), false
100
110
  end
101
111
 
102
- def test_item_exists?
103
- assert_equal @manager.item_exists?(:tblock1), true
104
- assert_equal @manager.item_exists?('list'), true
105
- assert_equal @manager.item_exists?(:unknown), false
106
- # Alias method
107
- assert_equal @manager.exists?(:tblock1), true
112
+ def test_exists_asker_should_operate_like_as_item_exists_asker
113
+ manager = create_manager
114
+ assert_equal manager.exists?(:unknown), manager.item_exists?(:unknown)
108
115
  end
109
116
  end