Skip to content

Commit

Permalink
Merge pull request #52 from saveriomiroddi/clean_gemspec
Browse files Browse the repository at this point in the history
Clean gemspec/gemfile and add preliminary PrawnPDF formatter test suite
  • Loading branch information
kbrock committed Jun 3, 2020
2 parents b0d335a + 8cb1046 commit d572d65
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ source "https://rubygems.org"
gemspec

# Utilities
gem 'rake'
gem 'rdoc'
gem 'byebug'

# Testing gems
gem 'minitest'
Expand Down
8 changes: 1 addition & 7 deletions ruport.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ Gem::Specification.new do |s|

s.rdoc_options = ['--title', 'Ruport Documentation', '--main', 'README.rdoc', '-q']

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<pdf-writer>, ["= 1.1.8"])
s.add_runtime_dependency(%q<prawn>, [">= 0.12.0", "< 2.1.0"]) # tested on 2.0.x, but not 2.1.x
else
s.add_dependency(%q<pdf-writer>, ["= 1.1.8"])
s.add_runtime_dependency(%q<prawn>, [">= 0.12.0", "< 2.1.0"])
end
s.add_runtime_dependency(%q<prawn>, ["= 0.12.0"])

s.add_development_dependency(%q<rake>)
end
154 changes: 154 additions & 0 deletions test/expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test
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
103 changes: 103 additions & 0 deletions test/prawn_pdf_formatter_test.rb
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

0 comments on commit d572d65

Please sign in to comment.