thinreports 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +5 -1
- data/Rakefile +9 -9
- data/lib/thinreports/generator/pdf.rb +3 -1
- data/lib/thinreports/layout/version.rb +43 -43
- data/lib/thinreports/report/internal.rb +1 -4
- data/lib/thinreports/version.rb +1 -1
- data/test/unit/generator/test_pdf.rb +11 -1
- data/test/unit/helper.rb +13 -9
- data/test/unit/report/test_base.rb +307 -307
- data/test/unit/report/test_internal.rb +188 -175
- data/thinreports.gemspec +2 -1
- metadata +21 -5
@@ -8,227 +8,240 @@ class ThinReports::Report::TestInternal < MiniTest::Unit::TestCase
|
|
8
8
|
# Alias
|
9
9
|
Report = ThinReports::Report
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
layout = flexmock('layout_base')
|
14
|
-
layout.should_receive(:config).and_return(flexmock('layout_configuration'))
|
15
|
-
|
16
|
-
flexmock(ThinReports::Layout).
|
17
|
-
should_receive(:new).and_return(layout)
|
11
|
+
def report
|
12
|
+
Report::Base.new
|
18
13
|
end
|
19
|
-
|
20
|
-
def
|
21
|
-
|
22
|
-
assert_equal report.default_layout.flexmock_name, 'layout_base'
|
14
|
+
|
15
|
+
def sample_layout1
|
16
|
+
data_file('basic_layout1.tlf')
|
23
17
|
end
|
24
|
-
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
|
19
|
+
def sample_layout2
|
20
|
+
data_file('basic_layout2.tlf')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_layout_specified_in_new_method_should_be_defined_as_default_layout
|
24
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
25
|
+
assert_equal internal.default_layout.filename, sample_layout1
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_register_layout_should_be_set_as_default_layout_when_options_are_omitted
|
29
|
+
internal = Report::Internal.new(report, {})
|
30
|
+
internal.register_layout(sample_layout1)
|
31
|
+
|
32
|
+
assert_equal internal.default_layout.filename, sample_layout1
|
30
33
|
end
|
31
34
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
+
def test_register_layout_should_be_set_as_default_layout_when_default_option_is_true
|
36
|
+
internal = Report::Internal.new(report, {})
|
37
|
+
internal.register_layout(sample_layout1, :default => true)
|
35
38
|
|
36
|
-
assert_equal
|
39
|
+
assert_equal internal.default_layout.filename, sample_layout1
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def test_register_layout_should_be_able_to_change_the_default_layout
|
43
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
44
|
+
internal.register_layout(sample_layout2, :default => true)
|
45
|
+
|
46
|
+
assert_equal internal.default_layout.filename, sample_layout2
|
43
47
|
end
|
44
48
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
assert_equal
|
49
|
+
def test_register_layout_should_be_set_as_with_id_when_id_option_is_set
|
50
|
+
internal = Report::Internal.new(report, {})
|
51
|
+
internal.register_layout(sample_layout1, :id => :foo)
|
52
|
+
|
53
|
+
assert_equal internal.layout_registry[:foo].filename, sample_layout1
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
56
|
+
def test_register_layout_should_raise_an_error_when_id_is_already_registered
|
57
|
+
internal = Report::Internal.new(report, {})
|
58
|
+
internal.register_layout(sample_layout2, :id => :foo)
|
55
59
|
|
56
60
|
assert_raises ArgumentError do
|
57
|
-
|
61
|
+
internal.register_layout(sample_layout1, :id => :foo)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
def test_register_layout_should_return_the_instance_of_LayoutConfiguration
|
66
|
+
internal = Report::Internal.new(report, {})
|
67
|
+
|
68
|
+
assert_instance_of ThinReports::Layout::Configuration,
|
69
|
+
internal.register_layout(sample_layout1)
|
65
70
|
end
|
66
71
|
|
67
|
-
def
|
68
|
-
|
69
|
-
mock_page.should_receive(:finalize).mock
|
70
|
-
}
|
71
|
-
|
72
|
-
report = init_report
|
73
|
-
assert_equal report.page_count, 0
|
74
|
-
|
75
|
-
report.add_page(new_page.call)
|
76
|
-
assert_equal report.page_count, 1
|
72
|
+
def test_add_page_should_finalize_the_current_page
|
73
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
77
74
|
|
78
|
-
|
79
|
-
|
75
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
76
|
+
page = internal.add_page(ThinReports::Core::Page.new(report, layout))
|
77
|
+
internal.add_page(ThinReports::Core::Page.new(report, layout))
|
78
|
+
|
79
|
+
assert_equal page.finalized?, true
|
80
80
|
end
|
81
|
-
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
|
82
|
+
def test_add_page_should_return_the_current_page
|
83
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
84
|
+
new_page = ThinReports::Core::Page.new(report, layout)
|
85
|
+
|
86
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
87
|
+
|
88
|
+
assert_same new_page, internal.add_page(new_page)
|
87
89
|
end
|
88
|
-
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
assert_equal report.page.flexmock_name, 'page1'
|
98
|
-
|
99
|
-
report.add_page(new_page.call('page2'))
|
100
|
-
assert_equal report.page.flexmock_name, 'page2'
|
90
|
+
|
91
|
+
def test_add_page_should_add_the_initialized_page
|
92
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
93
|
+
new_page = ThinReports::Core::Page.new(report, layout)
|
94
|
+
|
95
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
96
|
+
internal.add_page(new_page)
|
97
|
+
|
98
|
+
assert_same new_page, internal.pages.last
|
101
99
|
end
|
102
|
-
|
103
|
-
def
|
104
|
-
|
105
|
-
report.add_page(new_page = mock_page)
|
100
|
+
|
101
|
+
def test_add_page_should_count_up_the_total_page_count
|
102
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
106
103
|
|
107
|
-
|
104
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
105
|
+
internal.add_page(ThinReports::Core::Page.new(report, layout))
|
106
|
+
|
107
|
+
assert_equal internal.page_count, 1
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
report.add_page(mock_blank_page)
|
126
|
-
|
127
|
-
assert_equal pass, true
|
110
|
+
def test_add_page_should_switch_to_a_reference_to_the_current_page
|
111
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
112
|
+
new_pages = (1..2).inject([]) do |pages, i|
|
113
|
+
pages << ThinReports::Core::Page.new(report, layout)
|
114
|
+
end
|
115
|
+
|
116
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
117
|
+
internal.add_page(new_pages[0])
|
118
|
+
|
119
|
+
assert_same internal.page, new_pages[0]
|
120
|
+
|
121
|
+
internal.add_page(new_pages[1])
|
122
|
+
|
123
|
+
assert_same internal.page, new_pages[1]
|
128
124
|
end
|
129
|
-
|
130
|
-
def test_add_blank_page_not_count_up_the_page_count_when_count_is_disabled
|
131
|
-
report = init_report
|
132
|
-
report.add_page(mock_not_counting_blank_page)
|
133
|
-
report.add_page(mock_not_counting_blank_page)
|
134
125
|
|
135
|
-
|
126
|
+
def test_add_page_should_dispatch_the_event_page_creation
|
127
|
+
dispatched = false
|
128
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
129
|
+
|
130
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
131
|
+
internal.events.on(:page_create) {|e| dispatched = true }
|
132
|
+
internal.add_page(ThinReports::Core::Page.new(report, layout))
|
133
|
+
|
134
|
+
assert dispatched
|
136
135
|
end
|
137
|
-
|
138
|
-
def
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
assert_equal report.finalized?, true
|
148
|
-
assert_equal pass, true
|
136
|
+
|
137
|
+
def test_add_blank_page_should_not_dispatch_the_event_page_creation
|
138
|
+
dispatched = false
|
139
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
140
|
+
|
141
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
142
|
+
internal.events.on(:page_create) {|e| dispatched = true }
|
143
|
+
internal.add_page(ThinReports::Core::BlankPage.new)
|
144
|
+
|
145
|
+
refute dispatched
|
149
146
|
end
|
150
147
|
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
148
|
+
def test_add_blank_page_should_not_count_up_the_total_page_count_when_count_is_disabled
|
149
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
150
|
+
|
151
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
152
|
+
internal.add_page(ThinReports::Core::BlankPage.new(false))
|
153
|
+
|
154
|
+
assert_equal internal.page_count, 0
|
157
155
|
end
|
158
|
-
|
159
|
-
def
|
160
|
-
|
161
|
-
|
162
|
-
report
|
156
|
+
|
157
|
+
def test_add_blank_page_should_count_up_the_total_page_count_when_count_is_enabled
|
158
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
159
|
+
|
160
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
161
|
+
internal.add_page(ThinReports::Core::BlankPage.new)
|
162
|
+
|
163
|
+
assert_equal internal.page_count, 1
|
163
164
|
end
|
164
165
|
|
165
|
-
def
|
166
|
-
|
167
|
-
|
166
|
+
def test_finalize_should_dispatch_the_event_report_generation
|
167
|
+
dispatched = false
|
168
|
+
|
169
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
170
|
+
internal.events.on(:generate) {|e| dispatched = true }
|
171
|
+
internal.finalize
|
172
|
+
|
173
|
+
assert dispatched
|
168
174
|
end
|
169
|
-
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
+
|
176
|
+
def test_finalize_should_finalize_the_report
|
177
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
178
|
+
internal.finalize
|
179
|
+
|
180
|
+
assert internal.finalized?
|
175
181
|
end
|
176
|
-
|
177
|
-
def
|
178
|
-
|
179
|
-
|
182
|
+
|
183
|
+
def test_finalize_should_not_work_when_report_is_already_finalized
|
184
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
185
|
+
|
186
|
+
flexmock(internal).
|
187
|
+
should_receive(:finalize_current_page).once
|
188
|
+
|
189
|
+
internal.finalize
|
190
|
+
internal.finalize
|
180
191
|
end
|
181
|
-
|
182
|
-
def
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
assert_raises ArgumentError do
|
188
|
-
report.load_layout(ThinReports::Layout.new('layout.tlf'))
|
189
|
-
end
|
192
|
+
|
193
|
+
def test_finalized_should_return_true_when_report_is_already_finalized
|
194
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
195
|
+
internal.finalize
|
196
|
+
|
197
|
+
assert internal.finalized?
|
190
198
|
end
|
191
199
|
|
192
|
-
def
|
193
|
-
|
194
|
-
report.register_layout('default.tlf', :default => true)
|
200
|
+
def test_load_layout_with_String
|
201
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
195
202
|
|
196
|
-
assert_equal
|
203
|
+
assert_equal internal.load_layout(sample_layout2).filename,
|
204
|
+
sample_layout2
|
197
205
|
end
|
198
206
|
|
199
|
-
def
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
report = init_report
|
207
|
-
report.add_page(page)
|
208
|
-
report.copy_page
|
209
|
-
|
210
|
-
assert_equal report.page.flexmock_name, 'copied_page'
|
211
|
-
end
|
212
|
-
|
213
|
-
def init_report(options = {})
|
214
|
-
Report::Internal.new(flexmock('report_base'), options)
|
207
|
+
def test_load_layout_with_id
|
208
|
+
internal = Report::Internal.new(report, {})
|
209
|
+
internal.register_layout(sample_layout1, :id => :sample)
|
210
|
+
|
211
|
+
assert_equal internal.load_layout(:sample).filename,
|
212
|
+
sample_layout1
|
215
213
|
end
|
216
214
|
|
217
|
-
def
|
218
|
-
|
219
|
-
|
220
|
-
should_receive(:no=).with(::Numeric).once.mock
|
215
|
+
def test_load_layout_with_unknown_id
|
216
|
+
internal = Report::Internal.new(report, {})
|
217
|
+
assert_nil internal.load_layout(:unknown)
|
221
218
|
end
|
222
219
|
|
223
|
-
def
|
224
|
-
|
225
|
-
|
226
|
-
|
220
|
+
def test_load_layout_should_raise_error_when_invalid_value_set
|
221
|
+
internal = Report::Internal.new(report, {})
|
222
|
+
|
223
|
+
assert_raises ThinReports::Errors::LayoutFileNotFound do
|
224
|
+
internal.load_layout('/path/to/unkown.tlf')
|
225
|
+
end
|
227
226
|
end
|
228
227
|
|
229
|
-
def
|
230
|
-
|
231
|
-
|
232
|
-
|
228
|
+
def test_copy_page_should_finalize_current_page
|
229
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
230
|
+
|
231
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
232
|
+
internal.add_page(page = ThinReports::Core::Page.new(report, layout))
|
233
|
+
internal.copy_page
|
234
|
+
|
235
|
+
assert page.finalized?
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_copy_page_should_add_the_copied_page
|
239
|
+
layout = ThinReports::Layout.new(sample_layout1)
|
240
|
+
|
241
|
+
internal = Report::Internal.new(report, :layout => sample_layout1)
|
242
|
+
internal.add_page(page = ThinReports::Core::Page.new(report, layout))
|
243
|
+
internal.copy_page
|
244
|
+
|
245
|
+
assert_equal internal.page_count, 2
|
233
246
|
end
|
234
247
|
end
|
data/thinreports.gemspec
CHANGED
@@ -28,8 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_dependency('prawn', '>= 0.12.0', '<= 0.12.0')
|
29
29
|
|
30
30
|
s.add_development_dependency('bundler', ['>= 1.0.0'])
|
31
|
-
s.add_development_dependency('flexmock', ['
|
31
|
+
s.add_development_dependency('flexmock', ['~> 0.9.0'])
|
32
32
|
s.add_development_dependency('yard', ['>= 0'])
|
33
33
|
s.add_development_dependency('rake', ['>=0'])
|
34
34
|
s.add_development_dependency('turn', ['>=0'])
|
35
|
+
s.add_development_dependency('simplecov', ['>=0'])
|
35
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinreports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07
|
12
|
+
date: 2012-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prawn
|
@@ -51,6 +51,22 @@ dependencies:
|
|
51
51
|
version: 1.0.0
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: flexmock
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.9.0
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.9.0
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: yard
|
54
70
|
requirement: !ruby/object:Gem::Requirement
|
55
71
|
none: false
|
56
72
|
requirements:
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
- !ruby/object:Gem::Version
|
67
83
|
version: '0'
|
68
84
|
- !ruby/object:Gem::Dependency
|
69
|
-
name:
|
85
|
+
name: rake
|
70
86
|
requirement: !ruby/object:Gem::Requirement
|
71
87
|
none: false
|
72
88
|
requirements:
|
@@ -82,7 +98,7 @@ dependencies:
|
|
82
98
|
- !ruby/object:Gem::Version
|
83
99
|
version: '0'
|
84
100
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
101
|
+
name: turn
|
86
102
|
requirement: !ruby/object:Gem::Requirement
|
87
103
|
none: false
|
88
104
|
requirements:
|
@@ -98,7 +114,7 @@ dependencies:
|
|
98
114
|
- !ruby/object:Gem::Version
|
99
115
|
version: '0'
|
100
116
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
117
|
+
name: simplecov
|
102
118
|
requirement: !ruby/object:Gem::Requirement
|
103
119
|
none: false
|
104
120
|
requirements:
|