thinreports 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,307 +1,307 @@
|
|
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_should_register_layout_as_default_when_layout_is_specified_as_the_option
|
16
|
-
report = Report::Base.new :layout => data_file('basic_layout1.tlf')
|
17
|
-
assert_equal report.default_layout.filename, data_file('basic_layout1.tlf')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_initialize_should_initialize_new_Report_without_default_layout
|
21
|
-
assert_nil @report.default_layout
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
|
25
|
-
@report.use_layout(data_file('basic_layout1.tlf'))
|
26
|
-
|
27
|
-
assert_equal @report.default_layout.filename, data_file('basic_layout1.tlf')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_use_layout_should_register_default_layout_when_default_property_is_true
|
31
|
-
@report.use_layout(data_file('basic_layout2.tlf'), :default => true)
|
32
|
-
|
33
|
-
assert_equal @report.default_layout.filename, data_file('basic_layout2.tlf')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_start_new_page_should_properly_create_a_new_Page_and_return
|
37
|
-
@report.use_layout(data_file('basic_layout1'))
|
38
|
-
|
39
|
-
assert_instance_of ThinReports::Core::Page, @report.start_new_page
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
|
43
|
-
assert_raises ThinReports::Errors::NoRegisteredLayoutFound do
|
44
|
-
@report.start_new_page(:layout => :unknown)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_start_new_page_should_create_a_new_page_using_a_default_layout
|
49
|
-
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
50
|
-
|
51
|
-
assert_equal @report.start_new_page.layout.filename, data_file('basic_layout1.tlf')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
|
55
|
-
@report.use_layout(data_file('basic_layout1.tlf'), :id => :foo)
|
56
|
-
|
57
|
-
assert_equal @report.start_new_page(:layout => :foo).layout.filename,
|
58
|
-
data_file('basic_layout1.tlf')
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
|
62
|
-
new_page = @report.start_new_page(:layout => data_file('basic_layout1.tlf'))
|
63
|
-
assert_equal new_page.layout.filename, data_file('basic_layout1.tlf')
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_add_blank_page_should_properly_create_a_new_blank_page
|
67
|
-
@report.use_layout(data_file('basic_layout1'))
|
68
|
-
|
69
|
-
assert_instance_of ThinReports::Core::BlankPage, @report.add_blank_page
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_layout_should_return_the_default_layout_with_no_arguments
|
73
|
-
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
74
|
-
|
75
|
-
assert_equal @report.layout.filename, data_file('basic_layout1.tlf')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_layout_should_raise_when_the_specified_layout_is_not_found
|
79
|
-
assert_raises ThinReports::Errors::UnknownLayoutId do
|
80
|
-
@report.layout(:unknown_layout_id)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_layout_should_return_the_layout_with_specified_id
|
85
|
-
@report.use_layout(data_file('basic_layout2.tlf'), :id => :foo)
|
86
|
-
|
87
|
-
assert_equal @report.layout(:foo).filename, data_file('basic_layout2.tlf')
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_specified
|
91
|
-
flexmock(ThinReports::Generator).
|
92
|
-
should_receive(:new).
|
93
|
-
with(:pdf, @report, {:option => :value}).
|
94
|
-
and_return(flexmock(:generate => 'Success')).once
|
95
|
-
|
96
|
-
assert_equal @report.generate(:pdf, :option => :value), 'Success'
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_omitted
|
100
|
-
flexmock(ThinReports::Generator).
|
101
|
-
should_receive(:new).
|
102
|
-
with(:pdf, @report, {:option => :value}).
|
103
|
-
and_return(flexmock(:generate => 'Success')).once
|
104
|
-
|
105
|
-
assert_equal @report.generate(:option => :value), 'Success'
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_specified
|
109
|
-
generator = flexmock('generator')
|
110
|
-
generator.should_receive(:generate_file).with('output.pdf').once
|
111
|
-
|
112
|
-
flexmock(ThinReports::Generator).
|
113
|
-
should_receive(:new).
|
114
|
-
with(:pdf, @report, {}).
|
115
|
-
and_return(generator).once
|
116
|
-
|
117
|
-
@report.generate_file(:pdf, 'output.pdf')
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_omitted
|
121
|
-
generator = flexmock('generator')
|
122
|
-
generator.should_receive(:generate_file).with('output.pdf').once
|
123
|
-
|
124
|
-
flexmock(ThinReports::Generator).
|
125
|
-
should_receive(:new).
|
126
|
-
with(:pdf, @report, {:option => :value}).
|
127
|
-
and_return(generator).once
|
128
|
-
|
129
|
-
@report.generate_file('output.pdf', :option => :value)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_events_should_return_Report_Events
|
133
|
-
assert_instance_of ThinReports::Report::Events, @report.events
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_page_should_return_the_current_page
|
137
|
-
@report.use_layout(data_file('basic_layout1.tlf'))
|
138
|
-
@report.start_new_page
|
139
|
-
|
140
|
-
assert_instance_of ThinReports::Core::Page, @report.page
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_page_count_should_return_total_page_count
|
144
|
-
@report.use_layout(data_file('basic_layout1.tlf'))
|
145
|
-
2.times { @report.start_new_page }
|
146
|
-
|
147
|
-
assert_equal @report.page_count, 2
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_finalize_should_finalize_report
|
151
|
-
@report.finalize
|
152
|
-
assert_equal @report.finalized?, true
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
|
156
|
-
assert_equal @report.finalized?, false
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_finalized_asker_should_return_true_when_report_is_already_finalized
|
160
|
-
@report.finalize
|
161
|
-
assert_equal @report.finalized?, true
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_list_should_create_new_page_when_page_is_not_created
|
165
|
-
@report.use_layout(data_file('basic_list_layout.tlf'))
|
166
|
-
@report.list(:list)
|
167
|
-
|
168
|
-
refute_nil @report.page
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_list_should_create_new_page_when_page_is_finalized
|
172
|
-
@report.tap do |r|
|
173
|
-
r.use_layout(data_file('basic_list_layout.tlf'))
|
174
|
-
r.start_new_page
|
175
|
-
r.page.finalize
|
176
|
-
end
|
177
|
-
@report.list(:list)
|
178
|
-
|
179
|
-
assert_equal @report.page.finalized?, false
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_list_should_properly_return_shape_with_the_specified_id
|
183
|
-
@report.use_layout(data_file('basic_list_layout.tlf'))
|
184
|
-
|
185
|
-
assert_equal @report.list(:list).id, 'list'
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_Base_create_should_finalize_report
|
189
|
-
report = Report::Base.create do |r|
|
190
|
-
assert_instance_of Report::Base, r
|
191
|
-
end
|
192
|
-
assert_equal report.finalized?, true
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_Base_create_should_raise_when_no_block_given
|
196
|
-
assert_raises ArgumentError do
|
197
|
-
Report::Base.create
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_Base_generate_should_properly_generate_when_type_is_specified
|
202
|
-
flexmock(Report::Base).new_instances.
|
203
|
-
should_receive(:generate).
|
204
|
-
with(:pdf, :option => :value).once
|
205
|
-
|
206
|
-
flexmock(Report::Base).
|
207
|
-
should_receive(:create).
|
208
|
-
with({:layout => 'layout.tlf'}, Proc).
|
209
|
-
and_return(Report::Base.new).once
|
210
|
-
|
211
|
-
Report::Base.generate(:pdf, :report => {:layout => 'layout.tlf'},
|
212
|
-
:generator => {:option => :value}) {}
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_Base_generate_should_properly_generate_when_type_is_omitted
|
216
|
-
flexmock(Report::Base).new_instances.
|
217
|
-
should_receive(:generate).
|
218
|
-
with({}).once
|
219
|
-
|
220
|
-
flexmock(Report::Base).
|
221
|
-
should_receive(:create).
|
222
|
-
with({}, Proc).
|
223
|
-
and_return(Report::Base.new).once
|
224
|
-
|
225
|
-
Report::Base.generate {}
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_Base_generate_file_should_properly_generate_file_when_type_is_specified
|
229
|
-
flexmock(Report::Base).new_instances.
|
230
|
-
should_receive(:generate_file).
|
231
|
-
with(:pdf, 'output.pdf', {}).once
|
232
|
-
|
233
|
-
flexmock(Report::Base).
|
234
|
-
should_receive(:create).
|
235
|
-
with({:layout => 'layout.tlf'}, Proc).
|
236
|
-
and_return(Report::Base.new).once
|
237
|
-
|
238
|
-
Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'}) {}
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_Base_generate_file_should_properly_generate_file_when_type_is_omitted
|
242
|
-
flexmock(Report::Base).new_instances.
|
243
|
-
should_receive(:generate_file).
|
244
|
-
with('output.pdf', :option => :value).once
|
245
|
-
|
246
|
-
flexmock(Report::Base).
|
247
|
-
should_receive(:create).
|
248
|
-
with({}, Proc).
|
249
|
-
and_return(Report::Base.new).once
|
250
|
-
|
251
|
-
Report::Base.generate_file('output.pdf', :generator => {:option => :value}) {}
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_Base_generate_should_raise_when_no_block_given
|
255
|
-
assert_raises ArgumentError do
|
256
|
-
Report::Base.generate(:pdf)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_Base_generate_file_should_raise_when_no_block_given
|
261
|
-
assert_raises ArgumentError do
|
262
|
-
Report::Base.generate_file(:pdf, 'output.pdf')
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
|
267
|
-
report, generator = Report::Base.send(:extract_options!, [{:report => {:layout => 'hoge.tlf'}}])
|
268
|
-
assert_equal report[:layout], 'hoge.tlf'
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_Base_extract_options_should_operate_an_argument_destructively
|
272
|
-
args = [:pdf, 'output.pdf', {:report => {:layout => 'foo.tlf'}}]
|
273
|
-
Report::Base.send(:extract_options!, args)
|
274
|
-
assert_equal args, [:pdf, 'output.pdf']
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
|
278
|
-
report, generator = Report::Base.send(:extract_options!, [{:layout => 'hoge.tlf'}])
|
279
|
-
assert_equal report[:layout], 'hoge.tlf'
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
|
283
|
-
report, generator = Report::Base.send(:extract_options!,
|
284
|
-
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf'}])
|
285
|
-
assert_equal report[:layout], 'hoge.tlf'
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
|
289
|
-
report, generator = Report::Base.send(:extract_options!,
|
290
|
-
[{:generator => {:option => 'value'}}])
|
291
|
-
assert_equal generator[:option], 'value'
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
|
295
|
-
report, generator = Report::Base.send(:extract_options!,
|
296
|
-
[{:generator => {:option => 'value1'}, :option => 'value2'}])
|
297
|
-
assert_equal generator[:option], 'value2'
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
|
301
|
-
report, generator = Report::Base.send(:extract_options!,
|
302
|
-
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf',
|
303
|
-
:generator_opt1 => 'value1', :generator_opt2 => 'value2'}])
|
304
|
-
assert_equal generator.values_at(:generator_opt1, :generator_opt2),
|
305
|
-
['value1', 'value2']
|
306
|
-
end
|
307
|
-
end
|
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_should_register_layout_as_default_when_layout_is_specified_as_the_option
|
16
|
+
report = Report::Base.new :layout => data_file('basic_layout1.tlf')
|
17
|
+
assert_equal report.default_layout.filename, data_file('basic_layout1.tlf')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize_should_initialize_new_Report_without_default_layout
|
21
|
+
assert_nil @report.default_layout
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_use_layout_should_register_default_layout_when_default_property_is_omitted
|
25
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
26
|
+
|
27
|
+
assert_equal @report.default_layout.filename, data_file('basic_layout1.tlf')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_use_layout_should_register_default_layout_when_default_property_is_true
|
31
|
+
@report.use_layout(data_file('basic_layout2.tlf'), :default => true)
|
32
|
+
|
33
|
+
assert_equal @report.default_layout.filename, data_file('basic_layout2.tlf')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_start_new_page_should_properly_create_a_new_Page_and_return
|
37
|
+
@report.use_layout(data_file('basic_layout1'))
|
38
|
+
|
39
|
+
assert_instance_of ThinReports::Core::Page, @report.start_new_page
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
|
43
|
+
assert_raises ThinReports::Errors::NoRegisteredLayoutFound do
|
44
|
+
@report.start_new_page(:layout => :unknown)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_start_new_page_should_create_a_new_page_using_a_default_layout
|
49
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
50
|
+
|
51
|
+
assert_equal @report.start_new_page.layout.filename, data_file('basic_layout1.tlf')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
|
55
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :id => :foo)
|
56
|
+
|
57
|
+
assert_equal @report.start_new_page(:layout => :foo).layout.filename,
|
58
|
+
data_file('basic_layout1.tlf')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
|
62
|
+
new_page = @report.start_new_page(:layout => data_file('basic_layout1.tlf'))
|
63
|
+
assert_equal new_page.layout.filename, data_file('basic_layout1.tlf')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_add_blank_page_should_properly_create_a_new_blank_page
|
67
|
+
@report.use_layout(data_file('basic_layout1'))
|
68
|
+
|
69
|
+
assert_instance_of ThinReports::Core::BlankPage, @report.add_blank_page
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_layout_should_return_the_default_layout_with_no_arguments
|
73
|
+
@report.use_layout(data_file('basic_layout1.tlf'), :default => true)
|
74
|
+
|
75
|
+
assert_equal @report.layout.filename, data_file('basic_layout1.tlf')
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_layout_should_raise_when_the_specified_layout_is_not_found
|
79
|
+
assert_raises ThinReports::Errors::UnknownLayoutId do
|
80
|
+
@report.layout(:unknown_layout_id)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_layout_should_return_the_layout_with_specified_id
|
85
|
+
@report.use_layout(data_file('basic_layout2.tlf'), :id => :foo)
|
86
|
+
|
87
|
+
assert_equal @report.layout(:foo).filename, data_file('basic_layout2.tlf')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_specified
|
91
|
+
flexmock(ThinReports::Generator).
|
92
|
+
should_receive(:new).
|
93
|
+
with(:pdf, @report, {:option => :value}).
|
94
|
+
and_return(flexmock(:generate => 'Success')).once
|
95
|
+
|
96
|
+
assert_equal @report.generate(:pdf, :option => :value), 'Success'
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_generate_should_properly_initialize_Generator_and_call_generate_method_when_type_is_omitted
|
100
|
+
flexmock(ThinReports::Generator).
|
101
|
+
should_receive(:new).
|
102
|
+
with(:pdf, @report, {:option => :value}).
|
103
|
+
and_return(flexmock(:generate => 'Success')).once
|
104
|
+
|
105
|
+
assert_equal @report.generate(:option => :value), 'Success'
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_specified
|
109
|
+
generator = flexmock('generator')
|
110
|
+
generator.should_receive(:generate_file).with('output.pdf').once
|
111
|
+
|
112
|
+
flexmock(ThinReports::Generator).
|
113
|
+
should_receive(:new).
|
114
|
+
with(:pdf, @report, {}).
|
115
|
+
and_return(generator).once
|
116
|
+
|
117
|
+
@report.generate_file(:pdf, 'output.pdf')
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_generate_file_should_properly_initialize_Generator_and_call_generate_file_method_when_type_is_omitted
|
121
|
+
generator = flexmock('generator')
|
122
|
+
generator.should_receive(:generate_file).with('output.pdf').once
|
123
|
+
|
124
|
+
flexmock(ThinReports::Generator).
|
125
|
+
should_receive(:new).
|
126
|
+
with(:pdf, @report, {:option => :value}).
|
127
|
+
and_return(generator).once
|
128
|
+
|
129
|
+
@report.generate_file('output.pdf', :option => :value)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_events_should_return_Report_Events
|
133
|
+
assert_instance_of ThinReports::Report::Events, @report.events
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_page_should_return_the_current_page
|
137
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
138
|
+
@report.start_new_page
|
139
|
+
|
140
|
+
assert_instance_of ThinReports::Core::Page, @report.page
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_page_count_should_return_total_page_count
|
144
|
+
@report.use_layout(data_file('basic_layout1.tlf'))
|
145
|
+
2.times { @report.start_new_page }
|
146
|
+
|
147
|
+
assert_equal @report.page_count, 2
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_finalize_should_finalize_report
|
151
|
+
@report.finalize
|
152
|
+
assert_equal @report.finalized?, true
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
|
156
|
+
assert_equal @report.finalized?, false
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_finalized_asker_should_return_true_when_report_is_already_finalized
|
160
|
+
@report.finalize
|
161
|
+
assert_equal @report.finalized?, true
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_list_should_create_new_page_when_page_is_not_created
|
165
|
+
@report.use_layout(data_file('basic_list_layout.tlf'))
|
166
|
+
@report.list(:list)
|
167
|
+
|
168
|
+
refute_nil @report.page
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_list_should_create_new_page_when_page_is_finalized
|
172
|
+
@report.tap do |r|
|
173
|
+
r.use_layout(data_file('basic_list_layout.tlf'))
|
174
|
+
r.start_new_page
|
175
|
+
r.page.finalize
|
176
|
+
end
|
177
|
+
@report.list(:list)
|
178
|
+
|
179
|
+
assert_equal @report.page.finalized?, false
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_list_should_properly_return_shape_with_the_specified_id
|
183
|
+
@report.use_layout(data_file('basic_list_layout.tlf'))
|
184
|
+
|
185
|
+
assert_equal @report.list(:list).id, 'list'
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_Base_create_should_finalize_report
|
189
|
+
report = Report::Base.create do |r|
|
190
|
+
assert_instance_of Report::Base, r
|
191
|
+
end
|
192
|
+
assert_equal report.finalized?, true
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_Base_create_should_raise_when_no_block_given
|
196
|
+
assert_raises ArgumentError do
|
197
|
+
Report::Base.create
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_Base_generate_should_properly_generate_when_type_is_specified
|
202
|
+
flexmock(Report::Base).new_instances.
|
203
|
+
should_receive(:generate).
|
204
|
+
with(:pdf, :option => :value).once
|
205
|
+
|
206
|
+
flexmock(Report::Base).
|
207
|
+
should_receive(:create).
|
208
|
+
with({:layout => 'layout.tlf'}, Proc).
|
209
|
+
and_return(Report::Base.new).once
|
210
|
+
|
211
|
+
Report::Base.generate(:pdf, :report => {:layout => 'layout.tlf'},
|
212
|
+
:generator => {:option => :value}) {}
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_Base_generate_should_properly_generate_when_type_is_omitted
|
216
|
+
flexmock(Report::Base).new_instances.
|
217
|
+
should_receive(:generate).
|
218
|
+
with({}).once
|
219
|
+
|
220
|
+
flexmock(Report::Base).
|
221
|
+
should_receive(:create).
|
222
|
+
with({}, Proc).
|
223
|
+
and_return(Report::Base.new).once
|
224
|
+
|
225
|
+
Report::Base.generate {}
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_Base_generate_file_should_properly_generate_file_when_type_is_specified
|
229
|
+
flexmock(Report::Base).new_instances.
|
230
|
+
should_receive(:generate_file).
|
231
|
+
with(:pdf, 'output.pdf', {}).once
|
232
|
+
|
233
|
+
flexmock(Report::Base).
|
234
|
+
should_receive(:create).
|
235
|
+
with({:layout => 'layout.tlf'}, Proc).
|
236
|
+
and_return(Report::Base.new).once
|
237
|
+
|
238
|
+
Report::Base.generate_file(:pdf, 'output.pdf', :report => {:layout => 'layout.tlf'}) {}
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_Base_generate_file_should_properly_generate_file_when_type_is_omitted
|
242
|
+
flexmock(Report::Base).new_instances.
|
243
|
+
should_receive(:generate_file).
|
244
|
+
with('output.pdf', :option => :value).once
|
245
|
+
|
246
|
+
flexmock(Report::Base).
|
247
|
+
should_receive(:create).
|
248
|
+
with({}, Proc).
|
249
|
+
and_return(Report::Base.new).once
|
250
|
+
|
251
|
+
Report::Base.generate_file('output.pdf', :generator => {:option => :value}) {}
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_Base_generate_should_raise_when_no_block_given
|
255
|
+
assert_raises ArgumentError do
|
256
|
+
Report::Base.generate(:pdf)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_Base_generate_file_should_raise_when_no_block_given
|
261
|
+
assert_raises ArgumentError do
|
262
|
+
Report::Base.generate_file(:pdf, 'output.pdf')
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key
|
267
|
+
report, generator = Report::Base.send(:extract_options!, [{:report => {:layout => 'hoge.tlf'}}])
|
268
|
+
assert_equal report[:layout], 'hoge.tlf'
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_Base_extract_options_should_operate_an_argument_destructively
|
272
|
+
args = [:pdf, 'output.pdf', {:report => {:layout => 'foo.tlf'}}]
|
273
|
+
Report::Base.send(:extract_options!, args)
|
274
|
+
assert_equal args, [:pdf, 'output.pdf']
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_Base_extract_options_should_include_the_layout_key_in_the_report_option
|
278
|
+
report, generator = Report::Base.send(:extract_options!, [{:layout => 'hoge.tlf'}])
|
279
|
+
assert_equal report[:layout], 'hoge.tlf'
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option
|
283
|
+
report, generator = Report::Base.send(:extract_options!,
|
284
|
+
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf'}])
|
285
|
+
assert_equal report[:layout], 'hoge.tlf'
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key
|
289
|
+
report, generator = Report::Base.send(:extract_options!,
|
290
|
+
[{:generator => {:option => 'value'}}])
|
291
|
+
assert_equal generator[:option], 'value'
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option
|
295
|
+
report, generator = Report::Base.send(:extract_options!,
|
296
|
+
[{:generator => {:option => 'value1'}, :option => 'value2'}])
|
297
|
+
assert_equal generator[:option], 'value2'
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option
|
301
|
+
report, generator = Report::Base.send(:extract_options!,
|
302
|
+
[{:report => {:layout => 'foo.tlf'}, :layout => 'hoge.tlf',
|
303
|
+
:generator_opt1 => 'value1', :generator_opt2 => 'value2'}])
|
304
|
+
assert_equal generator.values_at(:generator_opt1, :generator_opt2),
|
305
|
+
['value1', 'value2']
|
306
|
+
end
|
307
|
+
end
|