-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from saveriomiroddi/clean_gemspec
Clean gemspec/gemfile and add preliminary PrawnPDF formatter test suite
- Loading branch information
Showing
4 changed files
with
259 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
test/expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
%PDF-1.3 | ||
%���� | ||
1 0 obj | ||
<< /Creator <feff0050007200610077006e> | ||
/Producer <feff0050007200610077006e> | ||
>> | ||
endobj | ||
2 0 obj | ||
<< /Type /Catalog | ||
/Pages 3 0 R | ||
>> | ||
endobj | ||
3 0 obj | ||
<< /Type /Pages | ||
/Count 1 | ||
/Kids [5 0 R] | ||
>> | ||
endobj | ||
4 0 obj | ||
<< /Length 1060 | ||
>> | ||
stream | ||
q | ||
1 w | ||
/DeviceRGB CS | ||
0.000 0.000 0.000 SCN | ||
36.000 756.000 m | ||
52.672 756.000 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
36.000 732.128 m | ||
52.672 732.128 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
36.000 756.500 m | ||
36.000 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
52.672 756.500 m | ||
52.672 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
|
||
BT | ||
41 739.756 Td | ||
/F1.0 12 Tf | ||
[<61>] TJ | ||
ET | ||
|
||
/DeviceRGB cs | ||
0.000 0.000 0.000 scn | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
52.672 756.000 m | ||
69.344 756.000 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
52.672 732.128 m | ||
69.344 732.128 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
52.672 756.500 m | ||
52.672 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
69.344 756.500 m | ||
69.344 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
|
||
BT | ||
57.672 739.756 Td | ||
/F1.0 12 Tf | ||
[<62>] TJ | ||
ET | ||
|
||
0.000 0.000 0.000 scn | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
69.344 756.000 m | ||
85.344 756.000 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
69.344 732.128 m | ||
85.344 732.128 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
69.344 756.500 m | ||
69.344 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
85.344 756.500 m | ||
85.344 731.628 l | ||
S | ||
1 w | ||
0.000 0.000 0.000 SCN | ||
|
||
BT | ||
74.344 739.756 Td | ||
/F1.0 12 Tf | ||
[<63>] TJ | ||
ET | ||
|
||
0.000 0.000 0.000 scn | ||
Q | ||
|
||
endstream | ||
endobj | ||
5 0 obj | ||
<< /Type /Page | ||
/Parent 3 0 R | ||
/MediaBox [0 0 612.0 792.0] | ||
/Contents 4 0 R | ||
/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] | ||
/Font << /F1.0 6 0 R | ||
>> | ||
>> | ||
>> | ||
endobj | ||
6 0 obj | ||
<< /Type /Font | ||
/Subtype /Type1 | ||
/BaseFont /Helvetica | ||
/Encoding /WinAnsiEncoding | ||
>> | ||
endobj | ||
xref | ||
0 7 | ||
0000000000 65535 f | ||
0000000015 00000 n | ||
0000000109 00000 n | ||
0000000158 00000 n | ||
0000000215 00000 n | ||
0000001327 00000 n | ||
0000001505 00000 n | ||
trailer | ||
<< /Size 7 | ||
/Root 2 0 R | ||
/Info 1 0 R | ||
>> | ||
startxref | ||
1602 | ||
%%EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env ruby -w | ||
|
||
require_relative 'helpers' | ||
|
||
class TestRenderPDFTable < Minitest::Test | ||
|
||
def setup | ||
Ruport::Formatter::Template.create(:simple) do |format| | ||
format.page = { | ||
size: "LETTER", | ||
layout: :landscape | ||
} | ||
format.text = { | ||
font_size: 16 | ||
} | ||
format.table = { | ||
show_headings: false | ||
} | ||
format.column = { | ||
alignment: :center, | ||
width: 50 | ||
} | ||
format.heading = { | ||
alignment: :right, | ||
bold: false, | ||
title: "Test" | ||
} | ||
format.grouping = { | ||
style: :separated | ||
} | ||
end | ||
end | ||
|
||
def test_render_pdf_basic | ||
# can't render without column names | ||
data = Ruport.Table([], data: [[1,2],[3,4]]) | ||
assert_raises(Ruport::FormatterError) do | ||
data.to_prawn_pdf | ||
end | ||
|
||
data.column_names = %w[a b] | ||
|
||
data.to_prawn_pdf | ||
|
||
expected_output = IO.read(File.join(__dir__, 'expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test')).bytes | ||
|
||
actual_output = Ruport.Table(%w[a b c]).to_prawn_pdf.bytes | ||
|
||
assert_equal expected_output, actual_output | ||
end | ||
|
||
# this is mostly to check that the transaction hack gets called | ||
def test_relatively_large_pdf | ||
table = Ruport.Table(File.join(File.expand_path(File.dirname(__FILE__)), "../test/", | ||
%w[samples dates.csv])) | ||
table.reduce(0..99) | ||
table.to_prawn_pdf | ||
end | ||
|
||
#--------BUG TRAPS--------# | ||
|
||
# PDF::SimpleTable does not handle symbols as column names | ||
# Ruport should smartly fix this surprising behaviour (#283) | ||
def test_tables_should_render_with_symbol_column_name | ||
data = Ruport.Table([:a,:b,:c], data: [[1,2,3],[4,5,6]]) | ||
data.to_prawn_pdf | ||
end | ||
|
||
end | ||
|
||
class TestRenderPDFGrouping < Minitest::Test | ||
|
||
#--------BUG TRAPS----------# | ||
|
||
def test_grouping_should_have_consistent_font_size | ||
a = Ruport.Table(%w[a b c]) << %w[eye like chicken] << %w[eye like liver] << | ||
%w[meow mix meow ] << %w[mix please deliver ] | ||
b = Grouping(a, by: "a") | ||
splat = b.to_prawn_pdf.split("\n") | ||
splat.grep(/meow/).each do |m| | ||
assert_equal '10.0', m.split[5] | ||
end | ||
splat.grep(/mix/).each do |m| | ||
assert_equal '10.0', m.split[5] | ||
end | ||
splat.grep(/eye/).each do |m| | ||
assert_equal '10.0', m.split[5] | ||
end | ||
end | ||
|
||
end | ||
|
||
class TestPDFFormatterHelpers < Minitest::Test | ||
|
||
def test_move_up | ||
a = Ruport::Formatter::PrawnPDF.new | ||
a.move_cursor_to(500) | ||
a.move_up(50) | ||
assert_equal(550,a.cursor) | ||
a.move_down(100) | ||
assert_equal(450,a.cursor) | ||
end | ||
end |